pub struct ModelMessage {
pub role: ModelRole,
pub content: String,
pub content_parts: Vec<ContentPart>,
pub tool_call_id: Option<String>,
pub tool_name: Option<String>,
pub tool_calls: Vec<ToolInvocation>,
pub created_at: Option<u64>,
pub thinking_content: Option<String>,
}Expand description
A single message in a model conversation.
Messages carry role, content, and optional tool-related metadata so the same type can represent system prompts, user input, assistant responses, tool calls, and tool results.
Fields§
§role: ModelRoleThe conversational role of this message.
content: StringThe text content of the message.
content_parts: Vec<ContentPart>Multimodal content parts (text + images).
When non-empty, providers use these parts instead of the plain
content field to build the wire-format message.
This allows attaching images alongside text in user messages.
tool_call_id: Option<String>For tool-result messages, the id of the tool call being answered.
tool_name: Option<String>For tool-result messages, the name of the tool that produced this result.
tool_calls: Vec<ToolInvocation>For assistant messages, the tool invocations requested by the model.
created_at: Option<u64>Creation timestamp in milliseconds since Unix epoch (not serialized).
thinking_content: Option<String>Optional thinking/reasoning content from the model.
Implementations§
Source§impl ModelMessage
impl ModelMessage
Sourcepub fn developer(content: impl Into<String>) -> Self
pub fn developer(content: impl Into<String>) -> Self
Creates a developer-role message (context block injected separately from the base system prompt for provider cache efficiency).
Sourcepub fn user_multimodal(
content: impl Into<String>,
parts: Vec<ContentPart>,
) -> Self
pub fn user_multimodal( content: impl Into<String>, parts: Vec<ContentPart>, ) -> Self
Creates a user-role message with text and optional image attachments.
Sourcepub fn assistant(content: impl Into<String>) -> Self
pub fn assistant(content: impl Into<String>) -> Self
Creates an assistant-role message without thinking content.
Sourcepub fn assistant_with_thinking(
content: impl Into<String>,
thinking: Option<String>,
) -> Self
pub fn assistant_with_thinking( content: impl Into<String>, thinking: Option<String>, ) -> Self
Creates an assistant-role message with optional thinking content.
Sourcepub fn tool_result(
tool_call_id: impl Into<String>,
tool_name: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn tool_result( tool_call_id: impl Into<String>, tool_name: impl Into<String>, content: impl Into<String>, ) -> Self
Creates a tool-result message responding to a specific tool call.
Sourcepub fn tool_result_with_parts(
tool_call_id: impl Into<String>,
tool_name: impl Into<String>,
content: impl Into<String>,
content_parts: Vec<ContentPart>,
) -> Self
pub fn tool_result_with_parts( tool_call_id: impl Into<String>, tool_name: impl Into<String>, content: impl Into<String>, content_parts: Vec<ContentPart>, ) -> Self
Creates a tool-result message with optional multimodal content parts
(e.g. images from view_image for vision-capable models).
Sourcepub fn assistant_tool_call(invocation: ToolInvocation) -> Self
pub fn assistant_tool_call(invocation: ToolInvocation) -> Self
Creates an assistant message that requests a single tool invocation.
Sourcepub fn assistant_tool_call_with_context(
invocation: ToolInvocation,
content: impl Into<String>,
thinking: Option<String>,
) -> Self
pub fn assistant_tool_call_with_context( invocation: ToolInvocation, content: impl Into<String>, thinking: Option<String>, ) -> Self
Creates an assistant message that requests a tool invocation with accompanying text content and optional thinking.
pub fn assistant_tool_calls_with_context( invocations: Vec<ToolInvocation>, content: impl Into<String>, thinking: Option<String>, ) -> Self
Trait Implementations§
Source§impl Clone for ModelMessage
impl Clone for ModelMessage
Source§fn clone(&self) -> ModelMessage
fn clone(&self) -> ModelMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more