Skip to content
Client Tasks and AG-UI

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

  1. The agent calls a client task tool. The request pauses and emits a task event.
  2. The client shows the task to the user.
  3. The client completes the task with an answer that matches the output schema. The client can also cancel the task.
  4. 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_task for a client task. A tool call that needs approval is tool_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 example ask_question.
    • input: what the agent supplied. It matches the input schema. For ask_question, it is an object with a question string.
    • presentations: optional. This is a list. Each item has a type and content. The type a2ui holds an A2UI v0.9 surface for the open state. It can also hold a surface for the completed state.

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. 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}/draft
  • POST /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.

  • threadId is the external ID of the conversation. The same thread continues the same conversation.
  • runId is one request.
  • forwardedProps.intent names the Intent when the Mesh has several Intents and the path names none.
  • forwardedProps.input supplies 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_STARTED
  • TEXT_MESSAGE_*
  • REASONING_* for thinking
  • STATE_SNAPSHOT
  • ACTIVITY_SNAPSHOT for A2UI surfaces
  • RUN_FINISHED, with an outcome of interrupt or cancelled
  • RUN_ERROR

Restoring a thread

To restore a client after a reload, send GET /agui/threads/{thread_id}. It returns the history and the state of the thread.

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