Skip to main content

Session

Struct Session 

Source
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 loopsparent_loop_id is None (or points to a loop in a different session for sub-agent roots).
  • Continuation chainsparent_loop_idloop_id within the same session.
  • Parallel branches — siblings sharing the same parent_loop_id, each with parallel_group set.
  • Sub-agent children — in child_loop_refs on the parent loop (cross-session, not in loops vec).

§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: String

Stable identifier for this session — matches AgentStart.session_id.

§agent_id: String

The 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: SessionFormation

Why 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: SessionScope

Session 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

Source

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.

Source

pub fn children_of<'a>( &'a self, loop_id: &str, ) -> impl Iterator<Item = &'a LoopRecord>

Return all direct same-session children of loop_id.

Source

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.

Source

pub fn get_loop(&self, loop_id: &str) -> Option<&LoopRecord>

Look up a loop by its loop_id.

Source

pub fn get_loop_mut(&mut self, loop_id: &str) -> Option<&mut LoopRecord>

Mutable look up a loop by its loop_id.

Source

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).

Source

pub fn total_usage(&self) -> Usage

Cumulative token usage across all loops in this session.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Session

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Session

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Session

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,