Velamuvi AIAcademy

Lesson 25 of 39 · Control, Safety and Quality

DevUI: Run and Debug Agents Locally

Chat with your agents and workflows in a local web app with DevUI: serve(), the devui command, entity folders, its OpenAI-style API, DevServer and auth tokens.

  • 10 min read
  • Intermediate
  • Reviewed
In this lesson you will learn
  • Explain what DevUI shows and when to use it
  • Start DevUI from code with serve() and from the terminal with the devui command
  • Lay out an entities folder that DevUI can discover
  • Call your agent through DevUI's OpenAI-compatible API
  • Embed DevUI in your own app with DevServer, and keep it protected with a token

A test bench for your agents

While you build an agent, you want to talk to it, see which tools it called with which arguments, and watch a workflow move from step to step, without writing a front end first. DevUI is a local web app for exactly that. It ships with Agent Framework (pip install agent-framework, or agent-framework-devui on its own) and runs on your computer.

DevUI finds your entities, then sends each request to the one it names. The same idea in plain Python:

Try it yourselfPython
# What DevUI does, in plain Python: find the entities, then route each request by its entity id.
folders = {"velo_desk": "agent", "repair_flow": "workflow", "notes": None}
entities = {name: kind for name, kind in folders.items() if kind}
print("found:", entities)


def handle(request):
    entity_id = request.get("metadata", {}).get("entity_id")
    if entity_id is None:
        return "400 Missing entity_id in metadata"
    if entity_id not in entities:
        return f"404 Entity not found: {entity_id}"
    return f"200 ran the {entities[entity_id]} {entity_id} with {request['input']!r}"


print(handle({"input": "How much is a City E?", "metadata": {"entity_id": "velo_desk"}}))
print(handle({"input": "Hi"}))
print(handle({"input": "Hi", "metadata": {"entity_id": "velo-desk"}}))

Start DevUI from code: serve()

The quickest start is serve() from agent_framework.devui. Give it your agents and workflows, and it starts the server and opens the page in your browser:

import logging

from agent_framework import Agent, tool
from agent_framework.devui import serve
from agent_framework.openai import OpenAIChatClient


@tool
def bike_price(model: str) -> int:
    """Daily rental price in EUR for one bike model."""
    return {"City E": 35, "Trail X": 50}[model]


agent = Agent(
    client=OpenAIChatClient(model="MODEL_NAME"),
    name="velo_desk",
    description="Answers questions about Velo's rental bikes",
    instructions="You are Velo's rental desk in Porto. Use bike_price for prices.",
    tools=[bike_price],
)

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)              # shows the access token DevUI creates at start
    serve(entities=[agent], port=8080, auto_open=True)   # opens http://127.0.0.1:8080 in your browser

Run the script and DevUI opens at http://127.0.0.1:8080. Pick velo_desk, ask "How much does a City E cost?", and you'll see the bike_price tool call with its arguments and result next to the answer. For a workflow, it shows the workflow's events as they happen. serve() keeps running until you press Ctrl+C.

The devui command and entity folders

For a project with several agents, keep each one in its own folder and let the devui command find them:

entities/
└── velo_desk/
    ├── __init__.py      # from .agent import agent
    └── agent.py         # defines a variable called agent

__init__.py makes the folder importable and exports the entity. DevUI first guesses each folder's type from its files: agent.py means an agent and workflow.py a workflow. When it imports the folder, it looks for a variable called agent or workflow:

from agent_framework import Agent, tool
from agent_framework.openai import OpenAIChatClient


@tool
def bike_price(model: str) -> int:
    """Daily rental price in EUR for one bike model."""
    return {"City E": 35, "Trail X": 50}[model]


agent = Agent(                                  # DevUI looks for a variable called agent or workflow
    client=OpenAIChatClient(model="MODEL_NAME"),
    name="velo_desk",
    description="Answers questions about Velo's rental bikes",
    instructions="You are Velo's rental desk in Porto. Use bike_price for prices.",
    tools=[bike_price],
)

Then start DevUI from the terminal:

devui ./entities --port 8080

Useful options: --no-open (don't open a browser), --headless (API only), --mode user (fewer APIs and short error messages, for demos), --instrumentation (OpenTelemetry traces) and --reload (restart when you edit code). DevUI protects its API with a token, and prints one at startup:

DevUI authentication enabled with auto-generated token:
   <a long random token>
Pass it as: Authorization: Bearer <token>

Use --auth-token or the DEVUI_AUTH_TOKEN variable to choose your own token instead.

Call DevUI from code

DevUI's API follows the OpenAI Responses format, so the ordinary openai package can talk to it. Choose the agent with metadata={"entity_id": ...} and pass the token as the API key:

from openai import OpenAI

# DevUI speaks the OpenAI Responses API, so the normal OpenAI client works with it.
client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="velo-dev-token")

response = client.responses.create(
    model="velo_desk",
    input="How much does a City E cost?",
    metadata={"entity_id": "velo_desk"},       # which agent or workflow to run
)
print(response.output_text)
Output
A City E costs 35 EUR a day.

This is handy for quick scripted tests against a running DevUI, and it means any tool that speaks the OpenAI API can try your agents. GET /v1/entities lists what DevUI found.

Embed DevUI with DevServer

serve() and the devui command both use DevServer. Create one yourself to choose every setting, or to get the FastAPI app and run it your own way:

from agent_framework.devui import DevServer

server = DevServer(
    entities_dir="entities",        # the same folder layout the devui command uses
    host="127.0.0.1",
    port=8080,
    ui_enabled=False,               # API only, like devui --headless
    mode="user",                    # restricted APIs and short error messages
    auth_token="change-me",         # or set DEVUI_AUTH_TOKEN
)
app = server.get_app()              # a FastAPI app: run it with uvicorn or mount it in your own app

paths = sorted({route.path for route in app.routes if route.path.startswith(("/health", "/v1/responses", "/v1/entities"))})
print(paths)
Output
['/health', '/v1/entities', '/v1/entities/{entity_id}/deploy', '/v1/entities/{entity_id}/info', '/v1/entities/{entity_id}/reload', '/v1/responses', '/v1/responses/{response_id}/cancel']

/health reports the status, /v1/entities lists entities and /v1/responses runs them. DevUI is a development tool: for real users, host your agent as shown in the hosting lesson later in the course.

Common mistakes

Practice exercise

Write DevUI's folder rule: decide for each folder in an entities directory whether it is an agent, a workflow, unknown, or not an entity at all.

Your solutionPython
def entity_type(files):
    # Return None if the folder isn't an entity: it has none of agent.py, workflow.py or __init__.py.
    # Otherwise: only agent.py -> "agent", only workflow.py -> "workflow", both or neither -> "unknown".
    return "agent"

folders = {
    "velo_desk": ["__init__.py", "agent.py"],
    "repair_flow": ["__init__.py", "workflow.py"],
    "notes": ["readme.md"],
    "mixed": ["__init__.py", "agent.py", "workflow.py"],
    "plain": ["__init__.py"],
}
for name, files in folders.items():
    print(name, entity_type(files))
Knowledge check

An entities folder contains an __init__.py, agent.py and workflow.py. What type does DevUI guess for it before importing it?

Summary

  • DevUI is a local web app and API for chatting with your agents and workflows, with tool calls, events and traces in view.
  • Start it from code with serve(entities=[...]), or run devui ./entities on a folder per entity that exports agent or workflow.
  • Its API uses the OpenAI Responses format: pass the token and metadata={"entity_id": ...}.
  • DevServer gives full control and a FastAPI app; keep auth on, especially outside 127.0.0.1.

Next: Workflow Basics: Executors, Edges and Events.

Finished reading? Tick it off to track your progress.