Host agents as FastAPI Applications.
FastAPIApp
, and serve it:
OPENAI_API_KEY
environment variable.http://localhost:8001
, docs at http://localhost:8001/docs
.POST
requests to http://localhost:8001/runs?agent_id=basic_agent
:
FastAPIApp
: Wraps Agno agents/teams for FastAPI.FastAPIApp.serve
: Serves the FastAPI app using Uvicorn.FastAPIApp
uses helper functions for routing.
FastAPIApp
ClassParameter | Type | Default | Description |
---|---|---|---|
agents | Optional[List[Agent]] | None | List of Agno Agent instances. |
teams | Optional[List[Team]] | None | List of Agno Team instances. |
workflows | Optional[List[Team]] | None | List of Agno Workflow instances. |
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. |
agent
or team
, not both.
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. |
prefix
(default /v1
).
POST /run
agent.run()
/arun()
or team.run()
/arun()
).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. |
stream=True
: StreamingResponse
(text/event-stream
) with JSON RunResponse
/TeamRunResponse
events.stream=False
: JSON RunResponse
/TeamRunResponse
dictionary.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. |