Applications
FastAPI App
Host agents as FastAPI Applications.
The FastAPI App is used to serve Agents or Teams using a FastAPI server with a rest api interface.
Example Usage
Create an agent, wrap it with FastAPIApp
, and serve it:
To run:
- Set
OPENAI_API_KEY
environment variable. - API at
http://localhost:8001
, docs athttp://localhost:8001/docs
.
Send POST
requests to http://localhost:8001/v1/run
:
Core Components
FastAPIApp
: Wraps Agno agents/teams for FastAPI.serve_fastapi_app
: Serves the FastAPI app using Uvicorn.
FastAPIApp
uses helper functions for routing.
FastAPIApp
Class
Main entry point for Agno FastAPI apps.
Initialization Parameters
Parameter | Type | Default | Description |
---|---|---|---|
agent | Optional[Agent] | None | Agno Agent instance. |
team | Optional[Team] | None | Agno Team instance. |
settings | Optional[APIAppSettings] | None | API configuration. Defaults if None . |
api_app | Optional[FastAPI] | None | Existing FastAPI app. New one created if None . |
router | Optional[APIRouter] | None | Existing APIRouter. New one created if None . |
app_id | Optional[str] | None | App identifier (autogenerated if not set). |
name | Optional[str] | None | Name for the App. |
description | Optional[str] | None | Description for the App. |
Provide agent
or team
, not both.
Key Method
Method | Parameters | Return Type | Description |
---|---|---|---|
get_app | use_async: bool = True prefix: str = "/v1" | FastAPI | Returns configured FastAPI app (async by default). Sets prefix, error handlers, CORS, docs. |
Endpoints
Endpoints are available at the specified prefix
(default /v1
).
1. POST /run
- Description: Interacts with the agent/team (uses
agent.run()
/arun()
orteam.run()
/arun()
). - Request Form Parameters:
Parameter Type Default Description message
str
...
Input message (Required). stream
bool
True
(sync),False
(async default)Stream response. monitor
bool
False
Enable monitoring. session_id
Optional[str]
None
Session ID for conversation continuity. user_id
Optional[str]
None
User ID. files
Optional[List[UploadFile]]
None
Files to upload. - Responses:
stream=True
:StreamingResponse
(text/event-stream
) with JSONRunResponse
/TeamRunResponse
events.stream=False
: JSONRunResponse
/TeamRunResponse
dictionary.
Serving the Application (serve_fastapi_app
)
Serves the FastAPI app using Uvicorn.
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
app | Union[str, FastAPI] | N/A | FastAPI app instance or import string (Required). |
host | str | "localhost" | Host to bind. |
port | int | 7777 | Port to bind. |
reload | bool | False | Enable auto-reload for development. |