Skip to content

feat(rig-a2a): expose activated extensions to the agent run - #85

Merged
pingedbrain merged 3 commits into
mainfrom
feat-a2a-048-ext-context
Nov 29, 2026
Merged

pingedbrain merged 3 commits into
mainfrom
feat-a2a-048-ext-context

Conversation

@pingedbrain

@pingedbrain pingedbrain commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Additive; ships in 0.47.7.

Non-breaking. This adds one public function and changes no existing signature or behavior. It is a normal feat(rig-a2a): change, not !.

What

A tool or hook in an agent run can now call rig_a2a::activated_extensions() to get the declared extension URIs its request activated. The list is sorted, holds only URIs declared with A2aServer::extension, and is empty when nothing was activated or when called outside a run.

Why

The server echoed activated extensions but the agent run could not see them. Earlier attempts found no place that did not change a signature.

Design choice

Two parts:

  1. Source: the executor's ExecutorContext::service_params. The A2A SDK already fills this from the request headers for both the JSON-RPC and HTTP+JSON bindings. The v0.3 middleware already copies X-A2A-Extensions into A2A-Extensions before the SDK sees it. So the executor reads one key (a2a-extensions) and gets both protocol versions with no new middleware. The executor gets the declared list from A2aServer::into_router through a crate-private setter.
  2. Delivery: a tokio task-local, set around each poll of the run. The SDK runs execute in a spawned task (tokio::spawn in drive_execution), so a task-local set in the axum middleware would not reach the run. Setting it around each stream.next() poll and around the typed-run future keeps the value in scope for tool calls. Rig does not spawn tasks for tool calls, so tools see it. Streaming and non-streaming both go through this same run loop.

Rejected: a field on a new per-request context passed to a custom handler. Rig's Tool::call has no such argument, so it would force tools to take a new type.

Changes

  • src/executor.rs: the task-local, activated_extensions(), the parsing, a declared field, and the scoped polls.
  • src/server.rs: the declared list is computed before the handler and passed to the executor. The extension docs point to the new function.
  • src/lib.rs: re-export. Cargo.toml: tokio rt feature for task_local!.
  • tests/integration/extensions.rs: a tool records what it sees. Covers v1.0 and v0.3, message:send/message:stream and message/send/message/stream. A request activating one declared and one undeclared URI sees only the declared one. A request with no header sees an empty list.
  • README (extensions section) and CHANGELOG (## Unreleased).

How verified

  • cargo fmt --all -- --check
  • cargo clippy -p rig-a2a --all-targets --all-features -- -D warnings
  • cargo test -p rig-a2a --all-features (all pass, including the two new tests and the new doctest)
  • RUSTDOCFLAGS=-Dwarnings cargo doc -p rig-a2a --no-deps --all-features

Limits (added after review)

  • The list is visible only on the task that polls the run. A tool that uses tokio::spawn, spawn_blocking or another thread sees an empty list. Tests cover this.
  • On v0.3 the contract header is X-A2A-Extensions. A plain A2A-Extensions header sent to v0.3 is also seen, since the SDK reads that key. A test pins this.
  • Tests also cover the typed run (A2aExecutor::typed) on both surfaces, streaming and not.

A tool or hook can call rig_a2a::activated_extensions() during a run to
read the declared extension URIs the request activated. The executor reads
them from the request's service params, which the SDK already fills from
the headers, so v1.0 and v0.3 share one path. The list is set per poll of
the run, so streaming and non-streaming calls both see it.
Document that a tool running on a spawned task or another thread sees an
empty list, so it reads the list first. Note that a plain A2A-Extensions
header on the v0.3 surface is also seen. Add tests for the typed run and
for a tool that spawns a task.
@pingedbrain
pingedbrain marked this pull request as ready for review November 29, 2026 02:36
@pingedbrain
pingedbrain enabled auto-merge (squash) November 29, 2026 02:36
# Conflicts:
#	crates/rig-a2a/CHANGELOG.md
#	crates/rig-a2a/tests/integration/extensions.rs
@pingedbrain
pingedbrain merged commit 9dc1a08 into main Nov 29, 2026
9 checks passed
@pingedbrain
pingedbrain deleted the feat-a2a-048-ext-context branch November 29, 2026 03:42
@pingedbrain pingedbrain mentioned this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant