Skip to main content

Build your first Agent

Agents are AI programs where a language model controls the flow of execution. Instead of a toy demo, let’s build an Agent that you can extend by connecting to any MCP server. We’ll connect our agent to the Agno MCP server, and give it a database to store conversation history and state. Save the following code in a file named 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

# Create the Agent
agno_agent = Agent(
    name="Agno Agent",
    model=Claude(id="claude-sonnet-4-5"),
    # Add a database to the Agent
    db=SqliteDb(db_file="agno.db"),
    # Add the Agno MCP server to the Agent
    tools=[MCPTools(transport="streamable-http", url="https://docs.agno.com/mcp")],
    # Add the previous session history to the context
    add_history_to_context=True,
    markdown=True,
)


# Create the AgentOS
agent_os = AgentOS(agents=[agno_agent])
# Get the FastAPI app for the AgentOS
app = agent_os.get_app()
There is an incredible amount of alpha in these 25 lines of code.You get a fully functional Agent with memory and state that can access any MCP server. It’s served via a FastAPI app with pre-built endpoints that you can use to build your product.

Run your AgentOS

The AgentOS gives us a FastAPI application with ready-to-use API endpoints. Let’s run it.
1

Setup 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 will start your AgentOS on http://localhost:8000

Connect your AgentOS

Agno provides a beautiful web interface that connects directly to your AgentOS, use it to monitor, manage and test your agentic system. Open os.agno.com and sign in to your account.
  • Click on “Add new OS” in the top navigation bar.
  • Select “Local” to connect to a local AgentOS running on your machine.
  • Enter the endpoint URL of your AgentOS. The default is http://localhost:8000.
  • Give your AgentOS a descriptive name like “Development OS” or “Local 8000”.
  • Click “Connect”.
Once connected, you’ll see your new OS with a live status indicator.

Chat with your Agent

Next, let’s chat with our Agent, go to the Chat section in the sidebar and select your Agent.
  • Ask “What is Agno?” and the Agent will answer using the Agno MCP server.
  • Agents keep their own history, tools, and instructions; switching users won’t mix context.
Click on Sessions to view your Agent’s conversations. This data is stored in your Agent’s database, so no need for external tracing services.

Pre-built API endpoints

The FastAPI app generated by your AgentOS comes with pre-built SSE-compatible API endpoints that you can build your product on top of. You can add your own routes, middleware or any other FastAPI feature. Checkout the API endpoints at /docs of your AgentOS url, e.g. http://localhost:8000/docs

Next

Happy building!