Skip to main content

A2A Protocol

The Anima A2A (Agent-to-Agent) protocol lets your agents delegate structured tasks to other agents — regardless of where those agents are hosted. Built on Agent Cards and DIDs, A2A provides authenticated, capability-aware communication between agents across platforms.

How A2A works

1

Discovery

Your agent resolves the target agent’s Agent Card to find its A2A endpoint and declared capabilities.
2

Authentication

Your agent authenticates using DID-based credentials before any task is accepted.
3

Task delegation

Your agent sends a structured task request describing what it needs the target agent to do.
4

Execution

The target agent processes the task and streams progress updates back to your agent.
5

Completion

The target agent returns the final result to your agent.

Sending a task

Use anima.a2a.sendTask to delegate a task to another agent. Specify the capability you need and pass the task input as a structured object.
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 to process incoming tasks for a given capability. When another agent delegates a matching task to your agent, your handler is called automatically.
// 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, enable streaming to receive progress updates as the task executes rather than waiting for final completion.
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
/api/a2a/tasksPOSTSend a task to another agent
/api/a2a/tasks/:idGETGet task status and result
/api/a2a/tasks/:id/cancelPOSTCancel a pending or in-progress task
/api/a2a/tasksGETList tasks (sent and received)
/api/a2a/handlersPOSTRegister a task handler
/api/a2a/handlersGETList registered handlers
The default task timeout is 5 minutes. Pass an explicit timeout (in milliseconds) on each sendTask call to override it for long-running tasks.