Skip to main content

RequestContext

Struct RequestContext 

Source
#[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
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: String

The 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: 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: String, ) -> RequestContext

Creates a new RequestContext.

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

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:

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

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

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

Source§

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.

Source§

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

Source§

fn from_ref(input: &T) -> T

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

impl<T> FutureExt for T

Source§

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

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

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

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

impl<T> Instrument for T

Source§

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

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

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

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

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

impl<L> LayerExt<L> for L

Source§

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

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

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

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