Serve an Agent over AG-UI

Mount one Agent on AgentOS's AG-UI interface and expose its response as an AG-UI server-sent event stream.

basic.py
"""
Serve an Agent over AG-UI
=========================

Mount one Agent on AgentOS's AG-UI interface and expose its response as an
AG-UI server-sent event stream.

Prerequisites: OPENAI_API_KEY
Run: .venvs/demo/bin/python cookbook/05_agent_os/16_agui/basic.py
Try: GET http://localhost:7777/status, then POST an AG-UI request to /agui
"""

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.os import AgentOS
from agno.os.interfaces.agui import AGUI

# ---------------------------------------------------------------------------
# Create AG-UI AgentOS
# ---------------------------------------------------------------------------

db = SqliteDb(
    id="agui-basic-db",
    db_file="tmp/agui_basic.db",
)

assistant = Agent(
    id="agui-assistant",
    name="AG-UI Assistant",
    model=OpenAIResponses(id="gpt-5.5"),
    db=db,
    instructions="Answer clearly and concisely.",
)

agent_os = AgentOS(
    id="agui-basic-os",
    description="A minimal AgentOS with one AG-UI interface.",
    agents=[assistant],
    interfaces=[AGUI(agent=assistant)],
)
app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run AG-UI Server
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    agent_os.serve(app=app)

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U "agno[agui,os]" openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as basic.py, then run:

python basic.py

Send a request

With the server running in another terminal:

Save this complete AG-UI request as agui-input.json. Replace content with the prompt for this example. Use a fresh runId for each run; keep threadId only when continuing the same session.

agui-input.json
{
  "threadId": "example-thread-1",
  "runId": "example-run-1",
  "state": {},
  "messages": [
    {"id": "example-message-1", "role": "user", "content": "Hello"}
  ],
  "tools": [],
  "context": [],
  "forwardedProps": {}
}

The endpoint accepts this object, rather than a JSON string or the REST run endpoint's message form field. The response is an SSE stream whose data values are AG-UI event objects. Inspect RUN_ERROR and RUN_FINISHED events; an HTTP 200 only establishes that the stream opened.

curl --no-buffer -H "Content-Type: application/json" --data-binary @agui-input.json http://localhost:7777/agui

Full source: cookbook/05_agent_os/16_agui/basic.py