#[non_exhaustive]pub struct Message {
pub role: Role,
pub parts: Vec<Part>,
}Expand description
One message of the conversation history.
The system prompt is not a message: the Agent of agentai sends its own with every
request.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.role: RoleWho wrote the message.
parts: Vec<Part>Content of the message, in order.
Implementations§
Source§impl Message
impl Message
Sourcepub fn without_media(self) -> Self
pub fn without_media(self) -> Self
Returns the message with every media part, also inside tool results, replaced with a
short text such as [omitted image/png: cat.png].
Sourcepub fn without_reasoning(self) -> Self
pub fn without_reasoning(self) -> Self
Returns the message without the model’s reasoning: Part::Reasoning,
Part::ReasoningSignature, Part::ProviderData and the signatures of tool calls.
Only remove it from finished turns: during a tool loop, Anthropic and Gemini need the reasoning back unchanged.
Anthropic also rejects a stored history whose thinking was created with another system prompt or other tools. After changing them, remove the reasoning once and save the history again:
let history: Vec<Message> = history
.into_iter()
.map(Message::without_reasoning)
.filter(|message| !message.parts.is_empty())
.collect();Source§impl Message
impl Message
Sourcepub fn tool_response(response: ToolResponse) -> Self
pub fn tool_response(response: ToolResponse) -> Self
Creates a message with the result of a tool call.
Sourcepub fn deferred_task_notifications(
notifications: impl IntoIterator<Item = String>,
) -> Option<Self>
pub fn deferred_task_notifications( notifications: impl IntoIterator<Item = String>, ) -> Option<Self>
Creates one user message from deferred task notification lines.
Returns None when there are no notifications.
Sourcepub fn text(&self) -> Option<String>
pub fn text(&self) -> Option<String>
Returns the text parts joined together, or None when the message has no text.
Sourcepub fn tool_calls(&self) -> Vec<&ToolCall>
pub fn tool_calls(&self) -> Vec<&ToolCall>
Returns the tool calls in the message.