AG-UI Protocol
Open Agent Kernel (OAK) can serve agents over AG-UI, an event-based protocol for talking to a user-facing frontend. Where the standard chat routes return one reply, an AG-UI run streams the whole shape of the work: the answer as it arrives, the agent's reasoning, each tool call with its arguments and result, and a shared state object both sides read and write.
Mounting AGUIRequestHandler is what turns the surface on. The agui config block only parameterizes
it; there is deliberately no enabled flag.
from agentkernel.agui import AGUIRequestHandler
from agentkernel.api import RESTAPI
from agentkernel.openai import OpenAIModule
from agents import Agent
agent = Agent(name="planner", instructions="You are a helpful assistant.")
OpenAIModule([agent])
if __name__ == "__main__":
RESTAPI.run(handlers=[AGUIRequestHandler()])
Who may run an agent is configuration: the identity block in config.yaml names the identity
provider that turns each request's Bearer token into the run's principal. The example below uses the
static provider with one credential whose value is resolved from the environment when the app starts:
identity:
provider:
type: static
static:
principals:
DEMO_TOKEN: # names a secret; the value is never in the file
subject: demo-user
A complete working demo, including a React frontend that renders every event kind, lives in
examples/api/agui.
Routes
Under agui.prefix (default /agui):
| Method | Path | Purpose |
|---|---|---|
GET | /agui/agents | Discovery. Lists the names of agents reachable over AG-UI |
POST | /agui/{agent_name} | Run a named agent |
POST | /agui | Run agui.default_agent, registered only when one is configured |
A run takes a RunAgentInput body and returns text/event-stream: RunStarted first, then the run's
events, then exactly one of RunFinished or RunError.
Running the agent off the web tier
AGUIRequestHandler executes the agent inside the SSE request, so a slow model holds a web
connection for the whole run, and a run that fails cannot be retried. That is fine for a demo and for
modest traffic, and it stays supported for deployments that want no queue.
Mount AGUIPipelineRequestHandler instead to run the agent on the
queue pipeline. The handler keeps the caller's connection,
enqueues the run, and streams the reply back as a separate process produces it. Your frontend does
not change: same routes, same events, same order:
from agentkernel.agui import AGUIPipelineRequestHandler
from agentkernel.pipeline import IOHandler
IOHandler.run(handlers=[AGUIPipelineRequestHandler()])
It needs a response store that can carry a chunk stream, everywhere, not only on a broker, and on a broker transport a session store and an attachment store the agent runner can read:
| Setting | Local (in_memory transport) | On a broker (sqs, kafka, nats, pubsub, servicebus) |
|---|---|---|
execution.response_store.type | in_memory, redis or valkey: dynamodb has no blocking read | redis or valkey |
session.type | anything, or unset | redis, valkey, dynamodb, cosmosdb or firestore |
multimodal.storage_type (when multimodal.enabled) | anything but session_cache, or unset | redis or dynamodb |
execution.response_store.retry_count x delay | how long the edge waits for each next chunk: 25s by default | the same; this budget does not depend on the transport |
The handler checks the three store settings at startup and refuses to boot with a message naming the setting to change, rather than accepting a request whose answer could never come back. The chunk budget it cannot check, because only the run knows how long it will be quiet: it covers the first token's wait as well as the gap between a tool call and its result, so raise it when a turn can go quiet for longer than the product of the two values.
Mounting, authorization and the agui config block are the same either way, see
AG-UI Server.
Discovery publishes names only, deliberately not each agent's description, because several
framework adapters return the agent's instructions from get_description(), which would publish
your system prompt to every authorised caller.
Authorization
AG-UI has no open mode. AGUIRequestHandler refuses to construct without an identity block
(AKConfigError), because its routes run agents on a caller's behalf. The identity provider the block
names (static for a demo; oidc for Auth0, Keycloak, Okta or any OpenID Connect issuer; cognito,
entra or firebase; or your own IdentityProvider by dotted path) validates the Bearer token and
yields the caller's Principal, which becomes the run's principal: the agent, its hooks and its tools
read it through session.get_principal() and ToolContext.get().principal. A request without a
credential, or with one the provider refuses, is a 401. See
Identity and access.
An agent that is not exposed on AG-UI is treated exactly as an unknown agent, a 404, so the
surface never confirms that a name exists but is hidden. So is an agent the handler does not serve:
AGUIRequestHandler runs agents in its own process and lists and serves only the ones loaded there,
while AGUIPipelineRequestHandler puts the run on the queue and also serves agents that a shared
agent registry knows from another process.
Choosing which agents are reachable
Every streaming-capable agent is reachable unless its descriptor's surfaces leaves agui out
(rest, a2a, mcp, agui; unset means all of them). Set it per agent id in configuration, or
with Module.describe(agent, surfaces=[...]) where the agent is loaded:
registry:
agents:
reviewer:
surfaces: [rest] # not reachable over AG-UI
The agui.agents list (and AK_AGUI__AGENTS) no longer exists; a configuration that still sets it
stops the application at startup with a message pointing at registry.agents.<id>.surfaces. The list
named the agents AG-UI served and left every other agent out, where an agent with no surfaces is
served: to keep what a list did, give every agent it left out a surfaces value without agui, and
every agent you add later too. There is no allow-list any more, so a new agent with no surfaces is
reachable over AG-UI.
Configuration
agui:
prefix: /agui # route prefix
default_agent: planner # serves POST /agui in addition to POST /agui/planner; must be exposed on agui
state:
enabled: true # attaches get_agui_state / update_agui_state
agents: [planner] # omitted = all agents
client_context:
enabled: true # attaches get_forwarded_props / get_agui_context
agents: [planner] # omitted = all agents
Both tool blocks are opt-in. Mounting the handler without either yields no agent-facing tools;
setting enabled: true without mounting the handler attaches the tools to every agent for nothing.
There is no execution.message_type: delta here. AG-UI delivers every run as a stream by definition, so this
surface does not consult the execution mode or message type.
Shared state
AG-UI's shared state is a JSON object the frontend and the agent both read and write. It arrives on
RunAgentInput.state, the agent may amend it during the run, and the amended copy is streamed back as
a StateSnapshot: only when it actually changed, so a turn that touches nothing re-syncs nothing.
With agui.state.enabled, agents gain two tools:
get_agui_state(): read the current objectupdate_agui_state(updates): shallow-merge the given keys;updatesis a JSON object string
The state lives in the session's non-volatile cache under "agui_state" for the session's
lifetime, so it survives across turns and is separate from any framework's own context. It is
deliberately not stored inside framework_context: that dict is per-run and adapter-owned, and the
adapter's write-back would overwrite anything a tool put there mid-run.
AG-UI has no "read the current state" request, and a StateSnapshot is only sent on change, so a
reloading client cannot ask the server what it holds. Keeping its own copy and echoing it back as
state is the protocol's model, not a workaround.
Client-supplied context
The frontend can attach two things to a run, and neither reaches the prompt:
forwardedProps: free-form passthrough (the active page, a selected record, a feature flag)context:{description, value}entries describing the user's situation
With agui.client_context.enabled, the agent gains two read-only tools: get_forwarded_props()
and get_agui_context(), and has to pull the data. That is the point: flattening client text into
the system prompt is what would turn a frontend into a prompt injector, so the entries land in the
session's volatile cache and the model reads them as tool output instead of as instructions.
Both are read-only by design. There is no update_forwarded_props, because AG-UI has no event to
carry the field back: a write tool would mutate something nothing reads. Shared state has an update
tool only because StateSnapshot exists to carry the result.
Because they are pull-based, the model may simply never call them. If that matters for your application, say so in the agent's instructions; the tools' own descriptions are the first mitigation.
Per-adapter fidelity
Which AG-UI events a run produces depends on the framework adapter, not on the protocol. OAK never emits an event it cannot fully populate, so an adapter that reports no reasoning simply produces no thinking block.
| Adapter | Reachable | Assistant message | Reasoning | Tool calls | Steps |
|---|---|---|---|---|---|
| OpenAI Agents SDK | ✅ | ✅ | ✅ | ✅ | ❌ |
| LangGraph | ✅ | ✅ | ✅ | ✅ | ❌ |
| Google ADK | ✅ | ✅ | ✅ | ✅ | ❌ |
| Pydantic AI | ✅ | ✅ | ✅ | ✅ | ❌ |
| Claude Agent SDK | ✅ | ✅ | ✅ | ✅ | ❌ |
| Microsoft Agent Framework | ✅ | ✅ | ✅ | ✅ | ❌ |
| CrewAI | ❌ | - | - | - | - |
| smolagents | ❌ | - | - | - | - |
Reading the table:
- CrewAI and smolagents are not reachable over AG-UI. Their OAK adapters leave
Runner.stream()raising and declaresupports_streaming = False, so both discovery and the run routes exclude them: aPOSTto one returns a 400 naming the framework rather than a generic error. Both SDKs support streaming; OAK simply has not wired those APIs yet. That is a pending adapter capability, not a permanent SDK limit. - Reasoning is available on all five streaming adapters, and only when the model actually produces
it. OAK maps the model's reasoning summary, so a reasoning-capable model still emits nothing unless
the summary is requested: on LangGraph that means
ChatOpenAI(..., reasoning={"effort": ..., "summary": "auto"}), and the equivalent on other providers. An empty thinking block is far more often an unrequested summary than a missing capability. - No adapter emits
StepStart/StepEndtoday. LangGraph'son_chain_*fires for every runnable in a graph rather than only the nodes a reader would call steps, so choosing which to name is its own decision; the others have no equivalent signal. A client's step handling is therefore dead code for now, which is worth knowing before you build UI around it. - Handoffs surface as tool calls, because that is what they are in every framework that has them:
the OpenAI SDK lifts them into their own run items and OAK maps them back onto
ToolCall*; ADK'sTransferToAgentToolis an ordinary function tool; Pydantic AI has no handoff primitive, so delegation is a tool calling another agent. LangGraph is the exception: it surfaces a handoff only when the application built it as a tool; a bareCommand(goto=...)edge transition does not appear.
Notes and limits
threadIdis OAK'ssession_id. Conversation history is rebuilt from the session store, so only the finalusermessage inmessagesis read: there is no need to send the transcript, and any history you do send is ignored.- Client-declared
toolsare ignored. OAK builds an agent's tool registry when the agent is constructed, so a tool named per-request has nothing to bind to. - Audio and video content is rejected with a 400. OAK has no equivalent request type, and mapping
them onto the generic file type produces misleading model output. Images and documents are accepted,
from an inline base64
datasource or aurlsource. - A structured payload maps onto AG-UI's
CustomEvent.DataMessage, the one stream event that carries an object rather than scalars, becomes aCustomEventwhosenameis the media type and whosevalueis the payload. Nothing in OAK emits one: aPostHookassembles it from what it has accumulated and returns it alongside the closing event, which is whaton_stream_event's list form is for. Note the cost of that approach: a hook cannot know whether a message is UI or prose until the closing boundary, so it holds every delta back, and such an agent streams nothing incrementally. See A2UI. - Tool-call payloads are inspectable, but only if you write a hook. Every event an AG-UI run emits
passes through
PostHook.on_stream_event, includingToolCallArgsandToolCallResult, so a hook can rewrite or drop them before they reach the client, or raiseStreamHaltto end the run. The built-in guardrail providers do not implement it, so a configured output guardrail still does nothing on a streamed run: the capability is there, the wiring for those providers is not. See Hooks.