<!-- source: https://deepwiki.com/MervinPraison/PraisonAI/5.3-a2a-protocol -->

# A2A Protocol

- README.md
- api.md
- src/praisonai/README.md

## Purpose and Scope

This page documents the Agent-to-Agent (A2A) Protocol implementation in PraisonAI. The A2A Protocol enables inter-agent communication, discovery, and collaboration across distributed AI systems. It allows PraisonAI agents to be exposed as discoverable services that other agents can interact with through standardized endpoints.

For information about other integration protocols, see [MCP Protocol](/MervinPraison/PraisonAI/5.2-mcp-protocol). For general agent communication patterns, see [Multi-Agent Orchestration](/MervinPraison/PraisonAI/2.5-multi-agent-orchestration).

## Overview

The A2A Protocol provides a standardized way for AI agents to:

- Publish their capabilities through agent cards (JSON metadata)
- Accept and manage tasks from other agents
- Stream results in real-time via Server-Sent Events (SSE)
- Maintain stateful task lifecycles
- Auto-generate skill descriptions from tools

The protocol implementation centers around the `A2A` class which wraps a PraisonAI `Agent` and exposes it via FastAPI endpoints following the A2A specification.

**Sources:** [README.md1483-1523](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1483-L1523)

## System Architecture

```

```

**A2A Protocol Architecture**

The diagram shows how PraisonAI agents are exposed through the A2A protocol. An `Agent` instance with its tools is wrapped by the `A2A` class, which generates agent cards, manages task state, and provides streaming capabilities. These are exposed through FastAPI endpoints that external agents can discover and interact with.

**Sources:** [README.md1483-1523](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1483-L1523) [api.md515-527](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/api.md?plain=1#L515-L527)

## Core Components

### A2A Class

The `A2A` class is the primary interface for exposing agents via the A2A protocol. It encapsulates an agent and provides HTTP endpoints for agent discovery and task execution.

**Key Initialization:**

```

```

**Sources:** [README.md1488-1512](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1488-L1512) [api.md518-520](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/api.md?plain=1#L518-L520)

### Agent Card Structure

The agent card is a JSON document served at `/.well-known/agent.json` that describes the agent's capabilities:

**Sources:** [README.md1516-1521](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1516-L1521)

### Task Management

Tasks represent units of work submitted to the agent. Each task maintains state throughout its lifecycle:

Tasks are identified by unique task IDs and can be queried for status and results.

**Sources:** [README.md1520](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1520-L1520)

## Agent Discovery Flow

```

```

**Agent Discovery Sequence**

External agents discover capabilities by requesting the well-known agent card endpoint. The A2A server auto-generates the card from the underlying Agent's properties and tools.

**Sources:** [README.md1510-1512](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1510-L1512) [README.md1516-1521](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1516-L1521)

## Task Lifecycle

```

```

**Task State Machine**

Tasks progress through states as the agent processes them. Clients can query task status via `GET /tasks/{task_id}` or stream progress via SSE at `/tasks/{task_id}/stream`.

**Sources:** [README.md1520](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1520-L1520) [README.md1521](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1521-L1521)

## API Endpoints

### Discovery Endpoint

**GET /.well-known/agent.json**

Returns the agent card describing capabilities, skills, and endpoints.

**Response Example:**

```

```

### Status Endpoint

**GET /status**

Health check endpoint indicating agent availability.

### Task Creation

**POST /tasks**

Creates a new task for the agent to execute.

**Request Body:**

```

```

**Response:**

```

```

### Task Status

**GET /tasks/{task_id}**

Retrieves current task state and results (if completed).

**Response:**

```

```

### Task Streaming

**GET /tasks/{task_id}/stream**

Streams task progress via Server-Sent Events (SSE).

**Event Format:**

```
event: progress
data: {"status": "running", "message": "Processing..."}

event: result
data: {"status": "completed", "result": "Final output"}
```

**Sources:** [README.md1510-1512](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1510-L1512) [README.md1521](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1521-L1521)

## Integration with FastAPI

```

```

**FastAPI Integration Pattern**

The A2A router is generated from the A2A instance and included in the FastAPI application. This exposes all protocol endpoints at the configured base path.

**Code Pattern:**

```

```

**Sources:** [README.md1488-1512](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1488-L1512)

## Skills Extraction

The A2A protocol automatically generates a skills list from the agent's available tools. Each tool becomes a skill entry in the agent card.

**Extraction Logic:**

The skills array in the agent card enables other agents to understand what capabilities are available before submitting tasks.

**Sources:** [README.md1519](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1519-L1519)

## Streaming Support

The A2A protocol provides Server-Sent Events (SSE) streaming for real-time task progress updates:

```

```

**SSE Streaming Flow**

Clients establish an SSE connection to receive real-time updates as the agent processes tasks. The connection remains open until task completion or failure.

**Sources:** [README.md1521](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1521-L1521)

## Usage Examples

### Basic A2A Server

```

```

### Agent Card Access

```

```

### Task Submission

```

```

**Sources:** [README.md1488-1523](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1488-L1523)

## Configuration Options

When creating an A2A instance, configure the following:

**Example with Options:**

```

```

**Sources:** [README.md1505-1506](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1505-L1506)

## Comparison: A2A vs MCP

Both protocols can be used together: an agent can expose tools via MCP while also being discoverable via A2A for task delegation.

**Sources:** [README.md1407-1482](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1407-L1482) [README.md1483-1523](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1483-L1523)

## Protocol Compliance

The PraisonAI A2A implementation follows the specification at [https://a2a-protocol.org](https://a2a-protocol.org), including:

- Standard agent card format at /.well-known/agent.json
- RESTful task management endpoints
- Server-Sent Events for streaming
- Stateful task lifecycle tracking
- Skills-based capability advertising

**Sources:** [README.md1485](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/README.md?plain=1#L1485-L1485)
