Source:
examples/agent-with-sub-agentsOverview
This template shows how to deploy multiple specialist agents from a single service using theapp/agents/ directory. Each file in app/agents/ becomes an independent A2A endpoint alongside the main app/agent.ts coordinator.
The example has three agents and two tools:
- Coordinator (
app/agent.ts) — routes users to the right specialist - Math specialist (
app/agents/math.ts) — performs arithmetic using thecalculatetool - Text specialist (
app/agents/text.ts) — analyzes text using theword-counttool
Project Structure
Endpoints
A single deployment exposes three independent A2A endpoints:| Endpoint | Agent | Description |
|---|---|---|
/agent | Coordinator | Routes users to specialists |
/math/agent | Math | Arithmetic calculations |
/text/agent | Text | Word / character / sentence count |
/.well-known/agent-card.json | Coordinator | A2A discovery card |
/math/.well-known/agent-card.json | Math | A2A discovery card |
/text/.well-known/agent-card.json | Text | A2A discovery card |
/mcp | — | MCP tool endpoint |
Sub-Agent Definition
Each file inapp/agents/ follows the same pattern as app/agent.ts:
math.ts) determines the URL prefix (/math/agent).
Key Features
- Auto-discovery — All
.tsfiles inapp/agents/are automatically registered - Independent endpoints — Each sub-agent gets its own A2A endpoint and agent card
- Shared tools via MCP — Tools in
app/tools/are exposed on a single/mcpendpoint - Mixed deployment —
app/agent.tsandapp/agents/can coexist in the same project
Running
http://localhost:3000:
| Endpoint | Protocol | Description |
|---|---|---|
/.well-known/agent-card.json | A2A | Coordinator discovery |
/agent | A2A | Coordinator JSON-RPC |
/math/.well-known/agent-card.json | A2A | Math sub-agent discovery |
/math/agent | A2A | Math sub-agent JSON-RPC |
/text/.well-known/agent-card.json | A2A | Text sub-agent discovery |
/text/agent | A2A | Text sub-agent JSON-RPC |
/mcp | MCP | Shared tool endpoint |