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
impl MutableSession
Sourcepub fn new(session: Arc<dyn AdkSession>) -> Self
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.
Sourcepub fn apply_state_delta(&self, delta: &HashMap<String, Value>)
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.
Sourcepub fn append_event(&self, event: Event)
pub fn append_event(&self, event: Event)
Append an event to the session’s event list. This keeps the in-memory view consistent.
Sourcepub fn events_snapshot(&self) -> Vec<Event>
pub fn events_snapshot(&self) -> Vec<Event>
Get a snapshot of all events in the session. Used by the runner for compaction decisions.
Sourcepub fn replace_events(&self, new_events: Vec<Event>)
pub fn replace_events(&self, new_events: Vec<Event>)
Replace all events with a new list (used by intra-invocation compaction).
Sourcepub fn events_len(&self) -> usize
pub fn events_len(&self) -> usize
Return the number of accumulated events without cloning the full list.
Sourcepub fn conversation_history_for_agent_impl(
&self,
agent_name: Option<&str>,
branch: &str,
) -> Vec<Content>
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
impl Session for MutableSession
Source§fn conversation_history(&self) -> Vec<Content>
fn conversation_history(&self) -> Vec<Content>
Source§fn conversation_history_for_agent(&self, agent_name: &str) -> Vec<Content>
fn conversation_history_for_agent(&self, agent_name: &str) -> Vec<Content>
Source§fn conversation_history_scoped(
&self,
agent_name: Option<&str>,
branch: &str,
) -> Vec<Content>
fn conversation_history_scoped( &self, agent_name: Option<&str>, branch: &str, ) -> Vec<Content>
Source§fn append_to_history(&self, _content: Content)
fn append_to_history(&self, _content: Content)
Source§fn try_identity(&self) -> Result<AdkIdentity, AdkError>
fn try_identity(&self) -> Result<AdkIdentity, AdkError>
AdkIdentity triple. Read more