https://github.com/blairhudson/fastapi-agents
A FastAPI extension for integrating common AI agent frameworks.
https://github.com/blairhudson/fastapi-agents
agents fastapi llama-index pydantic-ai smolagents
Last synced: 8 days ago
JSON representation
A FastAPI extension for integrating common AI agent frameworks.
- Host: GitHub
- URL: https://github.com/blairhudson/fastapi-agents
- Owner: blairhudson
- License: mit
- Created: 2025-01-12T10:40:09.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-01-21T22:04:07.000Z (3 months ago)
- Last Synced: 2025-04-12T05:16:05.339Z (11 days ago)
- Topics: agents, fastapi, llama-index, pydantic-ai, smolagents
- Language: Python
- Homepage: https://fastapi-agents.blairhudson.com
- Size: 1.04 MB
- Stars: 32
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Citation: CITATION.cff
- Roadmap: ROADMAP.md
- Zenodo: .zenodo.json
Awesome Lists containing this project
README
# FastAPI Agents
**FastAPI Agents** is the ultimate FastAPI extension for integrating AI agents into your applications. With just a few lines of code, you can create, manage, and secure AI-powered endpoints, enabling you to build smarter, more interactive apps effortlessly. Whether you're a seasoned developer or just exploring AI integrations, FastAPI Agents has you covered! π
## β¨ Features at a Glance
- π€ **Easy Agent Management**: Register, organize, and interact with multiple AI agents seamlessly.
- π **Built-In Security**: Easily add API key, OAuth2, cookie, or OpenID authentication to your endpoints.
- π **Agent Framework Support**: Compatible with agent frameworks like PydanticAI, Llama-Index, HuggingFace Smolagents and CrewAI.
- π³ **Pre-Built Containers**: Easily deploy agents in your favourite framework with ready made containers.
- π **OpenAI Compatibility**: Use your APIs with other AI tooling including the OpenAI SDK itself. (Experimental)
- π οΈ **Extensibility**: Support additional agent frameworks by extending the `BaseAgent` class.
- π§© **Dynamic Dependencies**: Inject and resolve request-specific configurations effortlessly.
- π **Performance Optimized**: Leverage FastAPI's high performance and scalability for AI agent interactions.
- π **Auto-Generated API Documentation**: OpenAPI integration for your registered agents, out of the box!See [Releases](https://github.com/blairhudson/fastapi-agents/releases) for the latest updates at and [Roadmap](https://fastapi-agents.blairhudson.com/roadmap/) for what's coming.
## π Sponsors
You can support the ongoing development of FastAPI Agents by becoming a sponsor:
[Sponsor FastAPI Agents](https://github.com/sponsors/blairhudson)
## π Documentation
For further documentation, including detailed API documentation for the available agent frameworks, visit the [FastAPI Agents Documentation](https://fastapi-agents.blairhudson.com/).
## π Installation
Install `FastAPI Agents` using pip, poetry or uv:
```bash
pip install fastapi-agents
poetry add fastapi-agents
uv add fastapi-agents
```Install optional extras for your chosen agent frameworks:
```bash
pip install 'fastapi-agents[pydantic-ai]'
poetry add fastapi-agents -E pydantic-ai
uv add fastapi-agents --extra pydantic-ai
```For available extras, replace `pydantic-ai` with the desired agent framework (e.g. `smolagents` or `llama-index`). See [pyproject.toml](https://github.com/blairhudson/fastapi-agents/blob/main/pyproject.toml) for the full list of extras.
That's it! You're all set to start integrating AI agents into your FastAPI applications. π
## π Quick Start
### Registering Agents
Hereβs how to get started with a basic `PydanticAI` agent:
```python
from fastapi import FastAPI
from fastapi_agents import FastAPIAgents
from pydantic_ai import Agent# Create a FastAPI application and FastAPIAgents instance.
app = FastAPI()
agents = FastAPIAgents(path_prefix="/agents")# Initialize and register the agent.
# The framework is automatically detected.
agent = Agent("openai:gpt-4o-mini")
agents.register("pydanticai", agent)# Include the router in your FastAPI application.
app.include_router(agents)
```### Adding Security
Secure your endpoints with API Key authentication in just a few steps:
```python
from fastapi.security import APIKeyHeader
from fastapi_agents import FastAPIAgents# Define API Key validation
def validate_api_key(api_key: str = Depends(APIKeyHeader(name="X-API-Key"))):
if api_key != "my-secret-api-key":
raise HTTPException(status_code=403, detail="Invalid API Key")# Secure the agents
agents = FastAPIAgents(path_prefix="/agents", security_dependency=validate_api_key)
```π See [Security Examples](https://github.com/blairhudson/fastapi-agents/tree/main/examples/security) for more details.
### Running the Application
Run your FastAPI application with the registered agents:
```bash
uvicorn --reload :app
```Replace `` with the name of the Python module containing your FastAPI application.
That's it! You're all set to start building smarter, more secure FastAPI applications with AI agents. π
## π€ Supported Agent Frameworks
`FastAPI Agents` supports a variety of agent frameworks, including:
1. **PydanticAI**: AI agents powered by Pydantic AI. [Examples](https://github.com/blairhudson/fastapi-agents/tree/main/examples/pydantic-ai)
2. **Llama Index**: OpenAI agents with Llama Index integration. [Examples](https://github.com/blairhudson/fastapi-agents/tree/main/examples/llama-index)
3. **HuggingFace Smolagents**: Lightweight and efficient AI agents. [Examples](https://github.com/blairhudson/fastapi-agents/tree/main/examples/smolagents)
4. **CrewAI**: Multi-agent Framework to create Crews. [Examples](https://github.com/blairhudson/fastapi-agents/tree/main/examples/crewai)## π³ Using Docker
FastAPI Agents provides pre-built Docker images for each agent framework. To get started, pull the desired image from the GitHub Container Registry (GHCR):
```bash
docker pull ghcr.io/blairhudson/fastapi-agents:pydantic-ai
```For more information, see the [FastAPI Agents Docker Documentation](https://fastapi-agents.blairhudson.com/docker/).
## π‘ Examples
Explore real-world examples for implementing `FastAPI Agents` in different scenarios, including step-by-by Jupyter notebook guides and standalone code samples.
See all available [Guides](https://fastapi-agents.blairhudson.com/notebooks/getting-started/) and [Example Code](https://fastapi-agents.blairhudson.com/examples) in the FastAPI Agents documentation.
## π€ Contributing
We welcome contributions! To contribute:
1. Fork the repository.
2. Create a feature branch.
3. Add any new tests and ensure they pass. i.e. `uv run pytest`.
4. Submit a pull request.For any questions or feature requests including additional agent frameworks, open an issue in the repository.
## π Citation
If you use **FastAPI Agents** in your work, please consider citing it using the metadata in the `CITATION.cff` file:
[](https://doi.org/10.5281/zenodo.14635504)
This DOI represents all versions of the project. For version-specific DOIs, refer to the [Zenodo project page](https://doi.org/10.5281/zenodo.14635504).
Alternatively, you can use the following BibTeX entry:
```bibtex
@software{fastapi_agents,
author = {Blair Hudson},
title = {FastAPI Agents},
year = {2025},
version = {0.1},
doi = {10.5281/zenodo.14635504},
url = {https://github.com/blairhudson/fastapi-agents},
orcid = {https://orcid.org/0009-0007-4216-4555},
abstract = {FastAPI Agents is the ultimate FastAPI extension for integrating AI agents into your applications.}
}
```## π License
This project is licensed under the MIT License. See the `LICENSE` file for more details.