pub struct Session {
pub key: String,
pub messages: Vec<Value>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub metadata: HashMap<String, Value>,
pub last_consolidated: usize,
}Expand description
A conversation session.
Messages are append-only for LLM cache efficiency. The consolidation
process writes summaries to MEMORY.md / HISTORY.md but does not
modify the messages list or get_history output.
Fields§
§key: StringSession key, typically "{channel}:{chat_id}".
messages: Vec<Value>Ordered list of messages (append-only).
created_at: DateTime<Utc>When the session was first created.
updated_at: DateTime<Utc>When the session was last updated.
metadata: HashMap<String, Value>Arbitrary session metadata.
last_consolidated: usizeNumber of messages already consolidated to external files.
Implementations§
Source§impl Session
impl Session
Sourcepub fn add_message(
&mut self,
role: &str,
content: &str,
extras: Option<HashMap<String, Value>>,
)
pub fn add_message( &mut self, role: &str, content: &str, extras: Option<HashMap<String, Value>>, )
Append a message to the session.
Extra fields can be passed via extras and will be merged into
the message object alongside role, content, and timestamp.
Sourcepub fn get_history(&self, max_messages: usize) -> Vec<Value>
pub fn get_history(&self, max_messages: usize) -> Vec<Value>
Get recent messages in LLM format.
Returns at most max_messages entries from the end of the history.
Preserves tool_call_id and tool_calls metadata when present so
that the LLM can correctly associate tool results with tool calls.