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 conversation_history_for_agent_impl(
&self,
agent_name: Option<&str>,
) -> Vec<Content>
pub fn conversation_history_for_agent_impl( &self, agent_name: Option<&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).
Trait Implementations§
Source§impl Session for MutableSession
impl Session for MutableSession
fn id(&self) -> &str
fn app_name(&self) -> &str
fn user_id(&self) -> &str
fn state(&self) -> &dyn State
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 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