pub struct MutableSession { /* private fields */ }runner only.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 Session>) -> MutableSession
pub fn new(session: Arc<dyn Session>) -> MutableSession
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 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>,
) -> 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 moreSource§impl State for MutableSession
impl State for MutableSession
Auto Trait Implementations§
impl Freeze for MutableSession
impl !RefUnwindSafe for MutableSession
impl Send for MutableSession
impl Sync for MutableSession
impl Unpin for MutableSession
impl UnsafeUnpin for MutableSession
impl !UnwindSafe for MutableSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request