Skip to main content

RequestHandler

Struct RequestHandler 

Source
pub struct RequestHandler { /* private fields */ }
Expand description

Shared dispatch layer for A2A v1.0.0 operations.

Maps operation names to executor/store calls. Used by both the JSON-RPC handler and the REST handler.

When constructed with a adk_runner::RunnerConfig via RequestHandler::with_runner, message_send and message_stream invoke the agent through the ADK Runner for real LLM generation. Without a runner config, they perform state transitions only (useful for protocol-level testing).

The operation methods on RequestHandler act for an unauthenticated caller. Use for_caller to act for an authenticated one; the bundled transports do this with the principal from the request extensions.

Implementations§

Source§

impl RequestHandler

Source

pub fn new( executor: Arc<V1Executor>, task_store: Arc<dyn TaskStore>, push_sender: Arc<dyn PushNotificationSender>, agent_card: Arc<RwLock<CachedAgentCard>>, ) -> Self

Creates a new request handler without a runner (stub mode).

Source

pub fn with_runner( executor: Arc<V1Executor>, task_store: Arc<dyn TaskStore>, push_sender: Arc<dyn PushNotificationSender>, agent_card: Arc<RwLock<CachedAgentCard>>, runner_config: Arc<RunnerConfig>, ) -> Self

Creates a new request handler with a runner for real LLM invocation.

Source

pub fn with_interceptor(self, interceptor: Arc<dyn CallInterceptor>) -> Self

Runs interceptor around each operation, after the ones added before it; see CallInterceptor.

Source

pub fn with_inactivity_timeout(self, timeout: Duration) -> Self

Fails a run whose agent produces nothing for timeout, as a2a-go’s inactivity timeout does: the agent is stopped and the task fails with agent inactivity timeout.

Source

pub fn with_concurrency_limits(self, limits: ConcurrencyLimits) -> Self

Refuses a message when limits already has as many runs going, as a2a-go’s concurrency limits do (max concurrency limit reached).

Source

pub fn with_hooks(self, hooks: ExecutorHooks) -> Self

Calls hooks at their points in each run; see ExecutorHooks.

Source

pub fn with_extended_card(self, producer: ExtendedCardProducer) -> Self

Serves producer’s card for GetExtendedAgentCard, built for each caller. Without one, the method answers ExtendedAgentCardNotConfigured.

Source

pub fn with_output_mode(self, mode: OutputMode) -> Self

Lays each run’s output out in artifacts as mode says, as adk-go’s executor option of the same name. The default is OutputMode::ArtifactPerRun.

Source

pub fn for_caller(&self, caller: Option<RequestContext>) -> CallerScope<'_>

Returns a view of this handler that acts on behalf of caller.

With Some(caller), the agent session belongs to caller.user_id, every created task is owned by that user, and operations on tasks owned by anyone else fail with A2aError::TaskNotFound. With None — no authentication configured — the session user is A2A_USER_{contextId} and only ownerless tasks are visible.

§Example
ⓘ
let task = handler.for_caller(Some(request_context)).message_send(msg).await?;
Source

pub async fn require_extensions( &self, requested: &RequestedExtensions, ) -> Result<(), A2aError>

Refuses a call that leaves out an extension the agent card marks required, with ExtensionSupportRequired (-32008), as a2a-go does.

§Errors

Returns A2aError::ExtensionSupportRequired naming the first missing extension.

Source

pub async fn message_send(&self, msg: Message) -> Result<Task, A2aError>

Sends a message as an unauthenticated caller; see CallerScope::message_send.

§Errors

See CallerScope::message_send.

Source

pub async fn message_send_with( &self, msg: Message, configuration: Option<&SendMessageConfiguration>, ) -> Result<Task, A2aError>

Sends a message with the request’s configuration as an unauthenticated caller; see CallerScope::message_send_with.

§Errors

See CallerScope::message_send_with.

Source

pub async fn message_stream( &self, msg: Message, ) -> Result<BoxStream<'static, Result<StreamResponse, A2aError>>, A2aError>

Sends a streaming message as an unauthenticated caller; see CallerScope::message_stream.

§Errors

See CallerScope::message_stream.

Source

pub async fn message_stream_with( &self, msg: Message, configuration: Option<&SendMessageConfiguration>, ) -> Result<BoxStream<'static, Result<StreamResponse, A2aError>>, A2aError>

Streams a message with its configuration for an unauthenticated caller; see CallerScope::message_stream_with.

§Errors

See CallerScope::message_stream_with.

Source

pub async fn tasks_get( &self, task_id: &str, history_len: Option<u32>, ) -> Result<Task, A2aError>

Retrieves an ownerless task; see CallerScope::tasks_get.

§Errors

Returns A2aError::TaskNotFound if the task does not exist or has an owner.

Source

pub async fn tasks_cancel(&self, task_id: &str) -> Result<Task, A2aError>

Cancels an ownerless task; see CallerScope::tasks_cancel.

§Errors

See CallerScope::tasks_cancel.

Source

pub async fn tasks_list( &self, params: ListTasksParams, ) -> Result<TaskListResponse, A2aError>

Lists ownerless tasks; see CallerScope::tasks_list.

§Errors

See CallerScope::tasks_list.

Source

pub async fn tasks_subscribe( &self, task_id: &str, ) -> Result<BoxStream<'static, Result<StreamResponse, A2aError>>, A2aError>

Subscribes to an ownerless task; see CallerScope::tasks_subscribe.

§Errors

See CallerScope::tasks_subscribe.

Source

pub async fn push_config_create( &self, task_id: &str, config: TaskPushNotificationConfig, ) -> Result<TaskPushNotificationConfig, A2aError>

Creates a push notification configuration on an ownerless task; see CallerScope::push_config_create.

§Errors

Returns A2aError::TaskNotFound if the task does not exist or has an owner.

Source

pub async fn push_config_get( &self, task_id: &str, config_id: &str, ) -> Result<TaskPushNotificationConfig, A2aError>

Retrieves a push notification configuration from an ownerless task; see CallerScope::push_config_get.

§Errors

Returns A2aError::TaskNotFound if the task or config does not exist.

Source

pub async fn push_config_list( &self, task_id: &str, ) -> Result<Vec<TaskPushNotificationConfig>, A2aError>

Lists the push notification configurations of an ownerless task; see CallerScope::push_config_list.

§Errors

Returns A2aError::TaskNotFound if the task does not exist or has an owner.

Source

pub async fn push_config_delete( &self, task_id: &str, config_id: &str, ) -> Result<(), A2aError>

Deletes a push notification configuration from an ownerless task; see CallerScope::push_config_delete.

§Errors

Returns A2aError::TaskNotFound if the task or config does not exist.

Source

pub async fn agent_card_extended(&self) -> Result<AgentCard, A2aError>

Returns the extended agent card for an unauthenticated caller; see agent_card_extended_for.

§Errors

See agent_card_extended_for.

Source

pub async fn agent_card_extended_for( &self, caller: Option<RequestContext>, ) -> Result<AgentCard, A2aError>

Returns the extended agent card for caller, from the handler’s ExtendedCardProducer, as a2a-go serves it.

§Errors

Returns A2aError::UnsupportedOperation when the agent card says the agent offers no extended card (capabilities.extendedAgentCard: false), A2aError::ExtendedAgentCardNotConfigured when the handler has no producer, and the producer’s own error.

Source

pub fn executor(&self) -> &Arc<V1Executor> ⓘ

Returns a reference to the underlying executor.

Source

pub fn task_store(&self) -> &Arc<dyn TaskStore> ⓘ

Returns a reference to the underlying task store.

Auto Trait Implementations§

§

impl !Freeze for RequestHandler

§

impl !RefUnwindSafe for RequestHandler

§

impl !UnwindSafe for RequestHandler

§

impl Forget for RequestHandler

§

impl Move for RequestHandler

§

impl Send for RequestHandler

§

impl Sync for RequestHandler

§

impl Unpin for RequestHandler

§

impl UnsafeUnpin for RequestHandler
where *const ArcInner<V1Executor> is !null: UnsafeUnpin, PhantomData<ArcInner<V1Executor>>: UnsafeUnpin, *const ArcInner<dyn TaskStore> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn TaskStore>>: UnsafeUnpin, *const ArcInner<RwLock<CachedAgentCard>> is !null: UnsafeUnpin, PhantomData<ArcInner<RwLock<CachedAgentCard>>>: UnsafeUnpin, *const ArcInner<RunnerConfig> is !null: UnsafeUnpin, PhantomData<ArcInner<RunnerConfig>>: UnsafeUnpin, Align4<u32>: UnsafeUnpin, Align1<u8>: UnsafeUnpin, *const Waiter is !null: UnsafeUnpin, Align8<usize>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<((Option<String>, String), String)>: UnsafeUnpin, *const ArcInner<RunningTasks> is !null: UnsafeUnpin, PhantomData<ArcInner<RunningTasks>>: UnsafeUnpin, *const ArcInner<dyn Fn(Option<RequestContext>) -> Pin<Box<dyn Future<Output = Result<AgentCard, A2aError>> + Send>> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(Option<RequestContext>) -> Pin<Box<dyn Future<Output = Result<AgentCard, A2aError>> + Send>> + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(Arc<ExecutionContext>) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send>> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(Arc<ExecutionContext>) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send>> + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(&ExecutionContext, &Event, &mut ArtifactUpdate) -> Result<(), A2aError> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&ExecutionContext, &Event, &mut ArtifactUpdate) -> Result<(), A2aError> + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(&ExecutionContext, &mut FinalStatus) -> Result<(), A2aError> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&ExecutionContext, &mut FinalStatus) -> Result<(), A2aError> + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(&Event, &Part) -> Result<Option<Part>, A2aError> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&Event, &Part) -> Result<Option<Part>, A2aError> + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(&Part) -> Result<Option<Part>, A2aError> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&Part) -> Result<Option<Part>, A2aError> + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(&ExecutionContext, &TaskStatusUpdateEvent) + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&ExecutionContext, &TaskStatusUpdateEvent) + Sync + Send>>: UnsafeUnpin, *const ArcInner<RunLimiter> is !null: UnsafeUnpin, PhantomData<ArcInner<RunLimiter>>: UnsafeUnpin, PhantomData<Arc<dyn CallInterceptor>>: UnsafeUnpin,

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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, 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