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§impl Debug for ModelMessage
impl Debug for ModelMessage
Source§impl<'de> Deserialize<'de> for ModelMessage
impl<'de> Deserialize<'de> for ModelMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ModelMessage
impl RefUnwindSafe for ModelMessage
impl Send for ModelMessage
impl Sync for ModelMessage
impl Unpin for ModelMessage
impl UnsafeUnpin for ModelMessage
impl UnwindSafe for ModelMessage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more