pub enum Message {
System {
content: String,
},
User {
content: Vec<UserContentPart>,
},
Assistant {
content: Vec<AssistantContentPart>,
},
Tool {
content: Vec<ToolResultPart>,
},
}Expand description
A message in a conversation with a language model.
Messages represent different roles in the conversation: system instructions, user inputs, assistant responses, and tool results. Each message contains content appropriate to its role.
§Variants
System- Provides instructions and context for how the model should behaveUser- Input from the user/human, typically containing text and/or filesAssistant- Output from the language model, typically containing text and/or tool callsTool- Results from executing tools that the model requested
§Serialization
Messages are serialized with a role field that identifies their type. User message
content is deserialized flexibly to accept either a string or an array of content parts.
§Usage in Prompts
Messages form the conversation history passed to the model. A typical conversation might follow this pattern:
- System message (optional) - sets context
- User message - the human’s question
- Assistant message - the model’s response
- Repeat steps 2-3 as needed for multi-turn conversations
Variants§
System
System message providing instructions and context for model behavior.
System messages are typically placed at the beginning of a conversation to establish tone, guidelines, or special instructions for the model.
User
Message from the human user.
User messages contain the actual input - questions, requests, or statements from the human. Content can be text, files, or a mix of both.
Fields
content: Vec<UserContentPart>Content parts, typically text and/or file references. Deserialized flexibly to accept string or array formats.
Assistant
Message from the assistant (language model).
Assistant messages contain the model’s responses, which can include text, reasoning, tool calls, or references to files.
Fields
content: Vec<AssistantContentPart>Content parts generated by the model
Tool
Message containing tool execution results.
After the model requests a tool call, tool results are provided in a Tool message so the model can see what happened and make follow-up decisions.
Fields
content: Vec<ToolResultPart>Results from tool executions