Skip to main content

InvocationContext

Trait InvocationContext 

Source
pub trait InvocationContext: CallbackContext {
    // 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 get_secret<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn get_secret_for<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: &'life1 SecretRequest,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Full invocation context available to agents during execution.

Extends CallbackContext with access to the agent itself, memory, session, and run configuration.

Required Methods§

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.

Provided Methods§

Source

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.

Source

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).

Source

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

Returns the request metadata from the auth middleware bridge, if present.

This provides access to custom key-value pairs extracted from the HTTP request by the RequestContextExtractor.

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: Sync + 'async_trait, 'life0: 'async_trait, 'life1: '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).

Source

fn get_secret_for<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 SecretRequest, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: '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".

Implementors§