pub enum ChatMessage {
System {
content: String,
timestamp: IsoString,
},
User {
content: Vec<ContentBlock>,
timestamp: IsoString,
},
Assistant {
content: String,
reasoning: AssistantReasoning,
timestamp: IsoString,
tool_calls: Vec<ToolCallRequest>,
},
ToolCallResult(Result<ToolCallResult, ToolCallError>),
Error {
message: String,
timestamp: IsoString,
},
Summary {
content: String,
timestamp: IsoString,
messages_compacted: usize,
},
}Expand description
A message in the conversation history.
Each variant represents a different role or message type in the conversation sent to the LLM provider.
§Variants
System– The system prompt. Typically the first message in the conversation.User– User input, supporting multimodal content viaVec<ContentBlock>.Assistant– The model’s response. Includes text content, optionalAssistantReasoning, and anyToolCallRequests the model made.ToolCallResult– The result of executing a tool call, wrappingResult<ToolCallResult,ToolCallError>.Error– An error message recorded in conversation history.Summary– A compacted summary replacing multiple earlier messages to reduce context usage. Created byContext::with_compacted_summary.
§Helper methods
is_system,is_tool_result,is_summary– Variant checks.timestamp– Returns the message timestamp (all variants exceptToolCallResult).estimated_bytes– Rough byte-size estimate for pre-flight context checks.
§Serialization
Uses #[serde(tag = "type", rename_all = "camelCase")] – each variant is serialized with a "type" field (e.g. {"type": "system", "content": "..."}) for use in JSON-based persistence and wire formats.
Variants§
System
User
Assistant
ToolCallResult(Result<ToolCallResult, ToolCallError>)
Error
Summary
A compacted summary of previous conversation history. This replaces multiple messages with a structured summary to reduce context usage.
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcepub fn is_tool_result(&self) -> bool
pub fn is_tool_result(&self) -> bool
Returns true if this message is a tool call result
Sourcepub fn is_summary(&self) -> bool
pub fn is_summary(&self) -> bool
Returns true if this message is a compacted summary
Sourcepub fn estimated_bytes(&self) -> usize
pub fn estimated_bytes(&self) -> usize
Rough byte-size estimate of the message content for pre-flight context checks. Not meant to be exact — just close enough to detect overflow before calling the LLM.
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 · 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
Source§impl PartialEq for ChatMessage
impl PartialEq for ChatMessage
Source§impl Serialize for ChatMessage
impl Serialize for ChatMessage
impl Eq for ChatMessage
impl StructuralPartialEq for ChatMessage
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.