Skip to main content

A2A Protocol

The Anima A2A (Agent-to-Agent) protocol enables structured communication and task delegation between AI agents. Built on top of Agent Cards and DIDs, A2A provides authenticated, capability-aware messaging between agents regardless of their hosting platform.

How A2A Works

  1. Discovery — Agent A resolves Agent B’s Agent Card to find its A2A endpoint and capabilities
  2. Authentication — Agent A authenticates using DID-based credentials
  3. Task Delegation — Agent A sends a structured task request describing what it needs
  4. Execution — Agent B processes the task and streams progress updates
  5. Completion — Agent B returns the result to Agent A

Sending a Task

import { Anima } from "@anima-labs/sdk";

const anima = new Anima({ apiKey: "ak_..." });

// Delegate a task to another agent
const task = await anima.a2a.sendTask({
  fromAgentId: "ag_sender123",
  toAgentDid: "did:anima:ag_receiver456",
  capability: "purchase-order",
  input: {
    vendor: "Office Supplies Inc",
    items: [
      { name: "Printer paper", quantity: 10, unitPrice: 8.99 },
      { name: "Ink cartridges", quantity: 4, unitPrice: 24.99 },
    ],
    budget: 200,
  },
  timeout: 300_000, // 5 minutes
});

console.log(`Task ID: ${task.id}`);
console.log(`Status: ${task.status}`); // "pending" | "in_progress" | "completed" | "failed"

Receiving Tasks

Register a handler for incoming A2A tasks:
// Register a task handler for a capability
anima.a2a.onTask("ag_receiver456", "purchase-order", async (task) => {
  console.log(`Received task from: ${task.fromDid}`);
  console.log(`Input: ${JSON.stringify(task.input)}`);

  // Update progress
  await task.updateStatus("in_progress", { message: "Processing order..." });

  // Do the work...
  const result = await processOrder(task.input);

  // Complete the task
  await task.complete({
    orderId: result.orderId,
    totalCost: result.totalCost,
    status: "confirmed",
  });
});

Streaming Task Progress

For long-running tasks, stream progress updates back to the caller:
const task = await anima.a2a.sendTask({
  fromAgentId: "ag_sender123",
  toAgentDid: "did:anima:ag_receiver456",
  capability: "data-analysis",
  input: { dataset: "sales-2026-q1" },
  stream: true,
});

for await (const update of task.stream()) {
  console.log(`[${update.status}] ${update.message}`);
  if (update.progress) {
    console.log(`Progress: ${update.progress}%`);
  }
}

console.log(`Result: ${JSON.stringify(task.result)}`);

Task Lifecycle

StatusDescription
pendingTask submitted, awaiting processing
in_progressHandler is actively working on the task
completedTask finished successfully with a result
failedTask encountered an error
cancelledTask was cancelled by the sender
timeoutTask exceeded the configured timeout

API Reference

EndpointMethodDescription
https://api.useanima.sh/api/a2a/tasksPOSTSend a task to another agent
https://api.useanima.sh/api/a2a/tasks/:idGETGet task status and result
https://api.useanima.sh/api/a2a/tasks/:id/cancelPOSTCancel a pending/in-progress task
https://api.useanima.sh/api/a2a/tasksGETList tasks (sent and received)
https://api.useanima.sh/api/a2a/handlersPOSTRegister a task handler
https://api.useanima.sh/api/a2a/handlersGETList registered handlers

Configuration

VariableDefaultDescription
ANIMA_A2A_DEFAULT_TIMEOUT300000Default task timeout in ms (5 min)
ANIMA_A2A_MAX_PAYLOAD_KB1024Maximum task input/output size
ANIMA_A2A_REQUIRE_DID_AUTHtrueRequire DID authentication for tasks
ANIMA_A2A_STREAM_ENABLEDtrueEnable streaming task updates

Next Steps