pub enum ChatMessage {
System {
content: String,
ephemeral: bool,
},
User {
content: String,
images: Vec<ImageAttachment>,
ephemeral: 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,
},
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>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
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>) -> Self
Sourcepub fn system_ephemeral(content: impl Into<String>) -> Self
pub fn system_ephemeral(content: impl Into<String>) -> Self
Create an ephemeral system message: auto-cleaned after turn, not persisted.
pub fn user(content: impl Into<String>) -> Self
Sourcepub fn user_ephemeral(content: impl Into<String>) -> Self
pub fn user_ephemeral(content: impl Into<String>) -> Self
Create an ephemeral user message: auto-cleaned after turn, not persisted.
pub fn user_with_images( content: impl Into<String>, images: Vec<ImageAttachment>, ) -> Self
Sourcepub fn is_ephemeral(&self) -> bool
pub fn is_ephemeral(&self) -> bool
Whether this is an ephemeral message (auto-cleaned after turn, not persisted).
pub fn assistant(content: impl Into<String>) -> Self
pub fn assistant_with_reasoning( content: impl Into<String>, reasoning: impl Into<String>, ) -> Self
pub fn assistant_tool_call( tool_call_id: impl Into<String>, tool_name: impl Into<String>, arguments: impl Into<String>, ) -> Self
pub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
pub fn tool_with_name( tool_call_id: impl Into<String>, name: impl Into<String>, content: impl Into<String>, ) -> Self
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChatMessage
impl Debug for ChatMessage
Source§impl<'de> Deserialize<'de> for ChatMessage
impl<'de> Deserialize<'de> for ChatMessage
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ChatMessage
impl RefUnwindSafe for ChatMessage
impl Send for ChatMessage
impl Sync for ChatMessage
impl Unpin for ChatMessage
impl UnsafeUnpin for ChatMessage
impl UnwindSafe for ChatMessage
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
Mutably borrows from an owned value. Read more