Client Tasks and AG-UI
A client task lets an agent ask the user to do something during a request. This guide explains the task lifecycle. It shows how to handle tasks with the Conversation API and with AG-UI.
Lifecycle
- The agent calls a client task tool. The request pauses and emits a
taskevent. - The client shows the task to the user.
- The client completes the task with an answer that matches the output schema. The client can also cancel the task.
- The agent continues.
With the Conversation API
When a task opens, the request becomes waiting and the stream has a task event. The id of the event is the task ID. The tasks field of the request lists the open tasks, each with its id. To get them without a stream, send GET /conversations/{conversation_id}/requests/{request_id}.
A task has these fields:
kind:client_taskfor a client task. A tool call that needs approval istool_call_approval.response_schema: the JSON Schema that the answer must match. The request captures it when it creates the task. If you change the definition later, the schema stays valid for the open task.client_task: the details of a client task:name: the name of the client task, for exampleask_question.input: what the agent supplied. It matches the input schema. Forask_question, it is an object with aquestionstring.presentations: optional. This is a list. Each item has atypeandcontent. The typea2uiholds an A2UI v0.9 surface for theopenstate. It can also hold a surface for thecompletedstate.
To complete the task, send POST /conversations/{conversation_id}/requests/{request_id}/tasks/{task_id}/complete with a JSON body that matches response_schema. If the body does not match, the API rejects it and the task stays open.
This example completes an ask_question task:
curl -H "Authorization: Bearer <API_KEY_TOKEN>" -X POST "https://api.partite.ai/conversations/<CONVERSATION_ID>/requests/<REQUEST_ID>/tasks/<TASK_ID>/complete" -H "Content-Type: application/json" -d '{"answer": "macOS 14"}'To cancel the task, send POST .../tasks/{task_id}/cancel. The request goes on, and the agent gets an error from the client task tool. To cancel the whole request, send POST /conversations/{conversation_id}/requests/{request_id}/cancel.
A task_response event follows. Its data is the answer, or the string cancelled.
If your client cannot render A2UI, build a form from response_schema.
With AG-UI
AG-UI is an open protocol for agent user interfaces. Use an API key with the Converse scope, or a token for an access point under the access point’s URL. The path names the mesh version or the route:
POST /agui/meshes/{mesh_id}/versions/{version}POST /agui/meshes/{mesh_id}/version_labels/{version_label}POST /agui/meshes/{mesh_id}/draftPOST /agui/routes/{route_id}
To bind the endpoint to one intent, add /intents/{intent_name} to the path.
Request
The body is an AG-UI RunAgentInput.
threadIdis the external ID of the conversation. The same thread continues the same conversation.runIdis one request.forwardedProps.intentnames the Intent when the Mesh has several Intents and the path names none.forwardedProps.inputsupplies a structured input.
If you send no forwardedProps.input, the text of the last user message fills the single required string property of the Intent. A chat Intent must therefore take exactly one required string.
Client tasks as interrupts
Client tasks arrive as interrupts. To answer, send resume: [{interruptId, status: "resolved", payload}]. To cancel, send the status cancelled. forwardedProps.a2uiAction carries A2UI user actions.
Events
The stream has these events:
RUN_STARTEDTEXT_MESSAGE_*REASONING_*for thinkingSTATE_SNAPSHOTACTIVITY_SNAPSHOTfor A2UI surfacesRUN_FINISHED, with anoutcomeof interrupt or cancelledRUN_ERROR
Cancelling
A new user message cancels the active request of the thread. If the client disconnects, the run is cancelled.
Headers
AG-UI takes the conversation settings as headers, not in the body. These headers apply: Partite-Conversation-Tags, Partite-Request-Tags, Partite-Notification-Channel and Partite-Conversation-Tracing. The API rejects Partite-Conversation-External-Id, because the thread ID is the external ID.
Multi-turn chat
For multi-turn chat, the Mesh needs a Memory Store with Ingest conversations on. The Agent needs an Interaction Profile with Conversation history. For the setup, see the Memory guide.
Integration pattern
Use a server-side runtime, for example CopilotKit. The runtime registers the Mesh as an AG-UI HTTP agent and adds the API key. The key never reaches the browser. The chat component renders text, reasoning and interrupts. A task card renders the A2UI form, or a form built from the output schema. The task card then sends resume.
Related
- Client Tasks
- Conversation API
- Memory guide
- Meshes as MCP Servers: MCP takes the same headers.
- Tags