Skip to main content

MutableSession

Struct MutableSession 

Source
pub struct MutableSession { /* private fields */ }
Expand description

MutableSession wraps a session with shared mutable state.

This mirrors ADK-Go’s MutableSession pattern where state changes from events are immediately visible to all agents sharing the same context. This is critical for SequentialAgent/LoopAgent patterns where downstream agents need to read state set by upstream agents via output_key.

Implementations§

Source§

impl MutableSession

Source

pub fn new(session: Arc<dyn AdkSession>) -> Self

Create a new MutableSession from a session snapshot. The state is copied from the session and becomes mutable.

Source

pub fn apply_state_delta(&self, delta: &HashMap<String, Value>)

Apply state delta from an event to the mutable state. This is called by the Runner when events are yielded.

Source

pub fn append_event(&self, event: Event)

Append an event to the session’s event list. This keeps the in-memory view consistent.

Source

pub fn events_snapshot(&self) -> Vec<Event>

Get a snapshot of all events in the session. Used by the runner for compaction decisions.

Source

pub fn replace_events(&self, new_events: Vec<Event>)

Replace all events with a new list (used by intra-invocation compaction).

Source

pub fn events_len(&self) -> usize

Return the number of accumulated events without cloning the full list.

Source

pub fn conversation_history_for_agent_impl( &self, agent_name: Option<&str>, branch: &str, ) -> Vec<Content>

Build conversation history, optionally filtered for a specific agent.

When agent_name is Some, events authored by other agents (not “user”, not the named agent, and not function/tool responses) are excluded. This prevents a transferred sub-agent from seeing the parent’s tool calls mapped as “model” role, which would cause the LLM to think work is already done.

When agent_name is None, all events are included (backward-compatible).

branch additionally scopes history to a conversation branch: an event is kept when its branch equals branch or is an ancestor of it, so concurrent ParallelAgent branches do not read each other’s output. An empty branch, or an event without one, matches everything.

Trait Implementations§

Source§

impl Session for MutableSession

Source§

fn id(&self) -> &str

Returns the session identifier.
Source§

fn app_name(&self) -> &str

Returns the application name this session belongs to.
Source§

fn user_id(&self) -> &str

Returns the user identifier for this session.
Source§

fn state(&self) -> &dyn State

Returns the mutable state associated with this session.
Source§

fn conversation_history(&self) -> Vec<Content>

Returns the conversation history from this session as Content items
Source§

fn conversation_history_for_agent(&self, agent_name: &str) -> Vec<Content>

Returns conversation history filtered for a specific agent. Read more
Source§

fn conversation_history_scoped( &self, agent_name: Option<&str>, branch: &str, ) -> Vec<Content>

Returns conversation history scoped to an agent and a conversation branch. Read more
Source§

fn append_to_history(&self, _content: Content)

Append content to conversation history (for sequential agent support)
Source§

fn try_app_name(&self) -> Result<AppName, AdkError>

Returns the application name as a typed AppName. Read more
Source§

fn try_user_id(&self) -> Result<UserId, AdkError>

Returns the user identifier as a typed UserId. Read more
Source§

fn try_session_id(&self) -> Result<SessionId, AdkError>

Returns the session identifier as a typed SessionId. Read more
Source§

fn try_identity(&self) -> Result<AdkIdentity, AdkError>

Returns the stable session-scoped AdkIdentity triple. Read more
Source§

impl State for MutableSession

Source§

fn get(&self, key: &str) -> Option<Value>

Returns the value for the given key, or None if not present.
Source§

fn set(&mut self, key: String, value: Value)

Set a state value. Implementations should call validate_state_key and reject invalid keys (e.g., by logging a warning or panicking).
Source§

fn all(&self) -> HashMap<String, Value>

Returns all key-value pairs in the state.

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> 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> Same for T

Source§

type Output = T

Should always be Self
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