pub enum ChatMessage {
System {
content: String,
ephemeral: bool,
},
User {
content: String,
images: Vec<ImageAttachment>,
ephemeral: bool,
synthetic: bool,
},
Assistant {
content: Option<String>,
reasoning_content: Option<String>,
thinking_signature: Option<String>,
tool_calls: Option<Vec<ToolCallMessage>>,
},
Tool {
tool_call_id: String,
name: Option<String>,
content: String,
images: Vec<ImageAttachment>,
},
Custom {
role: String,
data: Value,
},
}Expand description
A chat message in a conversation.
Supports system, user, assistant, tool, and custom message types. Each variant carries the data needed for LLM API calls.
Variants§
System
Fields
User
Fields
images: Vec<ImageAttachment>synthetic: boolMachine-composed input on the user role (tool-failure notices,
background-task wakes, the window seed): the model sees it like
any user message, but it is never the user’s own words. Context
rotation skips synthetic messages when carrying the task trail
into a fresh window. Unlike ephemeral, this flag survives
persistence, so a resumed session keeps the distinction.
Assistant
Fields
thinking_signature: Option<String>Anthropic requires thinking blocks with signature to be sent back in multi-turn conversations. This field stores the signature.
tool_calls: Option<Vec<ToolCallMessage>>Tool
A tool’s result, paired with the assistant’s tool_calls entry.
content is the textual face; images carries pictures the tool’s
output wants the model to look at (a screenshot, a rendered
diagram). A provider whose tool-result shape can carry images sends
them beside the text; one that cannot says so in content rather
than dropping the picture silently.
Custom
Application-defined message type for extensibility.
Custom messages are preserved in the transcript but filtered out by the default conversion before being sent to the LLM provider.
Implementations§
Source§impl ChatMessage
impl ChatMessage
pub fn system(content: impl Into<String>) -> ChatMessage
Sourcepub fn system_ephemeral(content: impl Into<String>) -> ChatMessage
pub fn system_ephemeral(content: impl Into<String>) -> ChatMessage
Create an ephemeral system message: auto-cleaned after turn, not persisted.
pub fn user(content: impl Into<String>) -> ChatMessage
Sourcepub fn user_ephemeral(content: impl Into<String>) -> ChatMessage
pub fn user_ephemeral(content: impl Into<String>) -> ChatMessage
Create an ephemeral user message: auto-cleaned after turn, not persisted.
Sourcepub fn user_synthetic(content: impl Into<String>) -> ChatMessage
pub fn user_synthetic(content: impl Into<String>) -> ChatMessage
Create a synthetic user message: machine-composed input on the user role (a notice, a wake, a seed) that must never stand in for the user’s own words — context rotation skips it when collecting the task trail. The flag is persisted, so a resumed session keeps the distinction.
pub fn user_with_images( content: impl Into<String>, images: Vec<ImageAttachment>, ) -> ChatMessage
Sourcepub fn is_ephemeral(&self) -> bool
pub fn is_ephemeral(&self) -> bool
Whether this is an ephemeral message (auto-cleaned after turn, not persisted).
Sourcepub fn is_synthetic(&self) -> bool
pub fn is_synthetic(&self) -> bool
Whether this is machine-composed input on the user role (never the user’s own words).
pub fn assistant(content: impl Into<String>) -> ChatMessage
pub fn assistant_with_reasoning( content: impl Into<String>, reasoning: impl Into<String>, ) -> ChatMessage
pub fn assistant_tool_call( tool_call_id: impl Into<String>, tool_name: impl Into<String>, arguments: impl Into<String>, ) -> ChatMessage
pub fn tool( tool_call_id: impl Into<String>, content: impl Into<String>, ) -> ChatMessage
Sourcepub fn tool_with_images(
tool_call_id: impl Into<String>,
content: impl Into<String>,
images: Vec<ImageAttachment>,
) -> ChatMessage
pub fn tool_with_images( tool_call_id: impl Into<String>, content: impl Into<String>, images: Vec<ImageAttachment>, ) -> ChatMessage
A tool result that also hands the model pictures to look at.
pub fn tool_with_name( tool_call_id: impl Into<String>, name: impl Into<String>, content: impl Into<String>, ) -> ChatMessage
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more