Skip to content
Back to skills

A2a Agent Networking

ASecurity

Expose agents as A2A JSON-RPC servers discoverable via Agent Cards, and connect agents to remote A2A agents using the client discovery and capability-matching APIs.

  • 33 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added October 11, 2026
ai-agentstypescriptgoreactcode-reviewapi

Works with

  • terminal
  • cli
  • api

Security analysis

A100/100

Scanned December 5, 2026

npx -y skills add tylerjrbuell/reactive-agents-ts --skill a2a-agent-networking --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of A2a Agent Networking?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for A2a Agent Networking
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tylerjrbuell-a2a-agent-networking/badge)](https://www.skillsdirectory.com/skills/tylerjrbuell-a2a-agent-networking)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: a2a-agent-networking
description: Expose agents as A2A JSON-RPC servers discoverable via Agent Cards, and connect agents to remote A2A agents using the client discovery and capability-matching APIs.
compatibility: Reactive Agents TypeScript projects using @reactive-agents/*
metadata:
  author: reactive-agents
  version: "2.1"
  tier: "capability"
---

# Agent-to-Agent (A2A) Networking

## Agent objective

Serve a built agent over A2A with `agent.serveA2A()` (`.withA2A()` only sets its defaults), or connect to remote A2A agents using the client APIs from `@reactive-agents/a2a`.

## When to load this skill

- Exposing an agent as a remotely callable A2A service
- Connecting a lead agent to remote specialist agents at different URLs
- Discovering available agents in a network via Agent Cards
- Building agent microservices that communicate over HTTP

## Implementation baseline

### Exposing an agent as an A2A server

```ts
import { ReactiveAgents } from "reactive-agents";

const agent = await ReactiveAgents.create()
  .withName("specialist")
  .withProvider("anthropic")
  .withReasoning({ defaultStrategy: "adaptive", maxIterations: 10 })
  .withTools({ allowedTools: ["web-search", "http-get", "checkpoint"] })
  .withA2A({ port: 8000 })   // defaults only: no server starts here
  .build();

const handle = await agent.serveA2A({
  onError: (error) => console.error("A2A run failed:", error), // failed-run detail; callers never see it
});

// Agent is now discoverable at:
//   GET  http://127.0.0.1:8000/.well-known/agent.json  (Agent Card)
//   POST http://127.0.0.1:8000/                        (JSON-RPC 2.0)

// ...later
await handle.stop();
```

### Connecting from a lead agent

```ts
const lead = await ReactiveAgents.create()
  .withProvider("anthropic")
  .withReasoning({ defaultStrategy: "plan-execute-reflect", maxIterations: 20 })
  .withRemoteAgent("specialist", "http://specialist-service:8000")
  // Registers the remote A2A agent as a callable tool named "specialist"
  .withTools({ allowedTools: ["specialist", "checkpoint", "final-answer"] })
  .build();
```

## Key patterns

### serveA2A() — expose as A2A server

```ts
await agent.serveA2A()
// Port from .withA2A(), else 3000; basePath "/"; binds 127.0.0.1
// Endpoints:
//   GET  /.well-known/agent.json  → Agent Card (also GET /agent/card)
//   POST /                        → JSON-RPC 2.0 (message/send, tasks/get, tasks/cancel, agent/card)

await agent.serveA2A({ port: 8000, basePath: "/api/agents" })
// Agent Card at: http://127.0.0.1:8000/api/agents/.well-known/agent.json
// RPC at:        POST http://127.0.0.1:8000/api/agents
```

`serveA2A()` options override `.withA2A()`: `port`, `basePath`, `hostname`, `token`, `name`, `description`, `onError`. A non-loopback `hostname` needs `token` (or `RA_A2A_TOKEN`).

A run that does not succeed ends as a failed task. A run that fails with an `error`, or whose `run()` rejects, gets `Agent run failed`; an abstention gets `Agent declined to complete the task: <reason>`. The error detail goes only to `onError` (default: one line on stderr).

### A2A client — discover and call agents

```ts
import {
  A2AClient,
  createA2AClient,
  discoverAgent,
  discoverMultipleAgents,
  matchCapabilities,
  findBestAgent,
} from "@reactive-agents/a2a";
import { Effect } from "effect";

// Discover a single agent's card (.well-known/agent.json, then /agent/card)
const program = Effect.gen(function* () {
  const card = yield* discoverAgent("http://specialist:8000");
  console.log("Agent name:", card.name);
  console.log("Skills:", card.skills);
});

// Discover multiple agents (up to 5 concurrently)
const multi = Effect.gen(function* () {
  const cards = yield* discoverMultipleAgents([
    "http://researcher:8001",
    "http://coder:8002",
    "http://reviewer:8003",
  ]);
  // Best match by skill ids, tags or input modes: { agent, score, matchedSkills } | undefined
  const best = findBestAgent(cards, { skillIds: ["code-review"], tags: ["review"] });
  const ranked = matchCapabilities(cards, { tags: ["research"] });
});

// Direct A2A client call: the client is a Layer bound to one agent's base URL
const call = Effect.gen(function* () {
  const client = yield* A2AClient;
  const task = yield* client.sendMessage({
    message: { role: "user", parts: [{ kind: "text", text: "Analyze this dataset..." }] },
    configuration: { blocking: true }, // wait for a terminal state; default returns "working" and you poll getTask
  });
  console.log(task.status.state); // "completed" | "failed" | ...
}).pipe(Effect.provide(createA2AClient({ baseUrl: "http://specialist:8000" })));
```

### Generating Agent Cards

```ts
import { generateAgentCard, toolsToSkills } from "@reactive-agents/a2a";

const card = generateAgentCard({
  name: "Data Analyst",
  description: "Analyzes datasets and produces statistical summaries",
  skills: toolsToSkills(myTools),   // converts ToolDefinition[] to A2A skill format
  version: "1.0.0",
  url: "http://analyst-agent:8000",
});
```

### A2A vs withRemoteAgent()

Two ways to connect to remote agents:

```ts
// Option 1: withRemoteAgent() on the builder (simpler — agent-as-tool pattern)
.withRemoteAgent("analyst", "http://analyst:8000")
// The remote agent appears as a tool named "analyst" in the LLM's tool list.
// No client code needed — the framework handles the A2A protocol.

// Option 2: A2AClient directly (more control — for custom orchestration)
import { A2AClient } from "@reactive-agents/a2a";
// Use when you need capability discovery, load balancing, or custom retry logic.
```

## Options reference

`.withA2A(options)` sets defaults; `agent.serveA2A(options)` overrides them and starts the server.

| Field | Type | Default | Notes |
|-------|------|---------|-------|
| `port` | `number` | `3000` | HTTP port for the A2A server |
| `basePath` | `string` | `"/"` | Prefix for every A2A route |
| `hostname` | `string` | `127.0.0.1` | `serveA2A()` only. Non-loopback needs `token` |
| `token` | `string` | `RA_A2A_TOKEN` | `serveA2A()` only. Required `Authorization: Bearer <token>` |
| `onError` | `(error: unknown) => void` | one stderr line | `serveA2A()` only. Receives a failed run's error |

## Endpoints exposed by serveA2A()

| Endpoint | Method | Description |
|----------|--------|-------------|
| `<basePath>/.well-known/agent.json` | GET | Agent Card (capabilities, skills, metadata) |
| `<basePath>/agent/card` | GET | Agent Card, fallback path |
| `<basePath>` (default `/`) | POST | JSON-RPC 2.0: `message/send`, `tasks/get`, `tasks/cancel`, `agent/card` |

## Pitfalls

- `.withA2A()` does not start a server; `build()` binds nothing. Call `await agent.serveA2A()` and keep the process alive (combine with `.withGateway()` for persistent agents)
- Port conflicts surface when `serveA2A()` binds, not at `build()`
- Remote callers never get a run's error text, only `Agent run failed` or the abstention reason. Log the detail with `onError`
- Agent Cards are generated from the agent's name, description, and registered tools — populate `.withName()` for a meaningful card
- A2A uses JSON-RPC 2.0 over HTTP — ensure firewalls and network policies allow traffic between agent services on the configured ports
- Each `serveA2A()` call binds its own server — `port` must be unique per server to avoid conflicts

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.