pub struct Message {
pub id: String,
pub role: Role,
pub content: Content,
pub tool_calls: Vec<ToolCall>,
pub tool_call_id: Option<String>,
pub name: Option<String>,
pub usage: Option<TokenUsage>,
}Expand description
Message type for LLM conversations.
Used in agent workflows with message-based state.
Fields§
§id: StringUnique message identifier
role: RoleMessage role (system, human, ai, tool)
content: ContentMessage content (text or multimodal)
tool_calls: Vec<ToolCall>Tool calls made by the AI (for AI messages)
tool_call_id: Option<String>Tool call ID this message responds to (for tool messages)
name: Option<String>Optional name for the message sender
usage: Option<TokenUsage>Token usage information from LLM API responses
Implementations§
Source§impl Message
impl Message
Sourcepub fn ai_with_tool_calls(
content: impl Into<String>,
tool_calls: Vec<ToolCall>,
) -> Self
pub fn ai_with_tool_calls( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Self
Create an AI message with tool calls
Sourcepub fn tool_result(
tool_call_id: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn tool_result( tool_call_id: impl Into<String>, content: impl Into<String>, ) -> Self
Create a tool result message
Sourcepub const fn has_tool_calls(&self) -> bool
pub const fn has_tool_calls(&self) -> bool
Check if message has tool calls
Sourcepub fn content_text(&self) -> &str
pub fn content_text(&self) -> &str
Extract text content from the message
For Content::Text, returns the text directly.
For Content::MultiPart, returns the text of the first ContentPart::Text found,
or an empty string if no text part exists.
Sourcepub fn remove_all() -> Self
pub fn remove_all() -> Self
Create a remove-all message sentinel
This message clears the entire messages list when processed
by the messages reducer. The sentinel has a special ID
(REMOVE_ALL_MESSAGES) that triggers the clear operation.