Skip to content

feat(a2a): negotiate A2A-Version and serve the v1.0 wire dialect beside 0.3 - #18

Open
brainsparker wants to merge 1 commit into
mainfrom
feature/2026-10-30-a2a-version-negotiation
Open

brainsparker wants to merge 1 commit into
mainfrom
feature/2026-10-30-a2a-version-negotiation

Conversation

@brainsparker

Copy link
Copy Markdown
Owner

What this does

Stock A2A v1.0 clients can now talk to a youagent server. The JSON-RPC binding negotiates the wire dialect from the A2A-Version service parameter (spec section 3.6) and serves both 0.3 and 1.0 at the same URL.

Before this change, a default @a2a-js/sdk 1.3.0 client failed on its very first call:

JsonRpcRequestMalformedError: Invalid A2A part: unknown kind null   (-32602)

because the server ignored A2A-Version: 1.0, rejected v1.0 oneof parts ({ "text": "ping" } has no kind), and would have answered in 0.3 shapes (kind discriminators, lowercase states, user / agent roles) that a 1.0 client decodes as UNRECOGNIZED.

After this change, the same client (no legacyCompat, no flags) completes SendMessage, GetTask, ListTasks, and gets properly typed errors (JsonRpcTaskNotFoundError, JsonRpcTaskNotCancelableError). I ran that smoke against both main and this branch locally; the transcript is in the test notes below.

How to use it

Nothing to configure on the server. youagent start and any A2AServer embed get it:

Request Dialect served
no A2A-Version header 0.3 (spec 3.6.2: empty means 0.3). Existing peers see no change
A2A-Version: 0.1, 0.2.x, 0.3 0.3 (youagent used to advertise 0.2.1, so those peers keep working)
A2A-Version: 1.0 (or ?A2A-Version=1.0) v1.0: TASK_STATE_*, ROLE_*, oneof parts, SendMessage wrapped as { task } / { message }, error.data as typed details led by google.rpc.ErrorInfo
anything else VersionNotSupportedError (-32009) listing the supported versions

Responses echo A2A-Version and set Vary: A2A-Version. Push-config shapes follow the negotiated version (method-name aliases still work without a header, as before). Webhooks registered under 1.0 receive a StreamResponse ({ task }) as application/a2a+json; 0.3 webhooks keep the bare Task.

On the client side, A2AClient now sends A2A-Version: 0.3 on every request (spec 3.6.1 says clients MUST). To call a server that only implements v1.0:

const client = new A2AClient(card, { protocolVersion: '1.0' });
const task = await client.sendText('https://peer.example.com/a2a', 'hello');
// task comes back in youagent's internal shape regardless of dialect

Agent cards now advertise two JSON-RPC interfaces at the same URL (protocolVersion: "1.0" then "0.3"), and the legacy top-level protocolVersion is "0.3" instead of "0.2.1", which is the dialect a pre-1.0 reader is actually served.

Why this, why today

The gap was already on the README's known-gaps list. The entry read: "the JSON-RPC binding still speaks the pre-1.0 message shape ... Migrating the binding to v1.0 (single Part with a oneof content field, TASK_STATE_* enums, wrapped stream events) is the next step." 0.2.0 shipped yesterday with A2A serving on by default from youagent start, so the server is now reachable by whatever clients exist, and the clients that exist are 1.0.

The ecosystem has moved to 1.0 as the default.

Why this beat the other candidates today. The two runners-up were (1) idempotent SendMessage on messageId plus ordered, retried push delivery (A2A discussion #1857, matched by a2a-java 1.4.0), and (2) declaring the youagent social extension in capabilities.extensions[] with A2A-Extensions header handling. Both are real, but neither unblocks anyone: today no 1.0 client can complete a single request against youagent, and every later feature (extensions, idempotency, streaming) would otherwise be built on a dialect those clients cannot read. This also stays clear of the open PRs (#10, #17 streaming; #11 auth; #12 signed cards; #14 REST binding; #15 MCP; #16 validate).

Implementation notes

  • New src/a2a/version.ts (exported from the package root): resolveProtocolVersion, outbound projections (toV1Task, toV1Message, toV1Part, toV1Result, toV1Error), inbound helpers (fromV1Part, fromV1SendMessageResult, push-config shape helpers), and the constants. The file header has a dialect comparison table.
  • The server keeps one internal shape (0.3) and projects at the transport edge. Handlers registered with onMethod get a third argument { protocolVersion }; existing two-argument handlers need no change.
  • Ingest (normalizePart, normalizeMessage, normalizeTask) now accepts v1.0 oneof parts and ROLE_* / TASK_STATE_* values alongside the 0.3 and pre-0.2 shapes. One intentional behavior change: { "text": "hi" } with no discriminator used to be rejected and is now a text part. A part with no content field at all is still rejected.
  • A2AClient.listTasks was returning raw results without normalizeTask; fixed, since 1.0 servers return TASK_STATE_* there.
  • A2A_ERROR_CODES gains -32007 to -32009 to complete the spec table.
  • Cards persisted without a version are upgraded with 0.3 instead of 0.2.1. The For You registry still stamps 0.2.0 on its hosted cards; left alone, noted in the README.
  • Not in scope: streaming event wrappers (statusUpdate, artifactUpdate) beyond push payloads, since streaming is not implemented yet; the A2A-Extensions header; tenant.

Test status

  • npm test: 180 passed (was 148). New suites: src/a2a/version.test.ts (projections, version parsing, error shaping, push-config shapes) and src/a2a/a2a-server.version.test.ts (end-to-end negotiation, 0.3 and 1.0 reads of the same task, -32009 details, query-param form, push payload dialects, client 0.3 default and 1.0 mode including the exact request shape sent).
  • Updated 4 existing assertions that pinned the old behavior (bare { text } rejection, 0.2.1 defaults, single-interface cards).
  • npm run typecheck and npm run build clean.
  • Interop smoke, run locally against the built package with @a2a-js/sdk 1.3.0, ClientFactoryOptions.default:
main:         sendMessage -> JsonRpcRequestMalformedError: Invalid A2A part: unknown kind null
this branch:  sendMessage -> state TASK_STATE_COMPLETED, history roles [ROLE_USER, ROLE_AGENT]
              getTask(historyLength: 1) -> TASK_STATE_COMPLETED, history len 1
              listTasks(status: TASK_STATE_COMPLETED) -> 1 task
              cancelTask on terminal -> JsonRpcTaskNotCancelableError
              getTask ghost -> JsonRpcTaskNotFoundError

The smoke script is not committed because it would add @a2a-js/sdk as a dev dependency; happy to add it under examples/ or as an opt-in test if you want it in CI.

…de 0.3

The JSON-RPC binding now honors the A2A-Version service parameter (spec 3.6):
empty means 0.3, 1.0 gets TASK_STATE_* and ROLE_* enums, oneof parts, wrapped
SendMessage results and typed error details, anything else gets
VersionNotSupportedError (-32009). Ingest accepts v1.0 oneof parts and enums.
A2AClient sends the header and can speak 1.0 outbound. Cards advertise both
dialects at the same URL. Verified against a stock @a2a-js/sdk 1.3.0 client.
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