Agent-to-Agent Protocol (A2A)
The Agent-to-Agent (A2A) protocol allows AgentOS instances to discover, connect, and delegate tasks to each other. Built on JSON-RPC 2.0 with AgentCard discovery, A2A enables decentralized multi-agent systems that span organizational boundaries.Overview
Implemented insrc/a2a.ts:1 and src/a2a-cards.ts:1, A2A provides:
- JSON-RPC 2.0 transport for agent communication
- AgentCard discovery via
.well-known/agent.json - Task lifecycle with states: submitted → working → completed/failed
- Multi-turn conversations with message history
- Agent skill advertising with 15,000+ SkillKit skills
Core Concepts
AgentCard
Machine-readable description of an agent’s capabilities, skills, and endpoint
Tasks
Work items sent between agents with status tracking and history
JSON-RPC 2.0
Standard protocol for remote procedure calls over HTTP
AgentCard Structure
Fromsrc/a2a-cards.ts:9-22:
Discovering Agents
Fetch the AgentCard
Every A2A-compatible agent exposes an AgentCard at From
/.well-known/agent.json:src/a2a.ts:461-494, the discovery function:- Fetches
{url}/.well-known/agent.json - Caches the card in state
- Returns the discovered capabilities
Sending Tasks
Send a Task to Another Agent
src/a2a.ts:196-276, the task is:
- Created with a unique ID
- Sent via JSON-RPC POST to the agent’s URL
- Stored locally for tracking
- Added to the task order queue
Check Task Status
Cancel a Task
Task States
Fromsrc/a2a.ts:10-16:
Message Structure
Fromsrc/a2a.ts:18-30:
Receiving Tasks
AgentOS automatically handles incoming A2A tasks via thea2a::handle_task function (src/a2a.ts:321-459):
agent::chat and updates the task status.
JSON-RPC Methods
From the implementation:tasks/send
Create a new task:
tasks/get
Retrieve task status:
tasks/cancel
Cancel a running task:
Real-World Example: Multi-Agent Research
Exposing Your AgentCard
Generate a Card
src/a2a.ts:142-194, this generates a card and stores it at state::set("a2a", "agent_card").
Serve the Card
The card is automatically served at/.well-known/agent.json via HTTP trigger (src/a2a.ts:497-501).
List All Agent Cards
Task Limits
Fromsrc/a2a.ts:72:
- MAX_TASKS: 1000 tasks stored per instance
- Oldest tasks are automatically evicted when limit is reached
- Task order is maintained in
state::set("a2a_tasks", "_order")
HTTP API Endpoints
Security Considerations
SSRF Protection
SSRF Protection
From
src/a2a.ts:114, all URLs are validated with assertNoSsrf() to prevent Server-Side Request Forgery attacks.Authentication Required
Authentication Required
Task handling requires authentication via
requireAuth() (see src/a2a.ts:328).Rate Limiting
Rate Limiting
Consider implementing rate limits on the A2A RPC endpoint to prevent abuse.
Agent Verification
Agent Verification
Verify AgentCards are served over HTTPS and validate signatures if available.
Best Practices
Use SessionIDs
Maintain conversation context across multiple task invocations
Set Timeouts
Poll with exponential backoff and set max wait times
Handle Failures
Check for “failed” state and implement retry logic
Advertise Skills
Include relevant skills in your AgentCard for discoverability
Related Features
- Swarms - Coordinate local agents before delegating to A2A
- MCP Integration - Combine A2A with Model Context Protocol
- SkillKit - Advertise SkillKit skills in your AgentCard