Skip to main content

walrus_core/runtime/
session.rs

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