The 'FastAPI' for AI Agents - Build typed, production-ready AI agents in minutes
Project description
Axon ๐ง
The "FastAPI" for AI Agents
Build typed, production-ready AI agents in minutes, not hours.
Quick Start โข Features โข Examples โข Documentation
๐ฏ Why Axon?
The Problem: Building AI agents today feels like configuring Apache in 1999.
- LangChain? Powerful but complex (AbstractFactories everywhere).
- Manual OpenAI API? Too much boilerplate for tools and state management.
The Solution: Axon makes agent development as simple as FastAPI makes API development.
from axon import Agent
agent = Agent("ResearchBot")
@agent.tool
def search_web(query: str) -> str:
"""Search the internet."""
return duckduckgo_search(query)
response = agent.ask("Find the latest AI news")
No chains. No graphs. No configurations. Just Python.
โก Quick Start
Installation
pip install openai pydantic rich python-dotenv duckduckgo-search tiktoken requests
Create Your First Agent (60 seconds)
1. Set up environment:
echo "OPENAI_API_KEY=sk-your-key-here" > .env
2. Create app.py:
from axon import Agent
bot = Agent("Assistant", system="You are a helpful AI assistant.")
@bot.tool
def calculate(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
print(bot.ask("What is 15 + 27?"))
3. Run:
python app.py
That's it! ๐
๐ Features
๐ Zero Boilerplate
- Auto-schema generation: Type hints โ OpenAI function schemas
- Decorator-based tools: Just use
@agent.tool .envsupport: No manual environment handling
๐จ Beautiful DX
- Rich console logging: See agent reasoning in real-time
- Helpful errors: No cryptic stack traces
- 5-minute promise: From zero to working agent in 5 minutes
๐ Production Tools (v0.4 ๐)
Built-in batteries for real-world apps:
- Web Search (
web_search): DuckDuckGo integration, no API key - File System (
read_file,write_file): Safe file operations - HTTP/API (
http_get,http_post): REST API integration - Database (
query_db,create_table): SQLite queries & analytics
๐งช Type-Safe & Production-Ready
- Streaming Responses (v0.4): Real-time text generation
- Structured Outputs (v0.3): Return typed Pydantic models instead of strings
- History Management (v0.3): Auto-truncates conversation to stay within token limits
- Context/State (v0.3): Share data between tools without manual passing
- Persistent Memory (v0.5 ๐): Agents remember conversations across sessions
- Error Retry (v0.5 ๐): Automatic retry with exponential backoff
- Full type inference support
๐ Examples
Basic Math Agent
from axon import Agent
agent = Agent("MathBot")
@agent.tool
def multiply(a: int, b: int) -> int:
"""Multiply two numbers."""
return a * b
print(agent.ask("What's 12 times 8?"))
# Agent calls multiply(12, 8) โ "The result is 96"
Structured Output (v0.3 ๐)
from axon import Agent
from pydantic import BaseModel
class Email(BaseModel):
address: str
confidence: float
agent = Agent("EmailBot")
result = agent.ask(
"Extract email from: contact me at john@example.com",
response_model=Email
)
print(result.address) # "john@example.com"
print(result.confidence) # 0.95
Context/State Management (v0.3 ๐)
from axon import Agent, Context
agent = Agent("DataBot")
@agent.tool
def fetch_data(source: str, ctx: Context) -> str:
"""Fetch data and store in context."""
data = get_data(source)
ctx.set("data", data) # Share with other tools
return "Data fetched"
@agent.tool
def analyze(ctx: Context) -> str:
"""Analyze data from context."""
data = ctx.get("data") # Access shared state
return f"Analysis: {analyze(data)}"
# Agent automatically passes data between tools!
agent.ask("Fetch data from database and analyze it")
Web Research Agent
from axon import Agent
from axon_tools import web_search, write_file
agent = Agent("Researcher")
agent.tool(web_search)
agent.tool(write_file)
agent.ask("Search for Python AI frameworks and save a summary to report.txt")
# โ
Searches web, writes formatted report
More examples: See examples/ directory
Persistent Memory (v0.5 ๐)
from axon import Agent
# Enable memory for agent
agent = Agent("MemoryBot", memory="./memory.db")
# Session 1
agent.ask("My name is Alice and I love Python")
# Session 2 (new instance, same memory!)
agent2 = Agent("MemoryBot", memory="./memory.db")
agent2.ask("What's my name?")
# โ "Your name is Alice" โจ Remembers!
Error Retry (v0.5 ๐)
from axon import Agent, retry
agent = Agent("ReliableBot")
@agent.tool
@retry(max_attempts=3, backoff=2.0)
def flaky_api(url: str) -> str:
"""Call unreliable API with auto-retry."""
return requests.get(url).json()
# Automatically retries on failure with exponential backoff!
More examples: See examples/ directory
๐ฏ Advanced Features
History Management (v0.3)
Control conversation token usage to prevent context overflow:
agent = Agent(
"LongConversationBot",
max_history_tokens=4000 # Auto-truncates when exceeded
)
# After many questions, old messages are automatically removed
# System message is always preserved
Custom Configuration
agent = Agent(
name="CustomBot",
system="You are a helpful assistant specialized in...",
model="gpt-4o", # or "gpt-4o-mini"
max_history_tokens=2000
)
๐ Built-in Tools
Web Search
from axon_tools import web_search
@agent.tool
def search(query: str) -> str:
return web_search(query, max_results=5)
- Uses DuckDuckGo (no API key!)
- Returns formatted results with URLs
File Operations
from axon_tools import read_file, write_file
@agent.tool
def save_data(filename: str, content: str) -> str:
return write_file(filename, content)
๐ฆ Project Structure
axon/
โโโ axon/ # Core framework
โ โโโ core.py # Agent class
โ โโโ types.py # Type definitions
โ โโโ utils.py # Logging & utilities
โโโ axon_tools/ # Built-in plugins
โ โโโ web.py # Web search
โ โโโ filesystem.py # File operations
โโโ examples/ # Demo scripts
โ โโโ hello_world.py
โ โโโ web_researcher.py
โ โโโ simple_file_demo.py
โโโ tests/ # Test suite
๐ค Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
Quick contributions:
- ๐ Report bugs via Issues
- ๐ก Request features via Discussions
- ๐ง Submit PRs for fixes or new tools
๐บ๏ธ Roadmap
- v0.1: Core Agent + Tool decorator
- v0.2: Plugin ecosystem (Web Search, File System)
- v0.3: Production essentials (Structured Outputs, History Management, Context/State)
- v0.4: Essential tools (Streaming, HTTP/API, Database)
- v0.5: Intelligence & Memory (Persistent Memory, Error Retry, Plugin System) โจ CURRENT
- v0.6: Multi-agent collaboration
- v1.0: Axon Studio (Visual debugging UI) + Enterprise features
๐ Documentation
Core Concepts
Agent
The main orchestrator. Manages LLM calls, tool execution, and conversation history.
agent = Agent(
name="MyBot",
system="You are...", # System prompt
model="gpt-4o", # OpenAI model
max_history_tokens=4000 # Token limit (v0.3)
)
Tools
Functions that agents can call. Automatically registered with @agent.tool:
@agent.tool
def my_function(param: str) -> str:
"""This docstring becomes the tool description."""
return f"Result: {param}"
Requirements:
- Must have type hints
- Must have a docstring
- Return value should be string or serializable
Structured Outputs (v0.3)
Return typed Pydantic models instead of strings:
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
email: str
result = agent.ask(
"Extract person info from: John Doe, 30, john@example.com",
response_model=Person
)
# result is a Person instance with validated fields
print(result.name) # "John Doe"
Context/State (v0.3)
Share data between tools:
from axon import Context
@agent.tool
def step_one(data: str, ctx: Context) -> str:
"""Process data and store result."""
result = process(data)
ctx.set("result", result) # Store for next tool
return "Done"
@agent.tool
def step_two(ctx: Context) -> str:
"""Use data from previous tool."""
result = ctx.get("result") # Retrieve
return f"Final: {result}"
Context API:
ctx.set(key, value)- Store valuectx.get(key, default=None)- Retrieve valuectx.has(key)- Check if key existsctx.delete(key)- Remove keyctx.clear()- Clear all datactx.keys()- Get all keys
History Management (v0.3)
Automatic conversation truncation:
agent = Agent("Bot", max_history_tokens=2000)
# When token count exceeds limit:
# - System message is preserved
# - Oldest messages are removed
# - Automatic truncation on each ask()
โ๏ธ License
MIT License - see LICENSE for details
๐ Star History
If Axon saves you time, give us a star! โญ
๐ Acknowledgments
Inspired by:
- FastAPI: For proving that DX matters
- LangChain: For pioneering agent frameworks
- OpenAI: For making this possible
Built with โค๏ธ by developers, for developers
Report Bug โข Request Feature โข โญ Star
โญ Stargazers over time
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 axon_framework-0.5.0.tar.gz.
File metadata
- Download URL: axon_framework-0.5.0.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aa0d4f702b3899f1cc1bdc890ab89c23b02b10513cbe48c07be21313294735d
|
|
| MD5 |
f6f97efdf86c55c48388abc4e37d72fa
|
|
| BLAKE2b-256 |
84b3142adc9c1dce13ecfdbedeb3d586276f0b5c0cfd89df05e3c5c3b2093772
|
File details
Details for the file axon_framework-0.5.0-py3-none-any.whl.
File metadata
- Download URL: axon_framework-0.5.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30d7b10bae9cba769ebdba83c9a5aecfaa32aa89c3e85eea8f53fb333d6fb876
|
|
| MD5 |
3bf2360200324622121bb783a827ddad
|
|
| BLAKE2b-256 |
164cb17411b54f68e1b6efd26cc23d691d6800b5eb148187fc59086b2e2bd58e
|