This topic describes the AG-UI API of managed Harness. For connection steps, see Use managed Harness.
Endpoints and authentication
Operation | Method and path | Response |
Start a request or reconnect |
| SSE event stream |
Stop execution |
| Returns |
agent_endpoint is the base address of the endpoint.
Request headers
Name | Requirement | Description |
| Required |
|
| Recommended | Use |
| Required for API key authentication | The API key of the Agent endpoint |
| Optional | The session ID. Defaults to |
Request parameters
Request body
Field | Type | Description |
| string | Required. The session ID. Keep it unchanged within the same conversation |
| string | Required. The ID of this run. Use a new value for each new request |
| array | Required. The messages submitted to the Agent. A normal call includes at least the current user input |
| object | State data. Specify |
| array | The client tools declared for this request. Specify |
| array | Supplementary context. Specify |
| object | Extended properties. Specify |
| string | Optional. The associated parent run ID |
{
"threadId": "session-001",
"runId": "run-001",
"messages": [
{
"id": "message-001",
"role": "user",
"content": "Introduce your capabilities in three bullet points."
}
],
"state": {},
"tools": [],
"context": [],
"forwardedProps": {}
}Message fields
Field | Description |
| The message ID. Use a new ID for new messages; keep the original ID when resending existing messages |
| The message role. Supports |
| A text string, or an array composed of text, images, and other content |
| Optional. The name of the message sender |
| Required for |
developer messages are treated as system messages. Historical messages of type activity and reasoning are not used as model input for the current run.
Multimodal input
A user message can contain text, images, audio, video, or documents. Actual support depends on the selected Harness and model.
The following is an image message placed in the messages array of the request:
{
"id": "message-002",
"role": "user",
"content": [
{"type": "text", "text": "Analyze the anomaly in the image"},
{
"type": "image",
"source": {
"type": "url",
"value": "https://example.com/error.png",
"mimeType": "image/png"
}
}
]
}To pass Base64 content, set source.type=data and put the data in source.value. Other content types are audio, video, and document.
Client tools
tools declares tools provided by the caller, which differ from MCP tools bound in the console. Example of a single tool:
{
"name": "get_order",
"description": "Query an order by order number",
"parameters": {
"type": "object",
"properties": {
"orderId": {"type": "string"}
},
"required": ["orderId"]
}
}If the selected Harness or Agent configuration does not support client tools, the request may return EXECUTOR_INPUT_UNSUPPORTED.
Response events
SSE format
AG-UI always returns SSE and does not provide a stream:false switch. To display a complete answer at once, the application should first receive and concatenate the text, then display it after confirming successful execution.
Example response headers:
HTTP/1.1 200 OK
Content-Type: text/event-stream
Cache-Control: no-cache
X-AgentCore-Session-ID: session-001Each event consists of id and data, separated by blank lines. data is JSON. The first RUN_STARTED uses id: 0; subsequent event IDs increment.
Example text reply:
id: 0
data: {"type":"RUN_STARTED","threadId":"session-001","runId":"run-001"}
id: 1
data: {"type":"TEXT_MESSAGE_START","messageId":"assistant-001","role":"assistant"}
id: 2
data: {"type":"TEXT_MESSAGE_CONTENT","messageId":"assistant-001","delta":"I can help with Q&A, files, and tool calls."}
id: 3
data: {"type":"TEXT_MESSAGE_END","messageId":"assistant-001"}
id: 4
data: {"type":"RUN_FINISHED","threadId":"session-001","runId":"run-001","outcome":{"type":"success"}}Event types
Event | Main fields | Meaning and handling |
|
| The run starts |
|
| A message starts |
|
| Append the text fragment to the corresponding message |
|
| The message ends; continue waiting for the run result |
|
| Reasoning process; handle separately, do not concatenate into the answer body |
|
| Encrypted reasoning data; do not display as readable text |
|
| A tool call starts |
|
| Tool argument fragments; parse after receiving completely |
|
| Tool argument transmission ends; does not indicate tool execution success |
|
| Tool execution result; |
|
| Extended event; when |
|
| Check |
|
| The run failed or was cancelled |
outcome.type=interrupt means the run requires external input; this behavior requires support from the selected Harness.
Result handling
Check the HTTP status code and response type before parsing SSE.
Split complete events by blank lines.
Concatenate text by
messageId, and concatenate tool arguments and record results bytoolCallId; events of different messages and tools may interleave.After each event is fully processed, save its
idfor reconnection.On
RUN_FINISHED, checkoutcome; onRUN_ERROR, record the error.
If the connection closes before an end event is received, record it as a connection interruption.
File results
When file publishing is enabled, files are returned via temporary download links. TOOL_CALL_RESULT.content is a JSON string; the parsed structure is as follows:
{
"status": "success",
"files": [
{
"fileName": "report.csv",
"mimeType": "text/csv",
"downloadUrl": "https://example.com/temporary-download-link",
"expiresInSeconds": 3600
}
]
}On file publishing failure, status=error and an error message are returned; unconverted non-text output may trigger AG_UI_OUTPUT_UNSUPPORTED.
Multi-turn conversations
Call |
|
| New message ID |
First turn |
|
|
|
Second turn |
|
|
|
New session |
|
|
|
For session scheduling and history retention rules, see Session management.
Reconnection
Attach re-receives the events of the original request without re-executing it; it requires support from the selected Harness.
Send the following request to the same AG-UI address, keeping the original threadId and runId, and set afterSequence to the ID of the last fully processed event:
{
"threadId": "session-001",
"runId": "run-001",
"messages": [],
"state": {},
"tools": [],
"context": [],
"forwardedProps": {
"agentcore": {
"attach": {"afterSequence": 12}
}
}
}After reconnection, only events with id > afterSequence are returned. afterSequence must be a non-negative safe integer.
Limits:
The original request is still running, the runtime process has not restarted, and the event cache has not been cleared.
Only one external connection can receive events for the same run.
After a reconnection failure, first confirm the execution status of the original request. Resending with a different runId may cause duplicate execution.
Stop execution
To explicitly stop execution, call the Stop API instead of merely closing the connection:
curl --request POST "${AGENTCORE_ENDPOINT%/}/ag-ui/agent/stop" \
--header "x-api-key: ${AGENTCORE_ENDPOINT_API_KEY}" \
--header 'Content-Type: application/json' \
--data '{"threadId":"session-001","runId":"run-001"}'Use the threadId and runId from the original request. On success, 204 No Content is returned; the original event stream may receive RUN_ERROR with error code RUN_CANCELLED.
If the execution-end record is still retained, repeated stops return 204; if the target does not exist or the record has been cleared, 404 RUN_NOT_FOUND is returned.
Error handling
Before the event stream is established
On request failure, errors are returned via HTTP status codes and JSON:
{
"error": {
"code": "SESSION_ID_MISMATCH",
"message": "X-AgentCore-Session-ID must equal RunAgentInput.threadId."
}
}HTTP status code | Common error code | Description |
|
| The request body is not valid JSON |
|
| Request fields or types do not meet requirements |
|
| The session ID in the header does not match the request body |
|
| Reconnection or stop parameters are incorrect |
|
| The run to reconnect or stop cannot be found |
|
| The run ID already exists |
|
| The run to reconnect has already ended |
|
| A connection is already receiving events for this run |
|
| The current Harness does not support reconnection |
|
| The session is closing or unavailable |
|
| The request content is too large |
|
| The request queue is full |
|
| Execution capacity is full |
|
| The runtime is not ready or is draining new requests |
Authentication, access permissions, and gateway limits may also return errors before the request reaches the Agent; check the endpoint configuration and the actual response.
After the event stream is established
On execution failure or cancellation, the error is returned via RUN_ERROR, then the event stream is closed:
id: 6
data: {"type":"RUN_ERROR","code":"RUN_CANCELLED","message":"Run cancelled."}Limits
State snapshots, message snapshots, plans, and Activity events are not guaranteed to be returned.
Whether input fields such as
stateandcontextparticipate in execution depends on the selected Harness.The Runtime request body limit is 96 MiB; a single attachment is limited to 64 MiB after decoding; a single SSE event is limited to 1 MiB. The ingress gateway may set lower limits.
For general AG-UI event definitions, see the official event documentation. The Attach parameter, Stop API, and agentcore.usage in this topic are AgentCore extensions.