Skip to main content

Module a2a_wire

Module a2a_wire 

Expand description

Shared A2A v1.0 wire types for both inbound and outbound.

Pure-Serde protocol DTOs for the A2A (Agent2Agent) v1.0 protobuf-JSON payload, aligned to the official specification and a2a.proto (package lf.a2a.v1): camelCase field names, SCREAMING_SNAKE_CASE enum values, and oneof discriminators expressed as the branch field name (no kind discriminator). Inbound (zeroclaw-gateway/src/a2a.rs) uses these to construct responses; outbound (zeroclaw-tools/src/a2a_client.rs) uses them to build requests and deserialize peer responses. Router/server-only types stay gateway-local.

This follows the established precedent of crate::jsonrpc: a dependency-light, pure-Serde wire-model source shared across crates without cross-crate coupling. No a2a-rs/protobuf footprint.

JsonSchema derives are gated behind the schema-export feature (mirrors zeroclaw-config), so consuming crates can generate OpenAPI/OPTIONS schemas from these types directly.

Structs§

AgentCapabilities
A2A AgentCapabilities — optional feature flags. Only Some values serialize; None fields are omitted.
AgentCard
A2A AgentCard (spec §14) — the discovery surface for an agent. Serializes to the protobuf-JSON wire shape.
AgentInterface
A2A AgentInterface (spec §5.8) — a declared transport interface. The first entry of supportedInterfaces is the preferred transport. tenant, when set, MUST be echoed into the tenant field of every request sent to this interface (spec §5.2).
AgentSkill
A2A AgentSkill (spec §4.4). id/name/description are spec-required.
Artifact
A2A Artifact (proto message Artifact) — a task output. parts is the same Part oneof used by messages.
JsonRpcError
A2A JSON-RPC error object.
JsonRpcRequest
A2A JSON-RPC 2.0 request envelope (spec §9).
JsonRpcResponse
A2A JSON-RPC 2.0 response envelope. Peers wrap the result payload (Task, SendMessageResponse, …) in result; errors come back as error with the spec’s negative codes. result is Option<T> so a present-but-null result deserializes to None without forcing T: Default (the response union types are untagged enums with no Default).
Message
A2A Message (proto message Message) — one unit of client/server communication. messageId and role are spec-REQUIRED on send, and parts MUST contain at least one Part (spec §5.7 REQUIRED — a list field with REQUIRED behavior must have ≥1 element).
Part
A2A Part (proto message Part) — a section of communication content. The content oneof is expressed without a discriminator: the active branch is exactly one of text / raw / url / data; the shared optional fields (metadata/filename/mediaType) ride alongside it. The oneof invariant is enforced at deserialization (via deserialize_part): a payload with zero content branches or more than one is rejected, matching the proto oneof semantics (spec §5.7 — a Part carries exactly one content branch). A struct (not an enum) lets serde handle the field-name-keyed shape directly while a custom deserializer validates the oneof invariant.
SendMessageConfiguration
SendMessageConfiguration (proto) — optional send tuning.
SendMessageParams
SendMessage request params (proto SendMessageRequest). tenant echoes the selected AgentInterface.tenant; message is REQUIRED.
Task
A2A Task (proto message Task) — returned by SendMessage / GetTask / CancelTask. Fields beyond the spec-required id/status are optional and tolerate absence: a peer that omits contextId or artifacts still parses.
TaskStatus
A2A TaskStatus (proto message TaskStatus).

Enums§

Role
A2A Role (proto enum Role) — the sender of a message. ProtoJSON serializes enum values as their SCREAMING_SNAKE_CASE proto names (spec §5.5).
SendMessageResponse
SendMessageResponse (proto message SendMessageResponse) — the oneof payload with branches task / message. Custom de/serialization enforces exactly-one branch and the flat proto-shape ({"task": {...}} / {"message": {...}}): the default externally-tagged enum serializer would nest the branch value one level too deep ({"task":{"task":{...}}}) and would not round-trip through the custom deserializer.
TaskState
A2A TaskState (proto enum TaskState) — task lifecycle state. SCREAMING_SNAKE_CASE on the wire (spec §5.5). TASK_STATE_UNSPECIFIED is rejected at deserialization: the spec marks state as REQUIRED and the default UNSPECIFIED value must not be accepted as a valid wire value.

Functions§

escape_fence_body
Unwrap a JSON-RPC response into its result, validating the transport envelope. Fails on: missing/invalid jsonrpc version (must be "2.0"), response id mismatch (when expected_id is Some), ambiguous envelope (both result and error present), missing payload (neither result nor error), and a present non-success error. Escape the XML closing-tag trigger (</) in untrusted content before it is placed inside an <a2a-* ...> provenance wrapper, so a peer-controlled value containing a closing marker such as </a2a-artifact> cannot terminate the wrapper early. The wrapper is advisory provenance (the model is already told the interior is untrusted-external), but an inert <\/ keeps marker-looking content from confusing any downstream cursor/splitter. Defined here (the api crate) so both the inbound rpc_result error path and the outbound tool renderers share one canonical implementation.
rpc_result