Skip to main content

Build your first Agent

Agents are AI programs where a language model controls the flow of execution. Let’s build an Agent that connects to an MCP server, persists conversation state, and is served via FastAPI. Save the following code as agno_agent.py:
agno_agent.py
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.anthropic import Claude
from agno.os import AgentOS
from agno.tools.mcp import MCPTools

agno_agent = Agent(
    name="Agno Agent",
    model=Claude(id="claude-sonnet-4-5"),
    db=SqliteDb(db_file="agno.db"),
    tools=[MCPTools(transport="streamable-http", url="https://docs.agno.com/mcp")],
    add_history_to_context=True,
    markdown=True,
)

agent_os = AgentOS(agents=[agno_agent])
app = agent_os.get_app()
In ~20 lines, you have an Agent with memory, state, and MCP tools — served via FastAPI app with pre-built endpoints ready for your product.

Run your AgentOS

1

Set up your virtual environment

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

Install dependencies

uv pip install -U agno anthropic mcp 'fastapi[standard]' sqlalchemy
3

Export your Anthropic API key

export ANTHROPIC_API_KEY=sk-***
4

Run your AgentOS

fastapi dev agno_agent.py
This starts your AgentOS at http://localhost:8000.

Connect to the AgentOS UI

The AgentOS UI connects directly to your runtime, letting you monitor, manage, and test your system.
  1. Open os.agno.com and sign in.
  2. Click “Add new OS” in the top navigation.
  3. Select “Local” to connect to a local AgentOS.
  4. Enter your endpoint URL (default: http://localhost:8000).
  5. Name it something like “Development OS”.
  6. Click “Connect”.
Once connected, you’ll see your OS with a live status indicator.

Chat with your Agent

Go to Chat in the sidebar and select your Agent.
  • Ask “What is Agno?” and the Agent will answer using the Agno MCP server.
  • Each Agent maintains its own history, tools, and instructions—switching users won’t mix context.
Click on Sessions (or Traces) in the sidebar to view your Agent’s conversations. This data is stored in your Agent’s database, no 3rd party tracing services required.

Pre-built API endpoints

The FastAPI app includes SSE-compatible endpoints you can build on. Add your own routes, middleware, or any FastAPI feature. Check out the API docs at http://localhost:8000/docs.

Next steps