AG-UI Protocol

Runtime options

useAgUiRuntime options, adapters, supported events, thread list.

Reference for the runtime's API surface. Start with quickstart if you have not already.

useAgUiRuntime options

OptionTypeDescription
agentHttpAgentAn AG-UI client agent (from @ag-ui/client). Required.
loggerPartial<Logger>Optional logger overrides. The runtime logs event-parser warnings and run lifecycle events.
showThinkingbooleanWhether to render THINKING_* and REASONING_* events as visible reasoning. Defaults to true.
onError(e: Error) => voidError callback fired on RUN_ERROR events and protocol errors.
onCancel() => voidCancellation callback fired when the user cancels a run.
adaptersUseAgUiRuntimeAdaptersStandard adapter slots (see below).

Adapter slots

AdapterSlotNotes
Attachmentsadapters.attachmentsSee attachment adapter.
Speechadapters.speechText-to-speech. See speech adapter.
Dictationadapters.dictationSpeech-to-text input.
Feedbackadapters.feedbackThumbs up / down. See feedback adapter.
Historyadapters.historyPer-thread message persistence.
Thread listadapters.threadListMulti-thread switching (experimental, see below).

Thread list (experimental)

The thread list adapter is currently experimental and may change without notice.

UseAgUiThreadListAdapter lets you back the thread list with your own state.

OptionTypeDescription
threadIdstringThe currently active thread ID.
onSwitchToNewThread() => Promise<void>Called when the user creates a new thread. Reset your thread state here.
onSwitchToThread(threadId: string) => Promise<{ messages, state? }>Called when the user switches threads. Return the persisted messages (and optional opaque state).
const runtime = useAgUiRuntime({
  agent,
  adapters: {
    threadList: {
      threadId: currentThreadId,
      onSwitchToNewThread: async () => {
        setCurrentThreadId(await createThread());
      },
      onSwitchToThread: async (id) => {
        const { messages, state } = await loadThread(id);
        setCurrentThreadId(id);
        return { messages, state };
      },
    },
  },
});

Supported events

The runtime parses the AG-UI event stream and maps each event type to assistant-ui state.

EventEffect
RUN_STARTED / RUN_FINISHEDToggles thread isRunning.
RUN_CANCELLEDMarks the in-flight assistant message as cancelled.
RUN_ERRORMarks the message as errored; fires onError.
TEXT_MESSAGE_START / _CONTENT / _ENDStreams text content into an assistant message.
TEXT_MESSAGE_CHUNKAppends a delta without explicit lifecycle.
THINKING_START / _ENDWraps reasoning blocks (when showThinking is on).
THINKING_TEXT_MESSAGE_*Streams thinking text deltas.
REASONING_START / _MESSAGE_* / _ENDStreams structured reasoning per message.
TOOL_CALL_START / _ARGS / _ENDStreams tool calls into the current assistant message.
TOOL_CALL_CHUNKStreams tool deltas without explicit lifecycle.
TOOL_CALL_RESULTAttaches a tool result to a tool call.
STATE_SNAPSHOTReplaces the agent's external state.
STATE_DELTAApplies a JSON-patch-style delta to the agent's state.
MESSAGES_SNAPSHOTReplaces the full message list (used for thread restore).
CUSTOMForwarded to your custom event handling.
RAWUntyped passthrough for unrecognized events.

Feature support

FeatureSupported
Streaming textYes
Thinking / reasoning blocksYes
Tool calls and resultsYes
Tool result handoff (client-side execution)Yes
State snapshots and deltasYes
CancellationYes
Message editingYes
Message reloadYes
Run resumptionYes
Multi-threadExperimental (adapters.threadList)
History persistenceVia history adapter