pub struct Session {
pub session_id: String,
pub agent_id: String,
pub created_at: DateTime<Utc>,
pub last_active_at: DateTime<Utc>,
pub formation: SessionFormation,
pub parent_spawn_ref: Option<SpawnRef>,
pub scope: SessionScope,
pub loops: Vec<LoopRecord>,
}Expand description
A named container grouping all LoopRecords for one agent session.
§Loop tree structure
The tree is implicit via parent_loop_id / children_loop_ids links:
- Root loops —
parent_loop_idisNone(or points to a loop in a different session for sub-agent roots). - Continuation chains —
parent_loop_id→loop_idwithin the same session. - Parallel branches — siblings sharing the same
parent_loop_id, each withparallel_groupset. - Sub-agent children — in
child_loop_refson the parent loop (cross-session, not inloopsvec).
§Cross-session sub-agent tracking
When this session was itself spawned as a sub-agent, [parent_spawn_ref]
points back to the parent session and loop that triggered it. This is the
inverse of LoopRecord::child_loop_refs in the parent session, and together
they form a complete bidirectional cross-session spawn graph.
Fields§
§session_id: StringStable identifier for this session — matches AgentStart.session_id.
agent_id: StringThe agent_id from the first AgentStart seen for this session.
created_at: DateTime<Utc>Timestamp of the first AgentStart event seen for this session.
last_active_at: DateTime<Utc>Timestamp of the most recent AgentStart event seen for this session.
Updated each time a new loop opens (on AgentStart), so it reflects
when the last loop started, not when it last had activity.
formation: SessionFormationWhy this session was created.
parent_spawn_ref: Option<SpawnRef>Set when this session was spawned as a sub-agent by a loop in a different
session. Populated by [SessionRecorder] when a new session’s first
AgentStart carries a parent_loop_id that belongs to a different
session_id.
scope: SessionScopeSession scope — ephemeral (in-memory only) or persistent (written to store) (G7).
loops: Vec<LoopRecord>All completed and in-progress LoopRecords, ordered by LoopRecord::started_at.
Implementations§
Source§impl Session
impl Session
Sourcepub fn root_loops(&self) -> impl Iterator<Item = &LoopRecord>
pub fn root_loops(&self) -> impl Iterator<Item = &LoopRecord>
Return root loops — those whose parent_loop_id is None or whose parent
belongs to a different session.
Sourcepub fn children_of<'a>(
&'a self,
loop_id: &str,
) -> impl Iterator<Item = &'a LoopRecord>
pub fn children_of<'a>( &'a self, loop_id: &str, ) -> impl Iterator<Item = &'a LoopRecord>
Return all direct same-session children of loop_id.
Sourcepub fn parallel_siblings<'a>(
&'a self,
loop_id: &str,
) -> impl Iterator<Item = &'a LoopRecord>
pub fn parallel_siblings<'a>( &'a self, loop_id: &str, ) -> impl Iterator<Item = &'a LoopRecord>
Return all loops in the same parallel group as loop_id.
Sourcepub fn get_loop(&self, loop_id: &str) -> Option<&LoopRecord>
pub fn get_loop(&self, loop_id: &str) -> Option<&LoopRecord>
Look up a loop by its loop_id.
Sourcepub fn get_loop_mut(&mut self, loop_id: &str) -> Option<&mut LoopRecord>
pub fn get_loop_mut(&mut self, loop_id: &str) -> Option<&mut LoopRecord>
Mutable look up a loop by its loop_id.
Sourcepub fn loop_chain_to(&self, target_loop_id: &str) -> Vec<String>
pub fn loop_chain_to(&self, target_loop_id: &str) -> Vec<String>
Build the linear chain of loops from root to target_loop_id
by walking parent_loop_id links backward. Returns loop IDs
in chronological order (root first).
This naturally handles parallel branches (only the selected path) and reruns (only the active ancestor chain).
Sourcepub fn total_usage(&self) -> Usage
pub fn total_usage(&self) -> Usage
Cumulative token usage across all loops in this session.