Skip to main content

InvocationContext

Struct InvocationContext 

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

Runtime context for a single agent invocation.

Holds the agent, session, identity, and optional services (artifacts, memory, secrets) needed during execution. Created by the Runner for each run() call.

Implementations§

Source§

impl InvocationContext

Source

pub fn new_typed( invocation_id: String, agent: Arc<dyn Agent>, user_id: UserId, app_name: AppName, session_id: SessionId, user_content: Content, session: Arc<dyn AdkSession>, ) -> Result<Self>

Create a new invocation context from validated typed identifiers.

Source

pub fn new( invocation_id: String, agent: Arc<dyn Agent>, user_id: String, app_name: String, session_id: String, user_content: Content, session: Arc<dyn AdkSession>, ) -> Result<Self>

Create a new invocation context from raw string identifiers.

Validates and converts the string identifiers into typed wrappers. Prefer new_typed when you already have validated types.

Source

pub fn with_mutable_session_typed( invocation_id: String, agent: Arc<dyn Agent>, user_id: UserId, app_name: AppName, session_id: SessionId, user_content: Content, session: Arc<MutableSession>, ) -> Result<Self>

Create an invocation context that reuses an existing mutable session and validated typed identifiers.

Source

pub fn with_mutable_session( invocation_id: String, agent: Arc<dyn Agent>, user_id: String, app_name: String, session_id: String, user_content: Content, session: Arc<MutableSession>, ) -> Result<Self>

Create an InvocationContext with an existing MutableSession. This allows sharing the same mutable session across multiple contexts (e.g., for agent transfers).

Source

pub fn with_branch(self, branch: String) -> Self

Set the event branch identifier for this context.

Source

pub fn with_artifacts(self, artifacts: Arc<dyn Artifacts>) -> Self

Attach an artifact storage service to this context.

Source

pub fn with_memory(self, memory: Arc<dyn Memory>) -> Self

Attach a memory service for RAG/semantic search.

Source

pub fn with_run_config(self, config: RunConfig) -> Self

Set the run configuration (streaming mode, history limits, etc.).

Source

pub fn with_request_context(self, ctx: RequestContext) -> Self

Set the request context from the server’s auth middleware bridge.

When set, user_id() returns request_context.user_id (overriding the session-scoped identity), and user_scopes() returns request_context.scopes. This is the explicit authenticated user override — RequestContext remains separate from ExecutionIdentity and AdkIdentity (it does not carry session or invocation IDs).

Source

pub fn with_shared_state(self, shared: Arc<SharedState>) -> Self

Set the shared state for parallel agent coordination.

Source

pub fn with_secret_service(self, service: Arc<dyn SecretService>) -> Self

Set the secret service for runtime secret retrieval.

When configured, tools can call ctx.get_secret("name") to retrieve secrets from the configured provider (e.g., AWS Secrets Manager, Azure Key Vault, GCP Secret Manager).

Source

pub fn mutable_session(&self) -> &Arc<MutableSession>

Get a reference to the mutable session. This allows the Runner to apply state deltas when events are processed.

Trait Implementations§

Source§

impl CallbackContext for InvocationContext

Source§

fn artifacts(&self) -> Option<Arc<dyn Artifacts>>

Returns the artifact store, if one is configured.
Source§

fn shared_state(&self) -> Option<Arc<SharedState>>

Returns the shared state for parallel agent coordination. Returns None when not running inside a ParallelAgent with shared state enabled.
Source§

fn tool_outcome(&self) -> Option<ToolOutcome>

Returns structured metadata about the most recent tool execution. Available in after-tool callbacks and plugin hooks. Returns None when not in a tool execution context.
Source§

fn tool_name(&self) -> Option<&str>

Returns the name of the tool about to be executed. Available in before-tool and after-tool callback contexts.
Source§

fn tool_input(&self) -> Option<&Value>

Returns the input arguments for the tool about to be executed. Available in before-tool and after-tool callback contexts.
Source§

impl InvocationContext for InvocationContext

Source§

fn agent(&self) -> Arc<dyn Agent>

Returns the agent being executed.
Source§

fn memory(&self) -> Option<Arc<dyn Memory>>

Returns the memory service, if one is configured.
Source§

fn session(&self) -> &dyn Session

Returns the current session.
Source§

fn run_config(&self) -> &RunConfig

Returns the run configuration for this invocation.
Source§

fn end_invocation(&self)

Signals that this invocation should end after the current turn.
Source§

fn ended(&self) -> bool

Returns whether the invocation has been ended.
Source§

fn user_scopes(&self) -> Vec<String>

Returns the scopes granted to the current user for this invocation. Read more
Source§

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

Returns the request metadata from the auth middleware bridge, if present. Read more
Source§

fn get_secret<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve a secret by name from the configured secret provider. Read more
Source§

impl ReadonlyContext for InvocationContext

Source§

fn invocation_id(&self) -> &str

Returns the current invocation identifier.
Source§

fn agent_name(&self) -> &str

Returns the name of the currently executing agent.
Source§

fn user_id(&self) -> &str

Returns the user identifier for this session.
Source§

fn app_name(&self) -> &str

Returns the application name for this session.
Source§

fn session_id(&self) -> &str

Returns the session identifier.
Source§

fn branch(&self) -> &str

Returns the current conversation branch.
Source§

fn user_content(&self) -> &Content

Returns the user’s input content for this invocation.
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_invocation_id(&self) -> Result<InvocationId, AdkError>

Returns the invocation identifier as a typed InvocationId. Read more
Source§

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

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

fn try_execution_identity(&self) -> Result<ExecutionIdentity, AdkError>

Returns the full per-invocation ExecutionIdentity. 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> 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