Put a chat on an AG-UI agent
Connect an agent served over AG-UI — Agno, LangGraph, Mastra, CrewAI, Pydantic AI — and the chat draws its replies, its reasoning, its tool calls and its approvals while the agent runs on its own server.
Connect the agent
Section titled “Connect the agent”npm install @aparte/runner-ag-ui @aparte/coreimport { AparteClient } from '@aparte/core';
import { createAgUiRunner } from '@aparte/runner-ag-ui';
new AparteClient({
streamRunner: createAgUiRunner({ endpoint: 'https://agents.example.com/agui' }),
}).start();AG-UI is the protocol many agent frameworks serve their agents over:
Agno, LangGraph, Mastra, CrewAI, Pydantic AI, and TanStack AI.
The agent runs its loop and its tools on its server, so the page registers no provider and picks
no model. The runner is the client’s streamRunner: the chat, Stop, the conversation manager and
the approval panel work as they do with aparté’s own loop.
What the agent’s stream becomes
Section titled “What the agent’s stream becomes”| The agent sends | The chat shows |
|---|---|
TEXT_MESSAGE_* | the reply’s text |
REASONING_* | a reasoning block |
TOOL_CALL_START, TOOL_CALL_ARGS or TOOL_CALL_CHUNK, TOOL_CALL_END | a tool row, drawn with its whole arguments once the call ends |
TOOL_CALL_RESULT | the row’s result |
RUN_FINISHED | the end of the reply, with its usage — or, with an interrupt, a decision to make or a tool the page runs |
RUN_ERROR | the error card’s sentence, below what the stream drew; the agent’s message goes to the console and stays on the segment |
STATE_SNAPSHOT, STATE_DELTA | nothing drawn: the agent’s state, kept for the thread and sent back as the next run’s state |
| an HTTP error | the error card’s sentence; the start of the response body goes to the console and stays on the segment, stored with the conversation — keep secrets out of it |
Each model step of the run is a turn of its own in the reply, and the reply reports the usage of
its last step, as a run in the page does: the size of what the model last saw, which is what the
context gauge reads. A RUN_ERROR does not cut the stream: the runner reads it to the end, as the
protocol asks, and the error lands below what was drawn — unless the agent runs again in the same
stream, in which case the new run decides how the reply ends and the failure goes to onWarning. A stream that ends without
RUN_FINISHED ends the reply with an error. STEP_*, MESSAGES_SNAPSHOT, ACTIVITY_*, RAW,
CUSTOM and sub-agent events are checked, not drawn. The runner reads the answer as server-sent
events, or as NDJSON when its content type says so.
The protocol’s own rules
Section titled “The protocol’s own rules”The runner speaks AG-UI 1.0: it declares protocolVersion: "1.0" on every request, and holds the
agent’s stream to the rules 1.0 sets a client. A run opens with RUN_STARTED and ends with
RUN_FINISHED or RUN_ERROR; a message, a tool call, a step or a sub-agent is opened before it
continues and closed before the run finishes, each owner — the agent, or each sub-agent — keeping
its own; a known field has its type. A stream that breaks one ends the reply with an error that
names the rule; what was drawn before it stays. What the agent sends that 1.0 does not describe —
an event type, a property, an outcome — is dropped, and the runner tells onWarning what and
where, console.warn by default.
It is held to that by the protocol’s own conformance corpus: the 68 streams of AG-UI’s
spec/1.0/conformance, replayed through the runner on every build, each with what the
specification requires of a client. They were written for clients that keep the run’s messages
and state themselves, so the runner’s suite says, stream by stream, what it reads through and
what aparté does not draw yet: activities, a messages snapshot rewriting what was drawn, and
message metadata.
Tools the page runs
Section titled “Tools the page runs”A tool registered in the page — ask_user through setupAskUser(), your own through
registerTool — is sent to the agent as an AG-UI frontend tool. When the agent calls it, the run
pauses with the call open; the page runs the tool, shows its result in the row, and calls the agent
again with it. For an agent server, the pause is an interrupt whose reason contains
client_tool, or a call the agent leaves without a result. Before it runs, the page gates it as
its own loop would: a needsApproval tool asks through the approval panel (its row says it is
waiting), your approval policy can allow or refuse it, and a refusal goes back to the agent with
its reason — as the tool’s result, or as its error when the agent paused on the call. A call the
person approved once in the turn is not asked about again when the agent pauses to run it.
Approvals
Section titled “Approvals”When the agent pauses on a call that needs a person — an interrupt whose reason is tool_call or
confirmation — the page asks with the same
approval panel as for its own tools, and your
approval policy can answer first. Every answer goes back to the
agent in one resume, and the run goes on on the agent’s server, in the same reply. The pause is
part of the conversation, so a saved conversation brings the
question back after a reload.
Options
Section titled “Options”import { uuid } from '@aparte/core';
import { createAgUiRunner } from '@aparte/runner-ag-ui';
let conversationId = uuid(); // set it when your app opens a conversation
const runner = createAgUiRunner({
endpoint: '/agui',
headers: async () => ({ authorization: `Bearer ${sessionStorage.getItem('token') ?? ''}` }),
threadId: () => conversationId, // read on every turn
});| Option | What it does |
|---|---|
endpoint | the agent’s AG-UI URL; required |
headers | sent with every request; a function is called for each, for a fresh token |
fetch | the fetch the runner calls; the global one by default |
credentials | for a cross-origin endpoint that authenticates by cookie |
threadId | the AG-UI thread a turn runs in: a string, or a function of the run’s options |
forwardedProps | RunAgentInput.forwardedProps: settings your agent reads from the request |
context | RunAgentInput.context: { description, value } entries for the agent |
onWarning | told what the runner dropped or translated; console.warn by default |
relaxedRunFraming | reads runs framed otherwise than 1.0 frames them — a RUN_FINISHED per model step, a resume answered before RUN_STARTED — as TanStack AI does; every other rule holds |
peerProtocolVersion | the version of an agent older than 1.0, such as '0.0.47': its stream is read by that version’s rules, and the request leaves out protocolVersion |
These are the AgUiRunnerOptions. By default every turn runs in a new thread with the whole
history, which suits a stateless agent; give threadId when the agent keeps state per thread, as
Agno does with its session — the conversation’s id is the usual choice. The state the agent streams
is kept for that thread and sent back as the next run’s state; on a thread minted for one turn,
it lasts as long as the turn, pauses included. A paused run resumes in
its own thread, whatever threadId answers. An agent on another origin than the page has to allow
it: answer the preflight (OPTIONS) with Access-Control-Allow-Origin (the page’s origin) and
Access-Control-Allow-Headers: content-type plus the headers you send, and with
Access-Control-Allow-Credentials: true when credentials is 'include'.
from agno.agent.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.os import AgentOS
from agno.os.interfaces.agui import AGUI
chat_agent = Agent(model=OpenAIResponses(id="gpt-5.4"))
agent_os = AgentOS(agents=[chat_agent], interfaces=[AGUI(agent=chat_agent)])
app = agent_os.get_app() # POST /aguiAgno serves an agent or a team over AG-UI with the AGUI interface of its AgentOS, at
POST /agui; give that URL to createAgUiRunner. This is
Agno’s AG-UI example.
LangGraph, Pydantic AI and Google ADK
Section titled “LangGraph, Pydantic AI and Google ADK”Each of these examples is a Python agent with a tool that waits for a person, and a scripted model so it runs without a key:
| Framework | How the tool waits | Example |
|---|---|---|
| LangGraph | interrupt() with a reason and the call’s id, and emit_interrupt_outcome=True on the agent | langgraph-ag-ui |
| Pydantic AI | requires_approval=True on the tool | pydantic-ai-ag-ui |
| Google ADK | require_confirmation=True on the tool, and emit_interrupt_outcome=True on the agent | google-adk-ag-ui |
ADK asks through a tool of its own, adk_request_confirmation. Its example hides that row with
registerToolDisplay and has the question name the real tool.
What is not supported
Section titled “What is not supported”- A person’s message goes as text and images, as AG-UI 1.0 content; other files are left out.
- An interrupt the page cannot answer — one such as
input_required, or one that names notoolCallId— ends the reply without an error, and is answeredcancelledwhen the thread resumes or runs again. - A refusal reaches the agent as
{ approved: false }, without the words the person wrote. The row still shows them: the runner takes the refusal from core’stoolRefusal, so the row says who refused (You said: “…”,Refused by policy), and the agent reads the same sentence as before.