Agent chat API
Chat with an agent from scripts or external systems using a personal access token — create a chat, send a message, and wait for the reply in the same request.
Everything you can do in Chat is also available over HTTP. External systems can use it to embed an agent in their own flow: create a chat, send a message, and receive the agent's reply directly in the response.
Before you start
Every request authenticates with a personal access token (mul_ prefix) and selects the workspace with X-Workspace-ID:
Authorization: Bearer mul_xxxxxxxx
X-Workspace-ID: <workspace id>
Content-Type: application/json; charset=utf-8The token acts as its owner. Workspace members can read conversation history, including messages from before they joined. Each new turn uses the token owner’s permission to invoke the agent.
The agent's runtime must be online. While it is offline, messages wait in the queue and run once it reconnects.
A complete single-agent conversation
1. Create a chat
curl -X POST "$AGENTDOCK_URL/api/chat/sessions" \
-H "Authorization: Bearer $AGENTDOCK_TOKEN" \
-H "X-Workspace-ID: $AGENTDOCK_WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{"agent_id": "<agent id>", "title": "API chat"}'The id in the response is the chat id used by the following requests. List agent ids with GET /api/agents.
2. Send a message and wait for the reply
Append ?wait=<seconds> to the send URL. The server responds once the run finishes, with the reply in result.reply:
curl -X POST "$AGENTDOCK_URL/api/chat/sessions/<chat id>/messages?wait=55" \
-H "Authorization: Bearer $AGENTDOCK_TOKEN" \
-H "X-Workspace-ID: $AGENTDOCK_WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{"content": "Introduce yourself in one sentence"}'{
"message_id": "…",
"task_id": "…",
"queued": false,
"created_at": "2026-10-12T06:10:00Z",
"result": {
"task_id": "…",
"status": "completed",
"done": true,
"reply": {
"id": "…",
"role": "assistant",
"content": "I'm a test assistant that verifies the chat API.",
"failure_reason": null,
"elapsed_ms": 12840
}
}
}wait is capped at 55 seconds; larger values are treated as 55. Without wait the request returns immediately with no result, exactly as before.
3. Keep waiting if the reply is not ready
When the agent does not finish within wait, result.done is false. Resume with result.task_id:
curl "$AGENTDOCK_URL/api/chat/sessions/<chat id>/tasks/<task_id>?wait=55" \
-H "Authorization: Bearer $AGENTDOCK_TOKEN" \
-H "X-Workspace-ID: $AGENTDOCK_WORKSPACE_ID"This endpoint returns the result object itself. Repeat until done is true. Without wait it reports the current state once.
4. Continue the conversation
Repeat step 2 with the same chat id; the agent sees the earlier messages. Read the full transcript with GET /api/chat/sessions/<chat id>/messages.
Reading the result
status | done | Meaning |
|---|---|---|
queued, dispatched, running, waiting_local_directory, deferred | false | Still queued or running; keep waiting |
completed | true | Finished; reply.content is the agent's answer |
completed | false | Finished, but the reply is still being written; keep waiting |
failed | true | Failed; reply.failure_reason is the reason and reply.content the notice |
cancelled | true | Cancelled; there may be no reply |
A failed run may be retried automatically as a new run. The waiter follows the retry, so result.task_id can differ from the task_id returned by the send. Use result.task_id when you resume.
Disconnecting only stops the wait; the agent keeps running and you can fetch the outcome later with step 3.
Project group chats
First fetch GET /api/chat/capabilities. Enable group UI only when project_group_chat is true and project_group_chat_writes is not false. Send X-Client-Capabilities: project-group-chat-v1 on group requests. Without it, lists contain private chats only and direct group access returns 426. WebSocket clients advertise capabilities=project-group-chat-v1 during connection; group frames carry a required_capability marker and are filtered for older sockets.
Create a group with POST /api/chat/sessions and {"project_id":"<project UUID>","title":"Team discussion"}. Omit agent_id, execution options, and native runtime settings. Each project can have multiple groups. project_id cannot be changed on an existing session (409). Configure default_chat_agent_id using PATCH /api/projects/{id}; null clears it.
Send POST /api/chat/sessions/{id}/messages with a new UUID client_message_id for each logical message:
{
"content": "[@T-agent](mention://agent/<T-agent UUID>) Please review",
"client_message_id": "019a0000-0000-7000-8000-000000000001",
"attachment_ids": []
}{
"message_id": "…",
"created_at": "2026-10-19T00:00:00Z",
"tasks": [{"task_id":"…","agent_id":"…","initiator_user_id":"…","message_id":"…","status":"queued","created_at":"2026-10-19T00:00:00Z"}],
"dispatch_outcomes": [{"agent_id":"…","task_id":"…","status":"queued"}],
"supports_queue": true,
"attachment_ids": []
}There is no group task_id at the response root. One stored input can trigger several tasks. Retrying the same message ID returns its original dispatch decisions without sending again; reusing it for different content returns 409. Dispatch results are immutable admission results, not current task status. tasks contains accepted targets; dispatch_outcomes also contains blocked targets with a reason such as invocation_not_allowed, default_assistant_required, target_unavailable, or model_unavailable. All targets may be blocked while the human message still succeeds with 201.
An explicit agent mention suppresses the default assistant. Multiple targets and [@All agents](mention://all/all) are deduplicated. Human-only mentions do not notify anyone and still use the default. Only human sends dispatch group tasks; mentions in agent replies never recurse. Each task runs under the actual sending member's identity and the agent's own model/runtime configuration.
GET /api/chat/sessions/{id}/pending-task returns active_tasks: [] or multiple task summaries. Read each task through the existing task result endpoint; group sends reject ?wait with 400. Stop a task with POST /api/tasks/{task_id}/cancel; only the conversation creator may do so. Stored inputs and other tasks remain intact. Queue edit/clear/prioritize operations belong to private chats.
History supports limit and before_created_at/before_id pagination and includes trusted sender_type, sender_id, sender_name, and saved dispatch_outcomes. Per-user pin/read state is independent. The caller must still belong to the workspace and be the conversation creator; administrators have no exception. Deleting a project archives its groups without changing their project IDs. If group writes are disabled, create/send return 503, while history stays readable.
Errors
| Status | Cause |
|---|---|
400 | wait is not a non-negative integer, content is empty, or an id is malformed |
401 | The token is invalid, expired, or revoked |
403 | You may not invoke this agent |
404 | The chat does not exist or is not yours, or the task_id is not part of this chat |
409 | The agent is archived, has no runtime, or its runtime is switching |
Never commit tokens to a repository or write them to logs. External systems should read the token from an environment variable or a secret manager.
Next
- Authentication & tokens — create and revoke personal access tokens.
- Chat — chat with agents in the app.