Skip to main content

RequestContext

Struct RequestContext 

Source
#[non_exhaustive]
pub struct RequestContext { pub message: Message, pub task_id: TaskId, pub context_id: ContextId, pub stored_task: Option<Task>, pub metadata: Option<Value>, pub cancellation_token: CancellationToken, pub call_context: Option<CallContext>, /* private fields */ }
Expand description

Context for a single agent execution request.

Built by the RequestHandler and passed to AgentExecutor::execute.

The cancellation_token allows executors to observe cancellation requests and abort work cooperatively.

call_context carries who the caller is, which tenant they resolved to, the HTTP headers they sent and the extensions they activated. Before 0.13 an executor could see none of that — it was built into a CallContext the handler never passed on — so an executor could not enforce “only this tenant may invoke this skill”, and the only channel for anything caller-specific was Message.metadata.

#[non_exhaustive] since 0.13: this type grows, and every previous growth was a breaking change for a struct literal nobody was writing. Build one with new and the with_* methods.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§message: Message

The incoming user message.

§task_id: TaskId

The task identifier for this execution.

§context_id: ContextId

The conversation context identifier.

A ContextId, as the task’s is a TaskId (a String until 0.16.0, audit G-18): pass it to an event or a Task as it is, and use .as_ref() or .to_string() where a &str or String is wanted.

§stored_task: Option<Task>

The previously stored task snapshot, if this is a continuation.

§metadata: Option<Value>

Arbitrary metadata from the request.

§cancellation_token: CancellationToken

Cancellation token for cooperative task cancellation.

Executors should check CancellationToken::is_cancelled or .cancelled().await to stop work when the task is cancelled.

§call_context: Option<CallContext>

The call this execution belongs to: caller identity, tenant, HTTP headers, activated extensions, method name and request id.

None when the executor is driven directly rather than served — a unit test, a conformance harness — which is the honest answer there rather than a synthetic context claiming a call that never happened. Prefer the accessors (caller_identity, tenant, http_header, activated_extensions) over matching on this directly.

Implementations§

Source§

impl RequestContext

Source

pub fn new( message: Message, task_id: TaskId, context_id: impl Into<ContextId>, ) -> RequestContext

Creates a new RequestContext.

Source

pub fn inbox(&self) -> Option<&Inbox>

The messages sent to this turn while it works (ADR 0036): Some when the server was built with with_steering, None otherwise, and None for an executor driven directly.

An executor reads it when it can act on one: between steps of a loop, or recv().await beside the work it is waiting on. One that never reads it is unaffected, and whatever is still in it when the executor returns is dropped with the turn (and counted as unread). The text has the sender’s authority over the task and no more: it does not cancel, it is not an approval, and it is user text like any other.

let mut instructions = Vec::new();
if let Some(inbox) = ctx.inbox() {
    while let Some(steered) = inbox.try_recv() {
        instructions.extend(steered.message.texts().map(str::to_owned));
    }
}
instructions
Source

pub fn with_inbox(self, inbox: Arc<Inbox>) -> RequestContext

Gives the turn an inbox, as the handler does when steering is on; for an executor driven directly, as in a test.

Source

pub fn referenced_tasks(&self) -> &[Task]

The tasks the message’s referenceTaskIds name, as the handler resolved them before this execution (spec §3.4.3: “Agents SHOULD use referenced tasks to understand the context and intent of follow-up requests”).

Read in the caller’s own partition, so a task another caller or tenant holds is absent, as is one the store does not have; at most 16 are resolved, duplicates once, in the order the message lists them. Empty when the message references none. Since 2026-10-18.

Source

pub const fn content_check(&self) -> &ContentCheck

What the server found when it checked the message’s provenance signature (ADR 0027): ContentCheck::NotChecked unless the handler has keys (RequestHandlerBuilder::with_content_keys, feature signing). A signature that does not verify is refused before the executor runs, so an executor sees only Verified, Unsigned or NotChecked.

Source

pub fn with_referenced_tasks(self, tasks: Vec<Task>) -> RequestContext

Sets the resolved referenced tasks; see referenced_tasks.

Source

pub fn with_stored_task(self, task: Task) -> RequestContext

Sets the stored task snapshot for continuation requests.

Source

pub fn with_metadata(self, metadata: Value) -> RequestContext

Sets request metadata.

Source

pub const fn budget(&self) -> Option<&BudgetHandle>

The caller’s budget for this turn (ADR 0023), its account started when the send was admitted; None when the message carried none.

remaining_time and remaining say how much more the turn may spend; charge records spend; grant carves a delegated child’s budget out of it. The handler holds the turn to the deadline itself; meters are the executor’s to charge.

Source

pub fn with_budget(self, budget: BudgetHandle) -> RequestContext

Sets the turn’s budget, as the handler does for a message that carries one; for an executor driven directly, as in a test.

Source

pub const fn lineage(&self) -> &Lineage

The job this turn belongs to (ADR 0034): the lineage its task was created with, or, for a task sent without one, a job of its own whose root is its contextId, at depth 0. The handler checked it before the executor ran; a halt of its root (HaltScope::Root) stops this turn.

Source

pub fn child_lineage(&self) -> Result<Lineage, A2aError>

The lineage to give a task this turn delegates: the same root, one level deeper, with this task as its parent. Attach it to the child’s message (Lineage::attach, or a2a_protocol_client::delegation::DelegationOptions::with_lineage), so that halting this job stops the child too.

§Errors

Invalid params when this turn is at MAX_LINEAGE_DEPTH: the job may delegate no deeper.

Source

pub fn with_lineage(self, lineage: Lineage) -> RequestContext

Sets the turn’s lineage, as the handler does; for an executor driven directly, as in a test.

Source

pub const fn approval(&self) -> Option<&VerifiedApproval>

The approval decision this continuation carries, checked by the handler’s ApprovalGate: the request it answers, approve or deny, and who decided. None when the message carries no decision, and always None on a handler built without a gate — a decision nothing checked is not reported here.

Source

pub fn with_accepted_output_modes(self, modes: Vec<String>) -> RequestContext

Sets the output media types the caller accepts.

Source

pub fn accepted_output_modes(&self) -> &[String]

The media types the caller will accept in the response (SendMessageConfiguration.acceptedOutputModes), which the proto says an agent SHOULD use to tailor its output. Empty means no preference.

Source

pub fn with_call_context(self, call_context: CallContext) -> RequestContext

Attaches the CallContext this execution was requested under.

Source

pub fn caller_identity(&self) -> Option<&str>

Who the caller is, if authentication established an identity.

None means either that no interceptor authenticated the call or that this context was built without one. An executor that must refuse anonymous work should treat None as a refusal rather than a default.

Source

pub fn tenant(&self) -> Option<&str>

The tenant this call resolved to, after any TenantResolver has had its say.

This is the value to use inside an executor. TenantContext::current is a task-local that tokio::spawn does not inherit, so it reads empty in some executor contexts; this field is an owned copy taken before the spawn.

Source

pub fn http_header(&self, name: &str) -> Option<&str>

One inbound HTTP header, matched case-insensitively.

Source

pub fn activated_extensions(&self) -> &[String]

The extension URIs the caller activated for this request, from the A2A-Extensions header (spec §14.2.2).

With an agent card, only the URIs it declares, in request order: the set the response’s A2A-Extensions header echoes. An undeclared extension or version is left out (spec §4.6.3, “ignore the extension for that interaction”). With no card, the request’s list unchanged.

Source

pub fn trace_context(&self) -> Option<&TraceContext>

The W3C trace this execution belongs to, when the caller sent a traceparent.

Propagate it verbatim on any outbound A2A call and the delegation chain becomes one trace rather than several unrelated span trees (the client’s CurrentTrace::scope(tc.clone(), call) carries it; by hand):

let tc = ctx.trace_context()?;
Some(tc.traceparent()) // the `traceparent` header value for the callee

None means the caller was not tracing. It never means the SDK invented one.

Source

pub fn request_id(&self) -> Option<&str>

The caller’s request/trace id, from X-Request-ID if they sent one.

Trait Implementations§

Source§

impl Clone for RequestContext

Source§

fn clone(&self) -> RequestContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RequestContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more