Lightweight framework for building agentic AI backends with FastAPI
Project description
AgentAPI
AgentAPI is an open-source Python framework for building agentic AI backends with a clean developer experience: minimal setup, provider abstraction, tool calling, memory, and streaming-first APIs.
It is designed for teams that want FastAPI-style simplicity for LLM agents, without heavy orchestration overhead.
Table of Contents
- Why AgentAPI
- Features
- Installation
- Quick Start
- Provider Configuration
- Tool Calling
- Streaming
- CLI
- Custom Providers
- Error Handling
- Project Structure
- Project Status
- Roadmap
- Contributing
- License
Why AgentAPI
- Keep agent backends simple and readable.
- Use one
Agentinterface across providers. - Add tools as plain Python functions.
- Stream responses with minimal boilerplate.
- Start fast, then customize deeply when needed.
Features
Agentclass with memory and tool execution loop.- Provider abstraction for
openai,gemini, andopenrouter. - AgentAPI app integration with
@app.chat. - Automatic SSE when a chat handler returns an async iterator.
- Built-in project scaffolding and run helper via CLI.
- Environment-based configuration using
.env. - Extensible provider system (custom instance or registered factory).
Installation
Install from PyPI:
pip install agentapi-core
Install in editable mode while developing:
pip install -e .
Quick Start
Create main.py:
from agentapi import AgentApp, Agent
app = AgentApp()
agent = Agent(
system_prompt="You are a helpful assistant",
provider="openai",
)
@app.chat("/chat")
async def chat(message: str):
return await agent.run(message)
@app.chat("/stream")
async def stream_chat(message: str):
return agent.stream(message)
Run it:
uvicorn main:app --reload
Open docs:
http://127.0.0.1:8000/docshttp://127.0.0.1:8000/redoc
Provider Configuration
Create .env:
OPENAI_API_KEY=
GEMINI_API_KEY=
OPENROUTER_API_KEY=
DEFAULT_PROVIDER=openai
Supported provider names:
openaigeminiopenrouter
Tool Calling
Define tools with plain Python:
from agentapi import tool
@tool
def get_weather(city: str) -> str:
"""Get weather for a city."""
return f"Weather in {city}: sunny"
Attach tools to an agent:
agent = Agent(
system_prompt="You are a weather assistant",
provider="openai",
tools=[get_weather],
)
Tool schemas are generated from function signatures and mapped to provider-specific tool formats internally.
Streaming
@app.chat auto-switches to SSE (text/event-stream) when your handler returns an async iterator.
Example:
@app.chat("/stream")
async def stream_chat(message: str):
return agent.stream(message)
CLI
Create a new project scaffold:
agentapi new myproject
Interactive setup (asks for project name and provider):
agentapi new
Run app via helper:
agentapi run --app main:app --reload
Custom Providers
OpenAICompatibleProvider is an internal helper for OpenAI-compatible APIs. AgentAPI is not locked to it.
You can customize providers in two ways:
- Pass a provider instance directly:
provider=<BaseProvider instance> - Register a provider factory and reference by name.
from agentapi import Agent, BaseProvider
from agentapi.providers.base import ProviderResponse
class MyProvider(BaseProvider):
async def chat(self, messages, *, tools=None, tool_calling=None):
return ProviderResponse(content="hello", tool_calls=[], raw_message={})
async def stream(self, messages, *, tools=None, tool_calling=None):
yield "hello"
Agent.register_provider(
"myprovider",
lambda agent, settings, model: MyProvider(),
)
agent = Agent(system_prompt="You are helpful", provider="myprovider")
Error Handling
AgentAPI converts common runtime issues into clear API-level errors:
- Missing API keys -> configuration error message.
- Upstream provider failures -> provider error message with status context.
- Streaming endpoints emit SSE error events instead of hard crashes.
Project Structure
agentapi/
agent/
agent.py
memory.py
tools.py
assets/
agentapi-logo.png
agentapi-favicon.png
config/
settings.py
core/
app.py
providers/
base.py
gemini.py
openai_compatible.py
openai.py
openrouter.py
examples/
main.py
Project Status
Current phase: MVP
Implemented:
- Core agent runtime
- Provider abstraction (OpenAI, Gemini, OpenRouter)
- Tool calling and in-memory conversation memory
- Automatic SSE streaming on chat endpoints
- CLI scaffolding and run helper
Roadmap
- Add Anthropic provider.
- Expand memory backends (Redis/Postgres).
- Add richer observability and tracing hooks.
- Improve generated project templates.
- Add test suite and CI workflows.
Contributing
Contributions are welcome. See CONTRIBUTING.md for setup and PR workflow.
Publishing
This repository is configured to publish on GitHub Release.
- Bump
versioninpyproject.toml. - Commit and tag a release version.
- Create a GitHub Release.
- GitHub Actions publishes to PyPI using trusted publishing.
Required one-time setup:
- In PyPI, create project
agentapi-core. - Configure trusted publisher for this GitHub repository.
- Keep release workflow enabled in
.github/workflows/publish.yml.
Trusted Publisher Values
Use these exact values when adding publishers.
TestPyPI pending publisher:
- Project name:
agentapi-core - Owner:
prajwalsuryawanshi - Repository:
agentapi - Workflow filename:
publish-testpypi.yml - Environment name:
testpypi
PyPI trusted publisher (after project exists):
- Project name:
agentapi-core - Owner:
prajwalsuryawanshi - Repository:
agentapi - Workflow filename:
publish.yml - Environment name:
pypi
Note: package names on PyPI are normalized, so use lowercase agentapi-core.
License
MIT License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentapi_core-0.1.0.tar.gz.
File metadata
- Download URL: agentapi_core-0.1.0.tar.gz
- Upload date:
- Size: 181.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a63c44493efd343fb68b23792bb10c6139df2f9402062f524116b87416c6ccb
|
|
| MD5 |
218cae1e97a8b4aa667a99b836564ca5
|
|
| BLAKE2b-256 |
6af0ba957f9de058ac502b91fa5be01070fa463b085374c469a03b6ccbb651ff
|
Provenance
The following attestation bundles were made for agentapi_core-0.1.0.tar.gz:
Publisher:
publish.yml on prajwalsuryawanshi/agentapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentapi_core-0.1.0.tar.gz -
Subject digest:
6a63c44493efd343fb68b23792bb10c6139df2f9402062f524116b87416c6ccb - Sigstore transparency entry: 1065232221
- Sigstore integration time:
-
Permalink:
prajwalsuryawanshi/agentapi@549054db458934bf34bd3fcf0d565079524f22ee -
Branch / Tag:
refs/heads/main - Owner: https://github.com/prajwalsuryawanshi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@549054db458934bf34bd3fcf0d565079524f22ee -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file agentapi_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentapi_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 181.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50aeb8ab0cacd81bf2b7d1fd155af7c2bd3ce8d62a3b9b8a2ffb4eebd2e393e3
|
|
| MD5 |
8dc351e181258fd178ca8a33528a8976
|
|
| BLAKE2b-256 |
cf423f1ee3877af6d35cd7b09efa020a0a4b06484d969bdf090616884861e312
|
Provenance
The following attestation bundles were made for agentapi_core-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on prajwalsuryawanshi/agentapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentapi_core-0.1.0-py3-none-any.whl -
Subject digest:
50aeb8ab0cacd81bf2b7d1fd155af7c2bd3ce8d62a3b9b8a2ffb4eebd2e393e3 - Sigstore transparency entry: 1065232264
- Sigstore integration time:
-
Permalink:
prajwalsuryawanshi/agentapi@549054db458934bf34bd3fcf0d565079524f22ee -
Branch / Tag:
refs/heads/main - Owner: https://github.com/prajwalsuryawanshi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@549054db458934bf34bd3fcf0d565079524f22ee -
Trigger Event:
workflow_dispatch
-
Statement type: