Learn how to use your own FastAPI app in your AgentOS
AgentOS is built on FastAPI, which means you can easily integrate your existing FastAPI applications or add custom routes and routers to extend your agent’s capabilities.
The simplest way to bring your own FastAPI app is to pass it to the AgentOS constructor:
Copy
Ask AI
from fastapi import FastAPIfrom agno.agent import Agentfrom agno.models.openai import OpenAIChatfrom agno.os import AgentOS# Create your custom FastAPI appapp = FastAPI(title="My Custom App")# Add your custom routes@app.get("/status")async def status_check(): return {"status": "healthy"}# Pass your app to AgentOSagent_os = AgentOS( agents=[Agent(id="basic-agent", model=OpenAIChat(id="gpt-5-mini"))], base_app=app # Your custom FastAPI app)# Get the combined app with both AgentOS and your routesapp = agent_os.get_app()
Your custom FastAPI app can have its own middleware and dependencies.If you have your own CORS middleware, it will be updated to include the AgentOS allowed origins, to make the AgentOS instance compatible with the Control Plane.
Otherwise, the appropriate CORS middleware will be added to the app.
You can add any FastAPI middleware to your custom FastAPI app and it will be respected by AgentOS.Agno also provides some built-in middleware for common use cases, including authentication.See the Middleware page for more details.
For better organization, use FastAPI routers to group related endpoints:
custom_fastapi_app.py
Copy
Ask AI
from agno.agent import Agentfrom agno.db.sqlite import SqliteDbfrom agno.models.anthropic import Claudefrom agno.os import AgentOSfrom agno.tools.duckduckgo import DuckDuckGoToolsfrom fastapi import FastAPI# Set up the databasedb = SqliteDb(db_file="tmp/agentos.db")# Set up the agentweb_research_agent = Agent( name="Basic Agent", model=Claude(id="claude-sonnet-4-0"), db=db, tools=[DuckDuckGoTools()], add_history_to_context=True, num_history_runs=3, add_datetime_to_context=True, markdown=True,)# Create custom FastAPI appapp: FastAPI = FastAPI( title="Custom FastAPI App", version="1.0.0",)# Add your own routes@app.post("/customers")async def get_customers(): return [ { "id": 1, "name": "John Doe", "email": "john.doe@example.com", }, { "id": 2, "name": "Jane Doe", "email": "jane.doe@example.com", }, ]# Set up the AgentOS app by passing your FastAPI appagent_os = AgentOS( description="Example app with custom routers", agents=[web_research_agent], base_app=app,)# Alternatively, add all routes from AgentOS app to the current app# for route in agent_os.get_routes():# app.router.routes.append(route)app = agent_os.get_app()if __name__ == "__main__": """Run the AgentOS application. You can see the docs at: http://localhost:7777/docs """ agent_os.serve(app="custom_fastapi_app:app", reload=True)
You can programmatically access and inspect the routes added by AgentOS:
Copy
Ask AI
agent_os = AgentOS(agents=[agent])app = agent_os.get_app()# Get all routesroutes = agent_os.get_routes()for route in routes: print(f"Route: {route.path}") if hasattr(route, 'methods'): print(f"Methods: {route.methods}")