gizai:a2a
the Agent2Agent protocol (0.3, JSON-RPC over HTTP) for agents. handle serves an agent: message/send writes to it, tasks/get reads a turn, tasks/cancel stops one; card is what it says about itself. tool is the other end: another agent, by its card, as an agent tool that sends it a message and waits for its answer.
import * as A2a from "gizai:a2a";Types
Task
type Task = { id: string; context: string; state: string; text: string; }A turn of a served agent as A2A shows it: the task's id, the conversation (context) it continues, its state (submitted, working, input-required, completed, canceled, failed) and its answer so far.
id:stringcontext:stringstate:stringtext:string
Refusal
type Refusal = { code: i64; message: string; }A JSON-RPC error: TaskNotFound -32001, UnsupportedOperation -32004, InvalidParams -32602.
code:i64message:string
Answer
type Answer = Result<Task, Refusal>A turn, or the JSON-RPC error that refuses the call.
Functions
stateOf
function stateOf(status: string): stringThe A2A state of a run's status: done, running, failed, stopped, or approval (waiting for the person).
card
function card(name: string, about: string, url: string, version: string, tags: Vec<string>, bearer: string): bytesThe card of an agent: who it is, where its JSON-RPC answers, its skill's tags, and, unless BEARER is "", that it wants a Bearer token (BEARER says where to get one).
Effects: fail.
task
function task(t: Task): JsonValueA turn as an A2A Task: its state, the answer as the status message and, once completed, as the one artifact.
Effects: fail.
textOf
function textOf(message: JsonValue): stringThe text of a Message's text parts.
Effects: fail.
handle
function handle(request: Http.Request, send: (context: string, text: string) => Answer, get: (task: string) => Answer, cancel: (task: string) => Answer): Http.ResponseOne JSON-RPC request to an agent: send(context, text) writes to it ("" for a new conversation), get(task) reads
a turn, cancel(task) stops one. Streaming and push are refused as unsupported.
Effects: fail, read, write, console, io.
isCard
function isCard(spec: JsonValue): boolWhether a description is an A2A agent card rather than an API's.
Effects: fail.
about
function about(spec: JsonValue): stringWhat a model is told an agent is good at: its description and skills.
Effects: fail.
sending
function sending(id: string, text: string, context: string): bytesThe JSON-RPC body of message/send: TEXT, continuing CONTEXT unless it is "".
Effects: fail.
getting
function getting(id: string, task: string): bytesThe JSON-RPC body of tasks/get.
Effects: fail.
heard
function heard(result: JsonValue): TaskAn agent's answer as read: a Task, or a plain Message as a completed one with no id.
Effects: fail.
settled
function settled(state: string): boolWhether a task's state is its last (or waits for the caller).
tool
function tool(sys: System, spec: JsonValue, headers: Vec<Mcp.Header>, prefix: string, inside: bool = false): Agent.ToolAnother agent, by its A2A card, as one agent tool PREFIX_ask: the model sends it a message (and the context its
last answer named, to continue), and reads its answer, a task still working read again until it ends or WAIT_MS
passes. HEADERS go with each request (its key); only the public Internet is reached unless inside. The answer
may do anything the agent does, so the tool is not read-only.
Effects: fail.
Constants
PROTOCOL
const PROTOCOL = "0.3.0"The version of the A2A protocol that the served agents speak.