AG-UI
Expose Kern agents via the AG-UI protocol
AG-UI, the Agent-User Interaction Protocol, standardizes how AI agents connect to frontend applications.
Migration from Apps: For migration from AGUIApp, see the v2 migration guide for complete steps.
Example usage
Install backend dependencies
1uv pip install ag-ui-protocolRun the backend
Expose an Kern agent through the AG-UI interface using AgentOS and AGUI.
1from kern.agent.agent import Agent2from kern.models.openai import OpenAIResponses3from kern.os import AgentOS4from kern.os.interfaces.agui import AGUI56chat_agent = Agent(model=OpenAIResponses(id="gpt-5.5"))78agent_os = AgentOS(agents=[chat_agent], interfaces=[AGUI(agent=chat_agent)])9app = agent_os.get_app()1011if __name__ == "__main__":12 agent_os.serve(app="basic:app", reload=True)Run the frontend
Use Dojo (ag-ui's frontend) as an advanced, customizable interface for AG-UI agents.
- Clone:
git clone https://github.com/ag-ui-protocol/ag-ui.git - Install dependencies in
/ag-ui/typescript-sdk:pnpm install - Build the Kern package in
/ag-ui/integrations/kern:pnpm run build - Start Dojo following the instructions in the repository.
Chat with the Kern Agent
With Dojo running, open http://localhost:3000 and select the Kern agent.
Additional examples are available in the cookbook.
Custom Events
Custom events created in tools are automatically delivered to AG-UI in the AG-UI custom event format.
Creating custom events:
1from dataclasses import dataclass2from kern.run.agent import CustomEvent34@dataclass5class CustomerProfileEvent(CustomEvent):6 customer_name: str7 customer_email: strYielding from tools:
1from kern.tools import tool23@tool()4async def get_customer_profile(customer_id: str):5 customer = fetch_customer(customer_id)6 7 yield CustomerProfileEvent(8 customer_name=customer["name"],9 customer_email=customer["email"],10 )11 12 return f"Profile retrieved for {customer['name']}"Custom events are streamed in real-time to the AG-UI frontend.
See Custom Events documentation for more details.
Core Components
AGUI(interface): Wraps an KernAgentorTeaminto an AG-UI compatible FastAPI router.AgentOS.serve: Serves the FastAPI app (including the AGUI router) with Uvicorn.
AGUI mounts protocol-compliant routes on the app.
AGUI interface
Main entry point for AG-UI exposure.
Initialization Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
agent | Optional[Union[Agent, RemoteAgent]] | None | Kern Agent or RemoteAgent instance. |
team | Optional[Union[Team, RemoteTeam]] | None | Kern Team or RemoteTeam instance. |
prefix | str | "" | Route prefix (e.g., /chat, /web-research). |
tags | Optional[List[str]] | ["AGUI"] | OpenAPI tags for the router. |
Provide agent or team.
Key Method
| Method | Parameters | Return Type | Description |
|---|---|---|---|
get_router | None | APIRouter | Returns the AG-UI FastAPI router and attaches endpoints. |
Endpoints
Mounted at the interface's route prefix (root by default):
POST /agui: Main entrypoint. AcceptsRunAgentInputfromag-ui-protocol. Streams AG-UI events.GET /status: Health/status endpoint for the interface.
Refer to ag-ui-protocol docs for payload details.
Serving AgentOS
Use AgentOS.serve to run the app with Uvicorn.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
app | Union[str, FastAPI] | required | FastAPI app instance or import string. |
host | str | "localhost" | Host to bind. Override with AGENT_OS_HOST env var. |
port | int | 7777 | Port to bind. Override with AGENT_OS_PORT env var. |
reload | bool | False | Enable auto-reload for development. |
reload_includes | Optional[List[str]] | None | File patterns to watch. Auto-adds *.yaml, *.yml. |
reload_excludes | Optional[List[str]] | None | File patterns to exclude from reload. |
workers | Optional[int] | None | Number of Uvicorn worker processes. |
access_log | bool | False | Enable Uvicorn access logging. |
See cookbook examples for updated interface patterns.