a2a

The A2A (Agent-to-Agent) extension implements the A2A protocol for agent discovery and inter-agent communication.

Installation

bun add @regent/a2a

Basic Usage

import { createAgent } from '@regent/core';
import { http } from '@regent/http';
import { a2a } from '@regent/a2a';

const agent = await createAgent({
  name: 'my-agent',
  version: '1.0.0',
})
  .use(http())
  .use(a2a())
  .build();

// Build this agent's card
const card = agent.a2a.buildCard('https://my-agent.example.com');

// Fetch another agent's card
const otherCard = await agent.a2a.fetchCard('https://other-agent.example.com');

// Invoke another agent
const result = await agent.a2a.client.invoke(otherCard, 'echo', { text: 'hello' });

API Reference

a2a()

Creates the A2A extension.

A2ARuntime

When the extension is used, agent.a2a provides:

Agent Cards

Building Cards

Returns an AgentCardWithEntrypoints containing:

  • Agent identity (name, version, description)

  • Skills derived from entrypoints

  • Capabilities (streaming, pushNotifications, stateTransitionHistory)

  • Full entrypoints manifest

Fetching Cards

Discovery paths (tried in order):

  1. Direct URL (for ERC-8004)

  2. /.well-known/agent-card.json

  3. /.well-known/agent.json

  4. /agentcard.json

AgentCard Structure

Card Utilities

A2A Client

The client object provides methods for calling other agents.

Direct Invocation

invoke()

Directly invoke an entrypoint:

Endpoint: POST /entrypoints/{skillId}/invoke

stream()

Stream responses:

Endpoint: POST /entrypoints/{skillId}/stream

fetchAndInvoke()

Convenience method:

Task-Based Operations

Task-based operations enable asynchronous, multi-turn interactions.

Sending Messages

Endpoint: POST /tasks

Getting Task Status

Status values: 'running' | 'completed' | 'failed' | 'cancelled'

Subscribing to Updates

Endpoint: GET /tasks/{taskId}/subscribe (SSE)

Listing Tasks

Cancelling Tasks

Waiting for Tasks

Multi-Turn Conversations

Use contextId to maintain conversation context:

A2AClient Interface

Types

InvokeAgentResult

SendMessageResponse

Task

ListTasksRequest

ListTasksResponse

Exports

Last updated