Installation
FastAPI integration is an optional installation. To install all required dependencies, run:Setting Up FastAPI Endpoints
You can expose your agencies and tools as API endpoints using therun_fastapi() function.
Example: Create an API endpoint for a single agency
- host (default:
"0.0.0.0") - port (default:
8000) - app_token_env (default:
"APP_TOKEN") - Name of the env variable storing app token. - return_app (default: False) - If True, will return the FastAPI instead of running the server
- cors_origins: (default: [”*”])
- enable_agui (default:
False) - Enable AG-UI protocol compatibility for streaming endpoints - enable_logging (default:
False) - Enable request tracking and expose/get_logsendpoint - logs_dir (default:
"activity-logs") - Directory for log files when logging is enabled
/test_agency/get_response/test_agency/get_response_stream/test_agency/get_metadata
enable_logging=True, a /get_logs endpoint is also added.
Both of these endpoints will accept following input parameters:
"APP_TOKEN" specified (or a differently named variable if you provided app_token_env). If the token is not specified in the env variables, authentication will be disabled.
Example: Serving Multiple Agencies and Tools
/test_agency_1/get_response/test_agency_1/get_response_stream/test_agency_1/get_metadata/test_agency_2/get_response/test_agency_2/get_response_stream/test_agency_2/get_metadata/tool/ExampleTool(for BaseTools) or/tool/example_tool(for function tools)/tool/TestTool(for BaseTools) or/tool/test_tool(for function tools)
enable_logging=True, a /get_logs endpoint is also added.
Inputs for the tool endpoints will follow their respective schemas.
API Usage Example
You can interact with your agents and tools using HTTP requests. Here’s an example using Python’srequests library:
Endpoint Structure
-
Agency Endpoints:
Each agency is served at:
/your_agency_name/get_response(POST)/your_agency_name/get_response_stream(POST, streaming responses)/your_agency_name/get_metadata(GET)
-
Tool Endpoints:
Each tool is served at:
/tool/ToolClassName(POST) - for BaseTools/tool/function_name(POST) - for FunctionTools/openapi.json(GET) - aggregate schema for every agency and tool endpoint/docsand/redoc(GET) - interactive Swagger UI and ReDoc powered by the same OpenAPI spec
-
Logging Endpoint:
When
enable_logging=True:/get_logs(POST)
-
AG-UI Protocol:
When
enable_agui=True, only the streaming endpoint is exposed and follows the AG-UI protocol for enhanced frontend integration.
Inspecting Tool Schemas
When integrating your tools with external systems or documenting your API, you need to expose the parameter schemas. FastAPI automatically serves/openapi.json, so you can point tooling (Swagger UI, ReDoc, Agencii.ai, etc.) directly at the running server. The same schema is available programmatically via ToolFactory.get_openapi_schema() when you want to export it without starting FastAPI. Both outputs now share the same /tool/<ToolName> routes, HTTP Bearer security, and validation error responses, so either endpoint can be consumed interchangeably.
src/agency_swarm/tools/tool_factory.py
Example: Serving Standalone Tools
POST /tool/Address– executes the tool with full Pydantic validation (including nested models)GET /openapi.json– full schema for agencies and toolsGET /docs/GET /redoc– interactive exploration powered by/openapi.json
server_url when your server sits behind a proxy or external domain so /openapi.json advertises the correct base URL.
See examples/fastapi_integration/server.py for a complete multi-agent + tool setup.
File Attachments
When using the agency endpoints (/{your_agency}/get_response and /{your_agency}/get_response_stream), you can attach files in two ways:
- Direct inline:
.pdf,.jpeg,.jpg,.gif,.png - Via
file_ids/file_urls(processed, not inline):.c,.cs,.cpp,.csv,.html,.java,.json,.php,.py,.rb,.css,.js,.sh,.ts,.pkl,.tar,.xlsx,.xml,.zip,.doc,.docx,.md,.pptx,.tex,.txt - Rejected:
.goand any extension not listed above - Payload fields:
file_ids: string[]ORfile_urls: { filename: url }
file_urls:
- The server downloads each URL, uploads it to OpenAI, waits until processed, and uses the resulting File IDs.
file_ids_map(shape:{ filename: file_id }) is returned in the non‑streaming JSON response ofPOST /get_responseand in the finalevent: messagesSSE payload ofPOST /get_response_stream.