A2A Agent Delegation
CrewAI treats A2A protocol as a first-class delegation primitive, enabling agents to delegate tasks, request information, and collaborate with remote agents, as well as act as A2A-compliant server agents. In client mode, agents autonomously choose between local execution and remote delegation based on task requirements.How It Works
When an agent is configured with A2A capabilities:- The Agent analyzes each task
- It decides to either:
- Handle the task directly using its own capabilities
- Delegate to a remote A2A agent for specialized handling
- If delegating, the agent communicates with the remote A2A agent through the protocol
- Results are returned to the CrewAI workflow
A2A delegation requires the
a2a-sdk package. Install with: uv add 'crewai[a2a]' or pip install 'crewai[a2a]'Basic Configuration
Configure an agent for A2A delegation by setting thea2a parameter:
Code
Client Configuration Options
TheA2AClientConfig class accepts the following parameters:
The A2A agent endpoint URL (typically points to
.well-known/agent-card.json)Authentication scheme for the A2A agent. Supports Bearer tokens, OAuth2, API keys, and HTTP authentication.
Request timeout in seconds
Maximum number of conversation turns with the A2A agent
Optional Pydantic model for requesting structured output from an A2A agent. A2A protocol does not
enforce this, so an A2A agent does not need to honor this request.
Whether to raise an error immediately if agent connection fails. When
False, the agent continues with available agents and informs the LLM about unavailable ones.When
True, returns the A2A agent’s result directly when it signals completion. When False, allows the server agent to review the result and potentially continue the conversation.Update mechanism for receiving task status. Options:
StreamingConfig, PollingConfig, or PushNotificationConfig.Transport protocol for A2A communication. Options:
JSONRPC (default), GRPC, or HTTP+JSON.Media types the client can accept in responses.
Ordered list of transport protocols the client supports.
Whether to prioritize client transport preferences over server.
Extension URIs the client supports.
Authentication
For A2A agents that require authentication, use one of the provided auth schemes:- Bearer Token
- API Key
- OAuth2
- HTTP Basic
bearer_token_auth.py
Multiple A2A Agents
Configure multiple A2A agents for delegation by passing a list:Code
Error Handling
Control how agent connection failures are handled using thefail_fast parameter:
Code
fail_fast=False:
- If some agents fail, the LLM is informed which agents are unavailable and can delegate to working agents
- If all agents fail, the LLM receives a notice about unavailable agents and handles the task directly
- Connection errors are captured and included in the context for better decision-making
Update Mechanisms
Control how your agent receives task status updates from remote A2A agents:- Streaming (Default)
- Polling
- Push Notifications
streaming_config.py
Exposing Agents as A2A Servers
You can expose your CrewAI agents as A2A-compliant servers, allowing other A2A clients to delegate tasks to them.Server Configuration
Add anA2AServerConfig to your agent to enable server capabilities:
a2a_server_agent.py
Server Configuration Options
Human-readable name for the agent. Defaults to the agent’s role if not provided.
Human-readable description. Defaults to the agent’s goal and backstory if not provided.
Version string for the agent card.
List of agent skills. Auto-generated from agent tools if not provided.
Declaration of optional capabilities supported by the agent.
Supported input MIME types.
Supported output MIME types.
Preferred endpoint URL. If set, overrides the URL passed to
to_agent_card().Transport protocol for the preferred endpoint.
A2A protocol version this agent supports.
Information about the agent’s service provider.
URL to the agent’s documentation.
URL to an icon for the agent.
Additional supported interfaces (transport and URL combinations).
Security requirement objects for all agent interactions.
Security schemes available to authorize requests.
Whether agent provides extended card to authenticated users.
JSON Web Signatures for the AgentCard.
Combined Client and Server
An agent can act as both client and server by providing both configurations:Code
Best Practices
Set Appropriate Timeouts
Configure timeouts based on expected A2A agent response times. Longer-running tasks may need higher timeout values.
Limit Conversation Turns
Use
max_turns to prevent excessive back-and-forth. The agent will automatically conclude conversations before hitting the limit.Use Resilient Error Handling
Set
fail_fast=False for production environments with multiple agents to gracefully handle connection failures and maintain workflow continuity.Secure Your Credentials
Store authentication tokens and credentials as environment variables, not in code.
Monitor Delegation Decisions
Use verbose mode to observe when the LLM chooses to delegate versus handle tasks directly.
Supported Authentication Methods
- Bearer Token - Simple token-based authentication
- OAuth2 Client Credentials - OAuth2 flow for machine-to-machine communication
- OAuth2 Authorization Code - OAuth2 flow requiring user authorization
- API Key - Key-based authentication (header, query param, or cookie)
- HTTP Basic - Username/password authentication
- HTTP Digest - Digest authentication (requires
httpx-authpackage)
