| title | Your First Agent | ||||
|---|---|---|---|---|---|
| description | Build and run your first agent in 20 lines of code. | ||||
| keywords |
|
||||
| mode | wide |
In this guide, you'll build an agent that:
- Connects to an MCP server
- Stores and retrieves past conversations
- Runs as a production API
All in about 20 lines of code.
Save the following code as agno_assist.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_assist = Agent(
name="Agno Assist",
model=Claude(id="claude-sonnet-4-5"),
db=SqliteDb(db_file="agno.db"), # session storage
tools=[MCPTools(url="https://docs.agno.com/mcp")], # Agno docs via MCP
add_datetime_to_context=True,
add_history_to_context=True, # include past runs
num_history_runs=3, # last 3 conversations
markdown=True,
)
# Serve via AgentOS → streaming, auth, session isolation, API endpoints
agent_os = AgentOS(agents=[agno_assist], tracing=True)
app = agent_os.get_app()You now have:
- A stateful agent
- Streaming responses
- Per-user session isolation
- A production-ready API
- Tracing enabled out of the box
No 3rd-party services required
<CodeGroup>
```bash Mac
uv venv --python 3.12
source .venv/bin/activate
```
```bash Windows
uv venv --python 3.12
.venv\Scripts\activate
```
</CodeGroup>
<CodeGroup>
```bash Mac
export ANTHROPIC_API_KEY=sk-***
```
```bash Windows
setx ANTHROPIC_API_KEY sk-***
```
</CodeGroup>
`http://localhost:8000`
API documentation is automatically available at:
`http://localhost:8000/docs`
You can add your own routes, middleware, or any FastAPI feature on top.
The AgentOS UI connects directly from your browser to your runtime.
It lets you test, monitor, and manage your agents in real time.
- Open os.agno.com and sign in.
- Click "Add new OS" in the top navigation.
- Select "Local" to connect to a local AgentOS.
- Enter your endpoint URL (default:
http://localhost:8000). - Name it something like "Development OS".
- Click "Connect".
You’ll see your OS with a live status indicator once connected.
Open Chat, select your agent, and ask:
What is Agno?
The agent retrieves context from the Agno MCP server and responds with grounded answers.
Click Sessions in the sidebar to inspect stored conversations.
All session data is stored in your local database. No third-party tracing or hosted memory service is required.
In 20 lines, you built:
- A stateful agent
- Tool-augmented retrieval via MCP
- A streaming API
- Session isolation
- A production-ready runtime
You can use this exact same architecture for running multi-agent systems in production.