All Products
Search
Document Center

AgentCore:AG-UI protocol reference

Last Updated:Sep 24, 2026

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

POST {agent_endpoint}/ag-ui/agent

SSE event stream

Stop execution

POST {agent_endpoint}/ag-ui/agent/stop

Returns 204 No Content on success

agent_endpoint is the base address of the endpoint.

Request headers

Name

Requirement

Description

Content-Type

Required

application/json

Accept

Recommended

Use text/event-stream when calling AG-UI

x-api-key

Required for API key authentication

The API key of the Agent endpoint

X-AgentCore-Session-ID

Optional

The session ID. Defaults to threadId; if specified, it must equal threadId

Request parameters

Request body

Field

Type

Description

threadId

string

Required. The session ID. Keep it unchanged within the same conversation

runId

string

Required. The ID of this run. Use a new value for each new request

messages

array

Required. The messages submitted to the Agent. A normal call includes at least the current user input

state

object

State data. Specify {} if not needed

tools

array

The client tools declared for this request. Specify [] if not needed

context

array

Supplementary context. Specify [] if not needed

forwardedProps

object

Extended properties. Specify {} if not needed. Place Attach parameters here

parentRunId

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

id

The message ID. Use a new ID for new messages; keep the original ID when resending existing messages

role

The message role. Supports user, assistant, system, developer, and tool

content

A text string, or an array composed of text, images, and other content

name

Optional. The name of the message sender

toolCallId

Required for tool messages. Associates the message with a tool call

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-001

Each 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

RUN_STARTED

threadId, runId

The run starts

TEXT_MESSAGE_START

messageId, role

A message starts

TEXT_MESSAGE_CONTENT

messageId, delta

Append the text fragment to the corresponding message

TEXT_MESSAGE_END

messageId

The message ends; continue waiting for the run result

REASONING_START, REASONING_MESSAGE_START, REASONING_MESSAGE_CONTENT, REASONING_MESSAGE_END, REASONING_END

messageId, delta

Reasoning process; handle separately, do not concatenate into the answer body

REASONING_ENCRYPTED_VALUE

entityId, encryptedValue

Encrypted reasoning data; do not display as readable text

TOOL_CALL_START

toolCallId, toolCallName

A tool call starts

TOOL_CALL_ARGS

toolCallId, delta

Tool argument fragments; parse after receiving completely

TOOL_CALL_END

toolCallId

Tool argument transmission ends; does not indicate tool execution success

TOOL_CALL_RESULT

toolCallId, content

Tool execution result; content is a string

CUSTOM

name, value

Extended event; when name=agentcore.usage, value is the token usage

RUN_FINISHED

threadId, runId, outcome, optional result

Check outcome.type; success means the run ended successfully

RUN_ERROR

code, message

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

  1. Check the HTTP status code and response type before parsing SSE.

  2. Split complete events by blank lines.

  3. Concatenate text by messageId, and concatenate tool arguments and record results by toolCallId; events of different messages and tools may interleave.

  4. After each event is fully processed, save its id for reconnection.

  5. On RUN_FINISHED, check outcome; on RUN_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

threadId

runId

New message ID

First turn

session-001

run-001

message-001

Second turn

session-001

run-002

message-002

New session

session-002

run-003

message-003

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

400

INVALID_JSON

The request body is not valid JSON

400

INVALID_AG_UI_REQUEST

Request fields or types do not meet requirements

400

SESSION_ID_MISMATCH

The session ID in the header does not match the request body

400

INVALID_ATTACH, INVALID_STOP

Reconnection or stop parameters are incorrect

404

RUN_NOT_FOUND

The run to reconnect or stop cannot be found

409

RUN_ALREADY_EXISTS

The run ID already exists

409

RUN_ALREADY_TERMINAL

The run to reconnect has already ended

409

RUN_ALREADY_ATTACHED

A connection is already receiving events for this run

409

RUN_ATTACH_UNSUPPORTED

The current Harness does not support reconnection

409

SESSION_UNAVAILABLE

The session is closing or unavailable

413

PAYLOAD_TOO_LARGE

The request content is too large

429

SESSION_QUEUE_FULL

The request queue is full

429

RUNTIME_CAPACITY_EXCEEDED

Execution capacity is full

503

RUNTIME_NOT_READY, RUNTIME_DRAINING

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 state and context participate 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.