#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.message: MessageThe incoming user message.
task_id: TaskIdThe task identifier for this execution.
context_id: ContextIdThe 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: CancellationTokenCancellation 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
impl RequestContext
Sourcepub fn new(
message: Message,
task_id: TaskId,
context_id: impl Into<ContextId>,
) -> RequestContext
pub fn new( message: Message, task_id: TaskId, context_id: impl Into<ContextId>, ) -> RequestContext
Creates a new RequestContext.
Sourcepub fn inbox(&self) -> Option<&Inbox>
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));
}
}
instructionsSourcepub fn with_inbox(self, inbox: Arc<Inbox>) -> RequestContext
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.
Sourcepub fn referenced_tasks(&self) -> &[Task]
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.
Sourcepub const fn content_check(&self) -> &ContentCheck
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.
Sourcepub fn with_referenced_tasks(self, tasks: Vec<Task>) -> RequestContext
pub fn with_referenced_tasks(self, tasks: Vec<Task>) -> RequestContext
Sets the resolved referenced tasks; see
referenced_tasks.
Sourcepub fn with_stored_task(self, task: Task) -> RequestContext
pub fn with_stored_task(self, task: Task) -> RequestContext
Sets the stored task snapshot for continuation requests.
Sourcepub fn with_metadata(self, metadata: Value) -> RequestContext
pub fn with_metadata(self, metadata: Value) -> RequestContext
Sets request metadata.
Sourcepub const fn budget(&self) -> Option<&BudgetHandle>
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.
Sourcepub fn with_budget(self, budget: BudgetHandle) -> RequestContext
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.
Sourcepub const fn lineage(&self) -> &Lineage
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.
Sourcepub fn child_lineage(&self) -> Result<Lineage, A2aError>
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.
Sourcepub fn with_lineage(self, lineage: Lineage) -> RequestContext
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.
Sourcepub const fn approval(&self) -> Option<&VerifiedApproval>
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.
Sourcepub fn with_accepted_output_modes(self, modes: Vec<String>) -> RequestContext
pub fn with_accepted_output_modes(self, modes: Vec<String>) -> RequestContext
Sets the output media types the caller accepts.
Sourcepub fn accepted_output_modes(&self) -> &[String]
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.
Sourcepub fn with_call_context(self, call_context: CallContext) -> RequestContext
pub fn with_call_context(self, call_context: CallContext) -> RequestContext
Attaches the CallContext this execution was requested under.
Sourcepub fn caller_identity(&self) -> Option<&str>
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.
Sourcepub fn tenant(&self) -> Option<&str>
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.
Sourcepub fn http_header(&self, name: &str) -> Option<&str>
pub fn http_header(&self, name: &str) -> Option<&str>
One inbound HTTP header, matched case-insensitively.
Sourcepub fn activated_extensions(&self) -> &[String]
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.
Sourcepub fn trace_context(&self) -> Option<&TraceContext>
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 calleeNone means the caller was not tracing. It never means the SDK
invented one.
Sourcepub fn request_id(&self) -> Option<&str>
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
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for RequestContext
impl Forget for RequestContext
impl Move for RequestContext
impl RefUnwindSafe for RequestContext
impl Send for RequestContext
impl Sync for RequestContext
impl Unpin for RequestContext
impl UnsafeUnpin for RequestContext
impl UnwindSafe for RequestContext
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].