5-Minute Quickstart¶
Get a FastAgentic agent running in under 5 minutes.
Prerequisites¶
- Python 3.10+
- uv (recommended) or pip
- OpenAI API key (or Anthropic)
Step 1: Create Project (30 seconds)¶
# Create directory
mkdir my-agent && cd my-agent
# Initialize with uv
uv init
uv add "fastagentic[pydanticai]"
Step 2: Create Agent (1 minute)¶
Create app.py:
from fastagentic import App, agent_endpoint, tool
from fastagentic.adapters.pydanticai import PydanticAIAdapter
from pydantic import BaseModel
from pydantic_ai import Agent
# Create your agent
agent = Agent(
model="openai:gpt-4o-mini",
system_prompt="You are a helpful assistant.",
)
# Add a tool
@agent.tool
async def get_time() -> str:
"""Get current time."""
from datetime import datetime
return datetime.now().strftime("%H:%M:%S")
# Create FastAgentic app
app = App(title="My Agent", version="1.0.0")
# Define request/response
class ChatRequest(BaseModel):
message: str
class ChatResponse(BaseModel):
response: str
# Expose as endpoint
@agent_endpoint(
path="/chat",
runnable=PydanticAIAdapter(agent),
input_model=ChatRequest,
output_model=ChatResponse,
stream=True,
)
async def chat(request: ChatRequest) -> ChatResponse:
pass
Step 3: Set API Key (10 seconds)¶
Step 4: Run (30 seconds)¶
Output:
Step 5: Test (1 minute)¶
Option A: Agent CLI (Recommended)¶
Option B: curl¶
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "What time is it?"}'
Option C: OpenAPI Docs¶
Open http://localhost:8000/docs in your browser.
What You Get¶
| Interface | URL |
|---|---|
| REST API | POST /chat |
| OpenAPI Docs | /docs |
| MCP Schema | /mcp/schema |
| Health Check | /health |
Next Steps¶
Add more tools¶
@agent.tool
async def search(query: str) -> str:
"""Search for information."""
return f"Results for: {query}"
Enable streaming¶
Already enabled! Use SSE client or Agent CLI.
Add authentication¶
Enable persistence¶
# Start Redis
docker run -d -p 6379:6379 redis
# Update app.py
app = App(
title="My Agent",
durable_store="redis://localhost:6379",
)
Use with Claude Desktop (MCP)¶
Add to claude_desktop_config.json:
{
"mcpServers": {
"my-agent": {
"command": "fastagentic",
"args": ["mcp", "serve", "app:app"],
"cwd": "/path/to/my-agent"
}
}
}
Complete Example¶
"""Complete FastAgentic agent in one file."""
from datetime import datetime
from fastagentic import App, agent_endpoint, tool, resource
from fastagentic.adapters.pydanticai import PydanticAIAdapter
from pydantic import BaseModel
from pydantic_ai import Agent
# Agent with tools
agent = Agent(
model="openai:gpt-4o-mini",
system_prompt="You are a helpful assistant with access to tools.",
)
@agent.tool
async def get_time() -> str:
"""Get the current time."""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@agent.tool
async def calculate(expression: str) -> str:
"""Calculate a math expression."""
try:
return str(eval(expression))
except:
return "Error"
# FastAgentic app
app = App(title="Quick Agent", version="1.0.0")
class ChatRequest(BaseModel):
message: str
class ChatResponse(BaseModel):
response: str
@agent_endpoint(
path="/chat",
runnable=PydanticAIAdapter(agent),
input_model=ChatRequest,
output_model=ChatResponse,
stream=True,
mcp_tool="chat",
)
async def chat(request: ChatRequest) -> ChatResponse:
pass
@resource(name="info", uri="info")
async def info() -> dict:
return {"name": "Quick Agent", "version": "1.0.0"}
# Run: uv run fastagentic run
Troubleshooting¶
"Module not found"¶
"API key not set"¶
Port already in use¶
Learn More¶
- Getting Started Guide - Full setup guide
- Examples - Complete working examples
- Adapters - All supported frameworks
- CLI Reference - All commands