Host Your Agent

Everything so far ran once and exited. To use an agent like a product, put a server in front of it — DevUI stands up a local web chat around any agent with one call.

Part 8 of 72 Microsoft Agent Framework Python — Every Lesson

What this lesson demonstrates

Every prior lesson ran a script and quit. serve() from agent_framework.devui wraps any agent (or several) in a local web inspector and chat surface, so you can interact with it live instead of editing print statements. This turns the same build_agent() you already know into a running, browsable service.

The code

Build the agent as usual, then hand it to serve():

from agent_framework.devui import serve

agent = build_agent()
print("Starting DevUI… open the printed URL, chat, Ctrl-C to stop.")
serve(entities=[agent])   # blocks, running a local web server until Ctrl-C

DevUI ships as a separate package, so the import is guarded with a helpful hint:

try:
    from agent_framework.devui import serve
except ModuleNotFoundError as e:
    raise SystemExit(f"DevUI isn't installed: {e}\nInstall it: uv add agent-framework-devui")

What to notice

How it maps to Azure AI Foundry

The hosted agent is the same FoundryChatClient + AzureCliCredential agent from lesson 1; DevUI only adds a web front end. Each chat message in the browser becomes a Foundry Responses call under the hood, so live use needs Foundry creds and az login.

Run it

uv run tutorial/01-get-started/08_host_your_agent.py

Expected: “Starting DevUI…” then a local URL; the server blocks until Ctrl-C. Needs Foundry creds and the DevUI extra.


Next: Middleware

Sources & References

The Python SDK this lesson exercises
Hosting an agent locally with DevUI