A2A and MCP in Practice: Agent Task Handoff and Recovery
Protocol interaction examples; not tested end to end.
A support system has two agents: a coordinator agent facing the user, deciding “who should look at this ticket”; and a ticket-analysis agent, a specialist at finding root causes and proposing fixes. The handoff between them is A2A. Where the ticket data lives, which tools get called, and how permissions are granted happen inside the specialist (that side is MCP — see the boundary at the end); A2A governs what happens between the two agents: discovery, task state, messages, artifacts, and recovery.
| A2A — between the two agents | MCP — inside the specialist | |
|---|---|---|
| What it owns | discovery, task state, messages, artifacts | ticket data access, controlled tools, permissions |
| How they combine | the coordinator hands the task over A2A | the specialist uses MCP to do the work it was handed |
| When it fails | timeouts, dropped streams, required authorization — recovery | The specialist may retry or recover under its application policy. It sets AUTH_REQUIRED when additional authorization is needed, or FAILED when the task cannot be completed. |
The comparison page A2A and MCP covers the general division between the two protocols; this page goes deep on the agent task handoff side.
Prerequisites: state and message semantics in the Task runtime guide , idempotency and recovery patterns in Task idempotency and recovery . This page walks them through one scenario.
Walkthrough overview
This walkthrough uses non-blocking SendMessage followed by GetTask polling. It requires neither streaming nor push. All JSON below is illustrative, not a transcript from a running endpoint.
sequenceDiagram
participant C as Coordinating agent
participant S as Specialist agent
C->>S: GET /.well-known/agent-card.json
C->>S: SendMessage (m1, returnImmediately=true)
S-->>C: result.task (TASK_STATE_WORKING, id, contextId)
C->>S: GetTask (id)
S-->>C: result (TASK_STATE_INPUT_REQUIRED)
C->>S: SendMessage (m2, taskId, contextId, returnImmediately=true)
S-->>C: result.task (TASK_STATE_WORKING)
C->>S: GetTask (id, with backoff)
S-->>C: result (TASK_STATE_COMPLETED, artifacts, status.message)
1. Discovery: select by skill and interface
The coordinator reads /.well-known/agent-card.json, checks skill descriptions and tags for ticket analysis, and verifies interfaces, bindings, and securitySchemes / securityRequirements. Tags are declarations, not a guarantee of analysis quality.
streaming and pushNotifications are optional capabilities. Streaming delivers events over an open connection; push supports disconnected notification delivery. This walkthrough polls for long-running work and requires neither capability. See Agent discovery
and Agent Card implementation
. Cache the card according to the server’s cache policy.
2. Starting: separate business identifiers from protocol identifiers
TCK-4821 is a business ticket number, not a protocol taskId or contextId. The message creator generates messageId; the server generates Task.id for a new task. Omit taskId and contextId from the first message, then record the returned id and contextId for reuse. Servers may accept client-provided context IDs, but clients must understand the server’s policy first. The two protocol identifiers are not both sender-generated.
configuration.returnImmediately: true explicitly selects non-blocking delivery. The default is false, which waits for a terminal or interrupted state. These behaviors must not be mixed.
{
"jsonrpc": "2.0",
"id": "req-101",
"method": "SendMessage",
"params": {
"message": {
"messageId": "coord-4f21-m1",
"role": "ROLE_USER",
"parts": [
{
"text": "Analyze ticket TCK-4821: order status does not update after checkout"
}
]
},
"configuration": {
"returnImmediately": true
}
}
}The non-blocking response wraps SendMessageResponse in result; its task field contains the Task. A message-only response is outside this example.
{
"jsonrpc": "2.0",
"id": "req-101",
"result": {
"task": {
"id": "task-9c31",
"contextId": "ctx-7e12",
"status": {
"state": "TASK_STATE_WORKING"
}
}
}
}This scenario assumes server-side message deduplication. A messageId can help detect duplicates, but A2A does not guarantee deduplication by every implementation; retry behavior and deduplication scope depend on server policy.
3. Tracking and supplying information
GetTask takes id; its result is the Task itself, unlike SendMessage with result.task. Poll with backoff and respect server rate limits.
{
"jsonrpc": "2.0",
"id": "req-102",
"method": "GetTask",
"params": {
"id": "task-9c31"
}
}{
"jsonrpc": "2.0",
"id": "req-102",
"result": {
"id": "task-9c31",
"contextId": "ctx-7e12",
"status": {
"state": "TASK_STATE_INPUT_REQUIRED",
"message": {
"messageId": "analyst-m1",
"role": "ROLE_AGENT",
"taskId": "task-9c31",
"contextId": "ctx-7e12",
"parts": [
{
"text": "Please supply reproduction steps."
}
]
}
}
}
}| Task state (JSON enum) | Coordinator action |
|---|---|
TASK_STATE_SUBMITTED / TASK_STATE_WORKING | Poll the current task with backoff |
TASK_STATE_INPUT_REQUIRED | Collect information and continue the same task with a new message |
TASK_STATE_AUTH_REQUIRED | Complete the authorization described in the status message; see section 4 of Security implementation |
TASK_STATE_COMPLETED | Read artifacts and the status message |
TASK_STATE_FAILED / TASK_STATE_CANCELED / TASK_STATE_REJECTED | Decide whether to create a new task, switch agents, or escalate; terminal tasks cannot restart |
The supplement has a new messageId and reuses the returned taskId and contextId:
{
"jsonrpc": "2.0",
"id": "req-103",
"method": "SendMessage",
"params": {
"message": {
"messageId": "coord-4f21-m2",
"role": "ROLE_USER",
"parts": [
{
"text": "Reproduction: refresh the order page twice within 30 seconds of checkout."
}
],
"taskId": "task-9c31",
"contextId": "ctx-7e12"
},
"configuration": {
"returnImmediately": true
}
}
}{
"jsonrpc": "2.0",
"id": "req-103",
"result": {
"task": {
"id": "task-9c31",
"contextId": "ctx-7e12",
"status": {
"state": "TASK_STATE_WORKING"
}
}
}
}4. Receiving: poll for the report and conclusion
Continue with GetTask. This scenario reads the complete Task.artifacts; it does not process streaming chunks or lastChunk. The report is an Artifact and the conclusion is Task.status.message. Both contain illustrative data below.
{
"jsonrpc": "2.0",
"id": "req-104",
"method": "GetTask",
"params": {
"id": "task-9c31"
}
}{
"jsonrpc": "2.0",
"id": "req-104",
"result": {
"id": "task-9c31",
"contextId": "ctx-7e12",
"status": {
"state": "TASK_STATE_COMPLETED",
"message": {
"messageId": "analyst-m2",
"role": "ROLE_AGENT",
"taskId": "task-9c31",
"contextId": "ctx-7e12",
"parts": [
{
"text": "Inspect the order-status synchronization path."
}
]
}
},
"artifacts": [
{
"artifactId": "report-1",
"name": "Ticket analysis",
"parts": [
{
"data": {
"ticket": "TCK-4821",
"hypothesis": "Order-status synchronization delay",
"recommendedAction": "Inspect synchronization logs"
}
}
]
}
]
}
}See the Artifact object page and Message object page for fields.
5. Recovery: act on what is known
| Observation | Action |
|---|---|
First SendMessage times out before a Task ID is known | Check server deduplication policy; retry with the same messageId only when that policy permits it. A second side effect is not ruled out |
| Task ID is known and a later request times out | Use GetTask first, then decide whether to resend new input |
| Query temporarily fails | Retry the query with backoff; a lost connection is not a failed task |
WORKING exceeds the business limit | Request CancelTask according to server policy, check its outcome, then decide about a new task in the same context; cancellation may fail |
| More authorization is needed | Follow the status message for out-of-band authorization and preserve the originator’s access boundary |
| Analyst is unreachable | Before switching interfaces, check whether the same task is accessible. Rediscover when switching agents; contexts are not assumed portable across servers |
When streaming is supported, SubscribeToTask can establish a new subscription and GetTask can reconcile a snapshot. The protocol guarantees neither complete replay of missed events nor a universal event sequence for deduplication. Configure push according to declared capability and receiver policy. See Task idempotency and recovery
and Push receiver hardening
.
Boundary: the MCP side
Internally, the ticket-analysis agent uses MCP to read ticket-system data and call controlled tools (refund lookup, order-status API). How an MCP tool or permission failure is reflected in the task is the specialist’s application-level decision, not something the protocol prescribes: it may retry or recover on its own, reports AUTH_REQUIRED only when additional authorization is genuinely needed, and FAILED when it cannot complete the task. That is MCP’s side of the boundary — MCP Servers/Clients, tools and resources, least privilege, call failures and observable results — covered in the corresponding practice page on the MCP site (Chinese)
. The division between the two protocols is summarized in A2A and MCP
.
Related pages
- Task runtime guide : state rules and event-stream validation
- Task idempotency and recovery : the idempotency and recovery patterns referenced here
- Agent discovery : card discovery mechanics
- A2A and MCP compared : the boundary between the two protocols
Version and verification notes
Static checks: parse each JSON block and compare operations, contexts, and the JSON-RPC binding with the fixed A2A v1.0.1 specification
. Compare SendMessageRequest, SendMessageConfiguration, SendMessageResponse, GetTaskRequest, Task, Message, Part, and enums with the matching specification/a2a.proto
. No running endpoint was contacted and no end-to-end test was performed.
Additional sources: local data structures and Life of a task . The pinned upstream version defines this example’s fields.