A streamlined framework for building powerful LLM-powered agents that actually work
Project description
tinyAgent
Turn any Python function into an AI‑powered agent in just a few lines:
from tinyagent import tool, ReactAgent
@tool
def multiply(a: float, b: float) -> float:
"""Multiply two numbers together."""
return a * b
@tool
def divide(a: float, b: float) -> float:
"""Divide the first number by the second number."""
return a / b
agent = ReactAgent(tools=[multiply, divide])
result = agent.run("What is 12 times 5, then divided by 3?")
# → 20
That's it! The agent automatically:
- Understands it needs to perform multiple steps
- Calls
multiply(12, 5)→ gets 60 - Takes that result and calls
divide(60, 3)→ gets 20 - Returns the final answer
Why tinyAgent?
- Zero boilerplate – Just decorate functions with
@tool - Automatic reasoning – Agent figures out which tools to use and in what order
- Built-in LLM – Works out of the box with OpenRouter
- Type safe – Full type hints and validation
- Production ready – Error handling and retries
Installation
Option A: UV (Recommended - 10x Faster)
uv venv # Creates .venv/
source .venv/bin/activate # Activate environment
uv pip install tiny_agent_os
Option B: Traditional pip
pip install tiny_agent_os
Quick Setup
Set your API key:
export OPENAI_API_KEY=your_openrouter_key_here
export OPENAI_BASE_URL=https://openrouter.ai/api/v1
Get your key at openrouter.ai
Note: This is a clean rewrite focused on keeping tinyAgent truly tiny. For the legacy codebase (v0.72.x), install with
pip install tiny-agent-os==0.72.18or see the0.72branch.
Package Structure
As of v0.73, tinyAgent's internal structure has been reorganized for better maintainability:
tinyagent/agent.py→tinyagent/agents/agent.py(ReactAgent)tinyagent/code_agent.py→tinyagent/agents/code_agent.py(TinyCodeAgent)
The public API remains unchanged - you can still import directly from tinyagent:
from tinyagent import ReactAgent, TinyCodeAgent, tool
Setting the Model
Pass any OpenRouter model when creating the agent:
from tinyagent import ReactAgent, tool
# Default model
agent = ReactAgent(tools=[...])
# Specify a model
agent = ReactAgent(tools=[...], model="gpt-4o-mini")
agent = ReactAgent(tools=[...], model="anthropic/claude-3.5-sonnet")
agent = ReactAgent(tools=[...], model="meta-llama/llama-3.1-70b-instruct")
# TinyCodeAgent works the same way
agent = TinyCodeAgent(tools=[...], model="gpt-4o-mini")
More Examples
Multi-step reasoning
from tinyagent import tool, ReactAgent
@tool
def calculate_percentage(value: float, percentage: float) -> float:
"""Calculate what percentage of a value is."""
return value * (percentage / 100)
@tool
def subtract(a: float, b: float) -> float:
"""Subtract b from a."""
return a - b
agent = ReactAgent(tools=[calculate_percentage, subtract])
result = agent.run("If I have 15 apples and give away 40%, how many are left?")
print(result) # → "You have 9 apples left."
Behind the scenes:
- Agent calculates 40% of 15 → 6
- Subtracts 6 from 15 → 9
- Returns a natural language answer
Web Search Tool
Built-in web search capabilities with Brave Search API:
from tinyagent import ReactAgent
from tinyagent.base_tools import web_search
# Simple web search with formatted results
agent = ReactAgent(tools=[web_search])
result = agent.run("What are the latest Python web frameworks?")
# Works great for research and comparisons
agent = ReactAgent(tools=[web_search])
result = agent.run("Compare FastAPI vs Django performance")
Set your Brave API key:
export BRAVE_SEARCH_API_KEY=your_brave_api_key
For a scraping-based approach using the Jina Reader endpoint, see examples/jina_reader_demo.py.
Optionally set JINA_API_KEY in your environment to include an Authorization header.
Key Features
ReactAgent
- Multi-step reasoning - Breaks down complex problems automatically
- Clean API - Simple, ergonomic interface
- Error handling - Built-in retry logic and graceful failures
- Custom prompts - Load system prompts from text files for easy customization
TinyCodeAgent
- Python execution - Write and execute Python code to solve problems
- Sandboxed - Safe execution environment with restricted imports
- Custom prompts - Load system prompts from text files for easy customization
Tools Philosophy
Every function can be a tool. Keep them:
- Atomic - Do one thing well
- Typed - Use type hints for parameters
- Documented - Docstrings help the LLM understand usage
File-Based Prompts
Both ReactAgent and TinyCodeAgent support loading custom system prompts from text files:
- Simple - Just pass
prompt_file="path/to/prompt.txt"to the agent - Flexible - Supports
.txt,.md, and.promptfile extensions - Safe - Graceful fallback to default prompts if files are missing or invalid
- Powerful - Customize agent behavior without code changes
For examples, see examples/file_prompt_demo.py.
For a comprehensive guide on creating tools with patterns and best practices, see the tool creation documentation. For a concise overview, read the one-page tools guide.
Status
BETA - Actively developed and used in production. Breaking changes possible until v1.0.
Found a bug? Have a feature request? Open an issue!
License
Business Source License 1.1
- Free for individuals and small businesses (< $1M revenue)
- Enterprise license required for larger companies
Contact: info@alchemiststudios.ai
Made by @tunahorse21 | alchemiststudios.ai focusing on keeping it "tiny"
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 tiny_agent_os-0.73.5.tar.gz.
File metadata
- Download URL: tiny_agent_os-0.73.5.tar.gz
- Upload date:
- Size: 96.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7379170ecfcc0e7a65d76a2fa63abac50022faf644b3fb06fb0de54d64ac4f03
|
|
| MD5 |
4f05a7b3191324b6d6154ec8caa6558b
|
|
| BLAKE2b-256 |
adc44d4ea819e92f0b7e7ea8ddc93da297f315b6be82db74eaf3b2cbd2f3841b
|
File details
Details for the file tiny_agent_os-0.73.5-py3-none-any.whl.
File metadata
- Download URL: tiny_agent_os-0.73.5-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48c64a7424962852b17e44b23970d4934745b82ac821cadfeb341cfd6c4dfab0
|
|
| MD5 |
011a72dfe5c5886b2dcf8c017ff85166
|
|
| BLAKE2b-256 |
d626b02c3540b0bcf75f4c12404ca112df08feb6b22c60c17a108e1c0cfa8d4c
|