pub trait InvocationContext: CallbackContext {
Show 18 methods
// Required methods
fn agent(&self) -> Arc<dyn Agent> ⓘ;
fn memory(&self) -> Option<Arc<dyn Memory>>;
fn session(&self) -> &dyn Session;
fn run_config(&self) -> &RunConfig;
fn end_invocation(&self);
fn ended(&self) -> bool;
// Provided methods
fn is_cancelled(&self) -> bool { ... }
fn user_scopes(&self) -> Vec<String> { ... }
fn request_metadata(&self) -> HashMap<String, Value> { ... }
fn authoritative_transfer_targets(&self) -> bool { ... }
fn delegation_depth(&self) -> u32 { ... }
fn max_delegation_depth(&self) -> Option<u32> { ... }
fn orchestration_root_invocation_id(&self) -> &str { ... }
fn orchestration_edge_id(&self) -> Option<&str> { ... }
fn requires_tool_confirmation(&self, _tool_name: &str) -> bool { ... }
fn steering_inbox(&self) -> Option<SteeringInbox> { ... }
fn get_secret<'life0, 'life1, 'async_trait>(
&'life0 self,
_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait { ... }
fn get_secret_for<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 SecretRequest,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait { ... }
}Expand description
Core traits and types.
Always available regardless of feature flags. Includes:
Agent- The fundamental trait for all agentsTool/Toolset- For extending agents with capabilitiesSession/State- For managing conversation contextEvent- For streaming agent responsesAdkError/Result- Unified error handling Full invocation context available to agents during execution.
Extends CallbackContext with access to the agent itself, memory,
session, and run configuration.
Required Methods§
Sourcefn run_config(&self) -> &RunConfig
fn run_config(&self) -> &RunConfig
Returns the run configuration for this invocation.
Sourcefn end_invocation(&self)
fn end_invocation(&self)
Signals that this invocation should end after the current turn.
Provided Methods§
Sourcefn is_cancelled(&self) -> bool
fn is_cancelled(&self) -> bool
Returns true if this invocation has been cancelled.
Agents and tools can poll this during long-running work (LLM streaming,
HTTP I/O, tool execution) to detect an external cancellation request —
for example, a user pressing “Stop” or a call to
Runner::interrupt. Checking it at chunk
or tool boundaries lets an agent exit promptly and perform any graceful
cleanup instead of running to natural completion.
The default returns false. The runtime sets the underlying token when
Runner::interrupt() is called or RunConfig::cancellation_token fires.
Sourcefn user_scopes(&self) -> Vec<String>
fn user_scopes(&self) -> Vec<String>
Returns the scopes granted to the current user for this invocation.
When a RequestContext is present (set by the
server’s auth middleware bridge), this returns the scopes from that
context. The default returns an empty vec (no scopes granted).
Sourcefn request_metadata(&self) -> HashMap<String, Value>
fn request_metadata(&self) -> HashMap<String, Value>
Returns the run’s request metadata: the run’s unauthenticated
RunConfig::request_metadata overlaid with the metadata of its
RequestContext, whose values win on a shared key.
Only the request context’s entries come from a request the server authenticated;
is_authenticated says whether there is one.
Whether the run’s transfer target list replaces static sub-agent targets.
Sourcefn delegation_depth(&self) -> u32
fn delegation_depth(&self) -> u32
Current nested agent-as-tool delegation depth.
Sourcefn max_delegation_depth(&self) -> Option<u32>
fn max_delegation_depth(&self) -> Option<u32>
Maximum nested agent-as-tool delegation depth.
Sourcefn orchestration_root_invocation_id(&self) -> &str
fn orchestration_root_invocation_id(&self) -> &str
Returns the root invocation that owns this orchestration tree.
Nested agent runs use this stable identifier to aggregate budgets, traces, and execution receipts without conflating unrelated runs.
Sourcefn orchestration_edge_id(&self) -> Option<&str>
fn orchestration_edge_id(&self) -> Option<&str>
Returns the causal relationship execution that started this run.
Sourcefn requires_tool_confirmation(&self, _tool_name: &str) -> bool
fn requires_tool_confirmation(&self, _tool_name: &str) -> bool
Returns whether a runtime-injected tool requires confirmation.
This additive hook lets composition layers protect relationship tools without mutating the concrete agent that receives them.
Sourcefn steering_inbox(&self) -> Option<SteeringInbox>
fn steering_inbox(&self) -> Option<SteeringInbox>
Returns the inbox of user messages sent to this run while it runs, through
Runner::steer.
An agent takes the queued messages at a safe point of its loop, after a tool step’s
results are in its history and before its next model request, and yields each as
SteeringMessage::to_event. A wrapper context
forwards it. A context whose agent must not take steering returns None: a
ParallelAgent branch, whose message waits for the first safe point after the join.
The default returns None.
Sourcefn get_secret<'life0, 'life1, 'async_trait>(
&'life0 self,
_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
fn get_secret<'life0, 'life1, 'async_trait>(
&'life0 self,
_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
Retrieve a secret by name from the configured secret provider.
Returns Ok(Some(value)) when a provider is configured and the secret
exists, Ok(None) when no provider is configured, or an error on
provider failure. The default returns Ok(None).
Sourcefn get_secret_for<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 SecretRequest,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
fn get_secret_for<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 SecretRequest,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
Resolves a secret for a described access.
A wrapper context must forward this, and a tool context builds the request from
the identity the framework gave it. The default drops the description and calls
InvocationContext::get_secret, which keeps a context that predates the
request object working.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".