Messages are the unit of communication in chat models. They are used to
represent the input and output of a chat model
Message contains (Role, Content, Metadata).
message: {
Role,
Content,
Metadata
}
Role: {
assistant, //Response from model, which can include text or a request to invoke tools.
function(legacy), //tool role should be used instead.
system, //tell the chat model how to behave and provide additional context
tool, //pass the results of a tool invocation back to the model
user, //tell the chat model how to behave and provide additional context
}
Content: {
text, //simple text
multimodal dictionary data, // List of Images,audio, video
}
Metadata: { //Depending on the chat model provider
ID, //An optional unique identifier for the message.
Name //An optional name property
Metadata //Additional information about the message(eg: timestamps, token usage)
Tool Calls //request made by the model to call one or more tools
}
See Messages first
LangChain provides unified message format that can be used across all
chat models.
LangChain messages are Python objects that subclass from a
BaseMessage
These are 5 message types
| Role | Message | Example | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Assistant |
AIMessage. This is response from Model. It will have following
attributes:
|
|
||||||||||||||
| Assistant role | AIMessageChunk(Used for streaming responses) |
|
||||||||||||||
| Tool | ToolMessage(contains the result of calling a tool) |
|
||||||||||||||
| System | SystemMessage | |||||||||||||||
| User | HumanMessage |
|
||||||||||||||
| No associated Role,Used to manage chat history | RemoveMessage | |||||||||||||||
| Legacy | FunctionMessage |