pub struct MessageRecord {
pub id: Uuid,
pub session_id: Uuid,
pub role: MessageRole,
pub content: Vec<ContentPart>,
pub tool_calls: Vec<ToolCall>,
pub tool_call_id: Option<String>,
pub tool_name: Option<String>,
pub usage: Option<TokenUsage>,
pub created_at: DateTime<Utc>,
pub is_compaction: bool,
pub is_summary: bool,
pub compaction_meta: Option<CompactionMeta>,
}Expand description
Persisted message exchange within a session.
Each message records a single turn in the conversation: the role (user, assistant, system, tool), its content parts, optional tool calls or tool results, token usage, and compaction state.
Fields§
§id: UuidUnique message identifier.
session_id: UuidSession this message belongs to.
role: MessageRoleMessage role.
content: Vec<ContentPart>Message content parts.
tool_calls: Vec<ToolCall>Tool calls made by the assistant, if any.
tool_call_id: Option<String>Tool call ID for tool result messages.
tool_name: Option<String>Tool name for tool result messages.
usage: Option<TokenUsage>Token usage associated with this exchange.
created_at: DateTime<Utc>When the message was created.
is_compaction: boolWhether this message is a compaction task (user message triggering compression).
is_summary: boolWhether this message contains a compaction summary (assistant response to compaction).
compaction_meta: Option<CompactionMeta>Compaction metadata, populated only for compaction-related messages.
Implementations§
Source§impl MessageRecord
impl MessageRecord
Sourcepub fn new(
session_id: Uuid,
role: MessageRole,
content: Vec<ContentPart>,
) -> Self
pub fn new( session_id: Uuid, role: MessageRole, content: Vec<ContentPart>, ) -> Self
Creates a new message record with a generated UUIDv7 ID and current timestamp.
All optional fields (tool_calls, tool_call_id, tool_name, usage,
compaction flags) are initialized to their default/absent state.
Sourcepub fn with_tool_result(self, call_id: String, name: String) -> Self
pub fn with_tool_result(self, call_id: String, name: String) -> Self
Sets tool call metadata on a tool result message, consuming and returning self.
Use this when the message represents a tool execution result rather than an assistant message that initiates tool calls.
Sourcepub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
pub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
Sets tool calls on the message record, consuming and returning self.
Use this when the assistant message initiates one or more tool calls.
Sourcepub fn with_usage(self, usage: TokenUsage) -> Self
pub fn with_usage(self, usage: TokenUsage) -> Self
Sets token usage on the message record, consuming and returning self.
Sourcepub fn with_compaction(self, meta: CompactionMeta) -> Self
pub fn with_compaction(self, meta: CompactionMeta) -> Self
Marks this message as a compaction task user message, consuming and returning self.
Sourcepub fn with_summary(self, meta: CompactionMeta) -> Self
pub fn with_summary(self, meta: CompactionMeta) -> Self
Marks this message as a compaction summary assistant message, consuming and returning self.
Trait Implementations§
Source§impl Clone for MessageRecord
impl Clone for MessageRecord
Source§fn clone(&self) -> MessageRecord
fn clone(&self) -> MessageRecord
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MessageRecord
impl Debug for MessageRecord
Source§impl<'de> Deserialize<'de> for MessageRecord
impl<'de> Deserialize<'de> for MessageRecord
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>,
Source§impl PartialEq for MessageRecord
impl PartialEq for MessageRecord
Source§fn eq(&self, other: &MessageRecord) -> bool
fn eq(&self, other: &MessageRecord) -> bool
self and other values to be equal, and is used by ==.