walrus_core/runtime/session.rs
1//! Session — lightweight history container for agent conversations.
2
3use compact_str::CompactString;
4use std::time::Instant;
5
6use crate::model::Message;
7
8/// A conversation session tied to a specific agent.
9///
10/// Sessions own the conversation history and are stored behind
11/// `Arc<Mutex<Session>>` in the runtime. Multiple sessions can
12/// reference the same agent — each with independent history.
13#[derive(Debug, Clone)]
14pub struct Session {
15 /// Unique session identifier (monotonic counter).
16 pub id: u64,
17 /// Name of the agent this session is bound to.
18 pub agent: CompactString,
19 /// Conversation history (user/assistant/tool messages).
20 pub history: Vec<Message>,
21 /// Origin of this session (e.g. "user", "telegram:12345", agent name).
22 pub created_by: CompactString,
23 /// When this session was created.
24 pub created_at: Instant,
25}
26
27impl Session {
28 /// Create a new session with an empty history.
29 pub fn new(
30 id: u64,
31 agent: impl Into<CompactString>,
32 created_by: impl Into<CompactString>,
33 ) -> Self {
34 Self {
35 id,
36 agent: agent.into(),
37 history: Vec::new(),
38 created_by: created_by.into(),
39 created_at: Instant::now(),
40 }
41 }
42}