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>) -> 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.
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).
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
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
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<ChatMessage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatMessage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&ChatMessage> for Message
impl From<&ChatMessage> for Message
Source§fn from(cm: &ChatMessage) -> Self
fn from(cm: &ChatMessage) -> Self
Converts to this type from the input type.
Source§impl Serialize for ChatMessage
impl Serialize for ChatMessage
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. 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