pub enum Message {
User {
content: String,
attachments: Vec<Attachment>,
},
Assistant {
content: String,
tool_calls: Vec<ToolCall>,
reasoning: Vec<ReasoningState>,
},
System {
content: String,
},
Tool {
content: String,
tool_call_id: String,
},
}Expand description
A message in a conversation.
Different message types have different fields:
- User/System: content with optional attachments
- Assistant: content with optional tool calls
- Tool: content with required
tool_call_id
Variants§
User
User message with content and optional attachments.
Fields
attachments: Vec<Attachment>Attachment URLs (images, documents, etc.)
Assistant
Assistant message with content and optional tool calls.
Fields
reasoning: Vec<ReasoningState>Opaque reasoning state produced with this turn.
Replayed to the provider on the next request. Order is significant — Anthropic rejects a turn whose thinking blocks were reordered or partially dropped — so append rather than rebuild.
System
System message with instructions/context.
Tool
Tool result message.
Implementations§
Source§impl Message
impl Message
Sourcepub fn attachments(&self) -> &[Attachment]
pub fn attachments(&self) -> &[Attachment]
Returns the typed attachments (only for User messages).
Sourcepub fn tool_calls(&self) -> &[ToolCall]
pub fn tool_calls(&self) -> &[ToolCall]
Returns tool calls made by the assistant (only for Assistant messages).
Sourcepub fn tool_call_id(&self) -> Option<&str>
pub fn tool_call_id(&self) -> Option<&str>
Returns the tool call ID (only for Tool messages).
Sourcepub fn assistant_with_tool_calls(
content: impl Into<String>,
tool_calls: Vec<ToolCall>,
) -> Self
pub fn assistant_with_tool_calls( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Self
Creates an assistant message with tool calls.
Sourcepub fn assistant_with_reasoning(
content: impl Into<String>,
tool_calls: Vec<ToolCall>,
reasoning: Vec<ReasoningState>,
) -> Self
pub fn assistant_with_reasoning( content: impl Into<String>, tool_calls: Vec<ToolCall>, reasoning: Vec<ReasoningState>, ) -> Self
Creates an assistant message carrying the reasoning state of its turn.
Use this when rebuilding a conversation for another request: without the reasoning, providers that verify their own thinking see a turn that has lost the reasoning behind its tool calls.
Sourcepub fn reasoning(&self) -> &[ReasoningState]
pub fn reasoning(&self) -> &[ReasoningState]
Reasoning state recorded on this message, if any.
Only assistant turns carry reasoning; every other role returns empty.
Sourcepub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
pub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
Creates a new tool result message.
Sourcepub fn with_attachment(self, attachment: Attachment) -> Self
pub fn with_attachment(self, attachment: Attachment) -> Self
Adds a typed attachment to the message (only works for User messages).
Sourcepub fn with_attachments(
self,
values: impl IntoIterator<Item = Attachment>,
) -> Self
pub fn with_attachments( self, values: impl IntoIterator<Item = Attachment>, ) -> Self
Adds multiple typed attachments to the message.
Sourcepub fn with_tool_calls(self, calls: Vec<ToolCall>) -> Self
pub fn with_tool_calls(self, calls: Vec<ToolCall>) -> Self
Adds tool calls to the message (only works for Assistant messages).