A lightweight, extensible, and provider-agnostic Python framework for building LLM agents.
Project description
TinyFlow
TinyFlow is a lightweight, extensible, and provider-agnostic Python framework for building LLM agents. It provides a clean abstraction layer over major LLM providers (OpenAI, Anthropic, Gemini), embedding models, and vector databases, enabling you to build complex agentic workflows with ease.
🚀 Key Features
- Provider Agnostic: Switch seamlessly between OpenAI, Anthropic, and Google Gemini models using a unified
LLMFactory. - Agentic Workflow: Built-in "Thinking -> Acting -> Observing" loop for autonomous task execution.
- Tool Support: Easy-to-use
@tooldecorator to give your agents capabilities (web search, code execution, etc.). - Memory & RAG: Integrated Vector Database support (ChromaDB, Qdrant) and Embedding abstraction (OpenAI, SentenceTransformers).
- Unified Configuration: flexible configuration system supporting parameters, environment variables, and settings files with clear precedence.
- Streaming UI: Rich streaming support for building interactive chat interfaces, including reasoning steps and tool execution visibility.
- Modern Stack: Built with Python 3.12+, Pydantic, Asyncio, and managed with
uv.
📦 Installation
You can install TinyFlow using pip or uv.
Using pip
pip install tinyflow-llm
Using uv (Recommended)
uv add tinyflow-llm
Installation with Extras
TinyFlow supports optional dependencies for specific features:
- Local Embeddings:
pip install "tinyflow-llm[local]" - Vector Databases:
pip install "tinyflow-llm[vector]"(includes ChromaDB and Qdrant)
⚙️ Configuration
TinyFlow uses a unified configuration system. You can configure providers via:
- Explicit Parameters (passed to Factory
createmethods) - Highest Priority - Environment Variables - Medium Priority
- Settings / Defaults - Lowest Priority
Common Environment Variables
| Category | Variable | Description |
|---|---|---|
| LLM | LLM_PROVIDER |
openai, anthropic, or gemini |
LLM_API_KEY |
API Key for the selected provider | |
LLM_MODEL |
Model name (e.g., gpt-4o, claude-3-5-sonnet) |
|
LLM_BASE_URL |
Optional custom base URL (e.g., for proxies) | |
| Embeddings | EMBEDDING_PROVIDER |
openai, local, or sentence-transformers |
EMBEDDING_API_KEY |
API Key for embedding provider | |
EMBEDDING_MODEL |
Model name (e.g., text-embedding-3-small) |
|
| Vector DB | VECTOR_DB_PROVIDER |
chroma or qdrant |
VECTOR_DB_PATH |
Path for local ChromaDB persistence | |
VECTOR_DB_URL |
URL for remote Vector DB (e.g., Qdrant Cloud) | |
VECTOR_DB_API_KEY |
API Key for remote Vector DB |
💡 Usage
1. Basic LLM Usage
Use the LLMFactory to create a provider instance. It automatically handles configuration.
import asyncio
from tinyflow.providers.base.factory import LLMFactory
from tinyflow.core.types import Message
async def main():
# Automatically loads config from env vars
llm = LLMFactory.create()
# Or specify explicitly
# llm = LLMFactory.create(provider="anthropic", model="claude-3-opus-20240229")
messages = [
Message(role="system", content="You are a helpful assistant."),
Message(role="user", content="Explain quantum computing in one sentence.")
]
response = await llm.generate(messages)
print(response.content)
if __name__ == "__main__":
asyncio.run(main())
2. Building an Agent with Tools
Create an Agent equipped with custom tools.
import asyncio
from tinyflow.core.agent import Agent
from tinyflow.providers.base.factory import LLMFactory
from tinyflow.core.tools import tool
# Define a tool
@tool
def get_weather(location: str, unit: str = "celsius") -> str:
"""Get the current weather for a location."""
# In a real app, call a weather API here
return f"The weather in {location} is 25°{unit.upper()} and sunny."
async def main():
# 1. Initialize LLM
llm = LLMFactory.create()
# 2. Create Agent with tools
agent = Agent(
llm=llm,
tools=[get_weather],
system_prompt="You are a helpful assistant with access to weather tools."
)
# 3. Run Agent
response = await agent.run("What's the weather like in Paris?")
print(response)
if __name__ == "__main__":
asyncio.run(main())
3. Using Vector Memory
Integrate RAG (Retrieval-Augmented Generation) capabilities.
from tinyflow.vector.factory import VectorDBFactory
from tinyflow.embeddings.factory import EmbeddingFactory
from tinyflow.memory.vector import VectorMemory
# Initialize components
embedding_model = EmbeddingFactory.create()
vector_db = VectorDBFactory.create()
# Create memory interface
memory = VectorMemory(
vector_db=vector_db,
embedding_model=embedding_model
)
# Use in Agent
agent = Agent(
llm=llm,
memory=memory,
system_prompt="Use your memory to answer questions."
)
🏗️ Project Structure
tinyflow/
├── tinyflow/
│ ├── config/ # Configuration and helper utilities
│ ├── core/ # Core abstractions (Agent, Tools, Types)
│ ├── providers/ # LLM Provider implementations (OpenAI, Anthropic, Gemini)
│ ├── embeddings/ # Embedding models (OpenAI, Local)
│ ├── vector/ # Vector Database adapters (Chroma, Qdrant)
│ └── memory/ # Memory implementations
├── tests/ # Unit and integration tests
├── main.py # Entry point example
└── pyproject.toml # Project dependencies and config
🧪 Development
Running Tests
TinyFlow uses pytest for testing.
# Run all tests
uv run pytest
# Run specific test file
uv run pytest tests/test_factories.py -v
Code Style
The project uses ruff for linting and formatting.
# Lint
uv run ruff check .
# Format
uv run ruff format .
📄 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 tinyflow_llm-0.1.0.tar.gz.
File metadata
- Download URL: tinyflow_llm-0.1.0.tar.gz
- Upload date:
- Size: 126.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc1233cb8798a11e2da7b110b9270e719e55310060f306185977594a97f5f9e2
|
|
| MD5 |
d34677b33c301512aa399487902cd6dc
|
|
| BLAKE2b-256 |
ec911bce86d6f0dd7a02fa7aa0e0b6e54c01ea43edc1ac6e4a304a2f8d19e412
|
File details
Details for the file tinyflow_llm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tinyflow_llm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 49.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c7b0151caf8ff0bc20b5b6e14791b3793ba1907b2caf0d8d66e3499fb2526d2
|
|
| MD5 |
9973240ae0ffbb5da26fe3b59f583a31
|
|
| BLAKE2b-256 |
b6a3232a1b8d2f0effbe181bbbf6d8a553bbfad9b5528cd201eae9f76084698c
|