#[non_exhaustive]pub struct RequestContext {
pub message: Message,
pub task_id: TaskId,
pub context_id: String,
pub stored_task: Option<Task>,
pub metadata: Option<Value>,
pub cancellation_token: CancellationToken,
pub call_context: Option<CallContext>,
}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: StringThe conversation context identifier.
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: String,
) -> RequestContext
pub fn new( message: Message, task_id: TaskId, context_id: String, ) -> RequestContext
Creates a new RequestContext.
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 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).
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:
if let Some(tc) = ctx.trace_context() {
CurrentTrace::scope(tc.clone(), async {
client.send_message(params).await
})
.await?;
}None 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 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§
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,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request