Skip to main content

A2A (Agent2Agent Protocol)

PraisonAI supports the A2A Protocol for agent-to-agent communication, enabling your agents to be discovered and collaborate with other AI agents.

Overview

The A2A Protocol is an open standard for inter-agent communication that enables:
  • Discovery: Agents publish Agent Cards for discovery by other agents
  • Collaboration: Agents can delegate tasks and exchange context
  • Interoperability: Works with any A2A-compatible agent system

Quick Start

from praisonaiagents import Agent, A2A
from fastapi import FastAPI

# Create an agent with tools
def search_web(query: str) -> str:
    """Search the web for information."""
    return f"Results for: {query}"

agent = Agent(
    name="Research Assistant",
    role="Research Analyst",
    goal="Help users research topics",
    tools=[search_web]
)

# Expose as A2A Server
a2a = A2A(agent=agent, url="http://localhost:8000/a2a")

app = FastAPI()
app.include_router(a2a.get_router())

# Run with: uvicorn app:app --reload

Endpoints

EndpointMethodDescription
/.well-known/agent.jsonGETAgent Card for discovery
/statusGETServer status

Agent Card

The Agent Card is a JSON metadata document that describes your agent’s capabilities:
{
  "name": "Research Assistant",
  "url": "http://localhost:8000/a2a",
  "version": "1.0.0",
  "description": "Research Analyst. Help users research topics",
  "capabilities": {
    "streaming": true,
    "pushNotifications": false
  },
  "skills": [
    {
      "id": "search_web",
      "name": "search_web",
      "description": "Search the web for information.",
      "tags": ["tool"]
    }
  ],
  "provider": {
    "name": "PraisonAI"
  }
}

Configuration Options

a2a = A2A(
    agent=agent,                    # PraisonAI Agent instance
    name="Custom Name",             # Override agent name
    description="Custom description",
    url="http://localhost:8000/a2a", # A2A endpoint URL
    version="1.0.0",                # Agent version
    prefix="/api",                  # Router prefix
    tags=["A2A", "Research"]        # OpenAPI tags
)

Multi-Agent Support

You can also expose multi-agent workflows:
from praisonaiagents import Agent, PraisonAIAgents, Task, A2A
from fastapi import FastAPI

# Create agents
researcher = Agent(name="Researcher", role="Research Analyst", goal="Research topics")
writer = Agent(name="Writer", role="Content Writer", goal="Write content")

# Create tasks
task1 = Task(description="Research AI trends", agent=researcher)
task2 = Task(description="Write a report", agent=writer)

# Create multi-agent system
agents = PraisonAIAgents(agents=[researcher, writer], tasks=[task1, task2])

# Expose as A2A Server
a2a = A2A(agents=agents, url="http://localhost:8000/a2a")

app = FastAPI()
app.include_router(a2a.get_router())

Docker Deployment

FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
requirements.txt:
praisonaiagents
fastapi
uvicorn

Features

FeatureDescription
Agent CardJSON metadata for agent discovery
Skills ExtractionAuto-generate skills from tools
Task ManagementStateful task lifecycle
StreamingSSE streaming for real-time updates
Lazy LoadingNo performance impact when not used

A2A Protocol Concepts

Task States

Tasks in A2A go through a lifecycle:
  • submitted - Task received
  • working - Agent is processing
  • input-required - Waiting for user input
  • completed - Task finished successfully
  • failed - Task failed
  • cancelled - Task was cancelled

Message Parts

A2A messages can contain different types of content:
  • TextPart - Plain text content
  • FilePart - File references (URI or bytes)
  • DataPart - Structured JSON data

Artifacts

Artifacts are outputs generated by the agent:
from praisonaiagents.ui.a2a import Artifact, TextPart

artifact = Artifact(
    artifact_id="report-001",
    name="Research Report",
    description="AI trends analysis",
    parts=[TextPart(text="Report content...")]
)

Examples

See the examples/python/a2a directory for complete examples.