User Story 08: Multi-Turn Conversation
Implementation-oriented user story for SDK development.
Send Follow-Up Turns Using Task.context_id and Resume Interrupted Tasks
Goal
Agent A holds a multi-turn conversation with Agent B: multiple request/reply exchanges are grouped by a shared Task.context_id so Agent B can maintain conversational continuity. When Agent B needs additional input mid-task, Agent A resumes the same task after prompting the user.
Preconditions
- Agent B is registered and discovered by Agent A.
- Agent A has subscribed to its reply topic.
- Agent B supports multi-turn conversations (maintains context across tasks sharing a
Task.context_id).
End-to-End Flow — Follow-Up Turns
Turn 1: Start Conversation
- Agent A generates
Task.context_idC (UUIDv4) andTask.idT1 (UUIDv4). - Agent A publishes
SendMessageto:$a2a/v1/request/{org_id}/{unit_id}/{agent_b_id}- QoS:
1(recommended) - MQTT v5 properties:
Response Topic:$a2a/v1/reply/{org_id}/{unit_id}/{agent_a_id}/{reply_suffix}Correlation Data: D1 (unique request correlation bytes)
- Optional MQTT User Property:
a2a-context-id= C - JSON-RPC payload includes
Message.task_id = T1andMessage.context_id = C
- Agent B creates task T1 within context C, processes the request.
- Agent B streams
TaskStatusUpdateEvent/TaskArtifactUpdateEventmessages echoing D1. - Agent B sends terminal status (
completed) echoing D1. Agent A marks T1 complete.
Turn 2: Follow-Up in Same Conversation
- User asks a follow-up question.
- Agent A generates new
Task.idT2 (UUIDv4), reusesTask.context_idC. - Agent A publishes
SendMessage:Correlation Data: D2 (fresh)- JSON-RPC payload includes
Message.task_id = T2andMessage.context_id = C
- Agent B creates task T2 within context C. Agent B uses prior context from T1 to inform its response.
- Agent B streams replies echoing D2, completes with terminal status.
End-to-End Flow — Interrupted Task (input-required)
Initial Request
- Agent A publishes
SendMessagewithTask.idT3,Task.context_idC,Correlation DataD3. - Agent B starts processing, streams partial results echoing D3.
Input Required
- Agent B determines it needs more information from the user.
- Agent B publishes
TaskStatusUpdateEventwithstatus.state = input-requiredand a message describing what input is needed, echoing D3. - Agent A receives
input-required, treats it as stream-final for D3, cleans up in-flight state, and prompts the user.
User Provides Input
- User provides the requested information.
- Agent A publishes a new
SendMessagewith the sameTask.idT3 andTask.context_idC, freshCorrelation DataD4. - Agent B continues processing task T3 with the new input, streams replies echoing D4.
- Agent B sends terminal status (
completed) echoing D4.
SDK Requirements Checklist
- Generate and persist
Task.context_id(UUIDv4) for new conversations; reuse for follow-up turns. - Include
Message.context_idin JSON-RPC payload on all requests within a conversation. - Optionally include MQTT User Property
a2a-context-idfor transport-level visibility. - Detect
input-required/auth-requiredstatus as stream-final for current correlation. - Resume interrupted tasks: publish new
SendMessagewith sameTask.idandTask.context_id, freshCorrelation Data. - Responder SDK: provide access to prior task results within the same
Task.context_idfor context-aware responses. - Responder SDK: validate
Task.context_idconsistency — reject if providedTask.context_idconflicts with existing task'sTask.context_id.
Failure Cases to Test
- Mismatched
Task.context_id: Agent A sends a follow-up for an existingTask.idwith a differentTask.context_id. Agent B rejects with JSON-RPC error-32602(invalid params). - Unknown
Task.context_id: Agent A sends a newTask.idwith aTask.context_idthe responder hasn't seen. Agent B creates a new context (no error — the context is new). - Expired context: Agent A sends a follow-up after Agent B's context expiration window. Agent B returns an appropriate error.
- Multiple concurrent tasks in same context: Agent A has two in-flight tasks (T4, T5) sharing the same
Task.context_idC. Both complete independently; each uses its ownCorrelation Data.