Production-ready orchestration for AI agents, built with Pydantic.
Project description
Flujo
A powerful Python library for orchestrating AI workflows using Pydantic models.
The flujo package (repository hosted at
github.com/aandresalvarez/flujo)
provides utilities to manage multi-agent pipelines with minimal setup.
Features
- 📦 Pydantic Native – agents, tools, and pipeline context are all defined with Pydantic models for reliable type safety.
- 🔁 Opinionated & Flexible – the
Defaultrecipe gives you a ready‑made workflow while the DSL lets you build any pipeline. - 🏗️ Production Ready – retries, telemetry, and quality controls help you ship reliable systems.
- 🧠 Intelligent Evals – automated scoring and self‑improvement powered by LLMs.
Quick Start
Installation
pip install flujo
Basic Usage
from flujo.recipes import AgenticLoop
from flujo import make_agent_async, init_telemetry
from flujo.domain.commands import AgentCommand
from pydantic import TypeAdapter
# Enable telemetry (optional but recommended)
init_telemetry()
async def search_agent(query: str) -> str:
"""A simple tool agent that returns information."""
if "python" in query.lower():
return "Python is a high-level, general-purpose programming language."
return "No information found."
PLANNER_PROMPT = """
You are a research assistant. Use the `search_agent` tool to gather facts.
When you know the answer, issue a `FinishCommand` with the final result.
"""
planner = make_agent_async(
"openai:gpt-4o",
PLANNER_PROMPT,
TypeAdapter(AgentCommand),
)
loop = AgenticLoop(planner_agent=planner, agent_registry={"search_agent": search_agent})
result = loop.run("What is Python?")
print(result.final_pipeline_context.command_log[-1].execution_result)
Pipeline Example
from flujo import Flujo, step, PipelineResult
@step
async def to_uppercase(text: str) -> str:
"""A simple step to convert text to uppercase."""
return text.upper()
@step
async def add_enthusiasm(text: str) -> str:
"""A second step to add emphasis."""
return f"{text}!!!"
# Compose the pipeline using the decorator-created steps
pipeline = to_uppercase >> add_enthusiasm
runner = Flujo(pipeline)
# Run the pipeline
result: PipelineResult[str] = runner.run("hello world")
print(f"Final pipeline output: {result.step_history[-1].output}")
# Expected Output: Final pipeline output: HELLO WORLD!!!
Documentation
Getting Started
- Installation Guide: Detailed installation instructions
- Quickstart Guide: Get up and running quickly
- Core Concepts: Understand the fundamental concepts
User Guides
- Usage Guide: Learn how to use the library effectively
- Configuration Guide: Configure the orchestrator
- Tools Guide: Create and use tools with agents
- Pipeline DSL Guide: Build custom workflows
- Scoring Guide: Implement quality control
- Telemetry Guide: Monitor and analyze usage
Advanced Topics
- Extending Guide: Create custom components
- Use Cases: Real-world examples and patterns
- API Reference: Detailed API documentation
- Troubleshooting Guide: Common issues and solutions
Development
- Contributing Guide: How to contribute to the project
- Development Guide: Development setup and workflow
- Code of Conduct: Community guidelines
- License: Dual License (AGPL-3.0 + Commercial)
Examples
Check out the examples directory for more usage examples:
| Script | What it shows |
|---|---|
| 00_quickstart.py | Hello World with the AgenticLoop recipe. |
| 01_weighted_scoring.py | Weighted scoring to prioritize docstrings. |
| 02_custom_agents.py | Building creative agents with custom prompts. |
| 03_reward_scorer.py | Using an LLM judge via RewardScorer. |
| 04_batch_processing.py | Running multiple workflows concurrently. |
| 05_pipeline_sql.py | Pipeline DSL with SQL validation plugin. |
| 06_typed_context.py | Sharing state with Typed Pipeline Context. |
| 07_loop_step.py | Iterative refinement using LoopStep. |
| 08_branch_step.py | Dynamic routing with ConditionalStep. |
Looking for more community resources? Check out the Awesome Flujo list.
Requirements
- Python 3.11 or higher
- OpenAI API key (for OpenAI models)
- Anthropic API key (for Claude models)
- Google API key (for Gemini models)
Installation
Basic Installation
pip install flujo
Development Installation
# Clone the repository
git clone https://github.com/aandresalvarez/flujo.git
cd flujo
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # Linux/macOS
# or
.\venv\Scripts\activate # Windows
# Install development dependencies
pip install -e ".[dev]"
# Set up the Hatch environment for tooling
pip install hatch
make setup
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Support
License
This project is dual-licensed:
-
Open Source License: GNU Affero General Public License v3.0 (AGPL-3.0)
- Free for open-source projects
- Requires sharing of modifications
- Suitable for non-commercial use
-
Commercial License
- For businesses and commercial use
- Includes support and updates
- No requirement to share modifications
- Contact for pricing and terms
For commercial licensing, please contact: alvaro@example.com
See LICENSE and COMMERCIAL_LICENSE for details.
Acknowledgments
- Pydantic for data validation
- OpenAI for GPT models
- Anthropic for Claude models
- Google for Gemini models
- All our contributors and users
Citation
If you use this project in your research, please cite:
@software{flujo,
author = {Alvaro Andres Alvarez},
title = {Flujo},
year = {2024},
url = {https://github.com/aandresalvarez/flujo}
}
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 flujo-0.4.22.tar.gz.
File metadata
- Download URL: flujo-0.4.22.tar.gz
- Upload date:
- Size: 143.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
844199a7be92a2fc5197c952a2f0e307b68984db446ea16c83875e611e3b5a43
|
|
| MD5 |
981c8eb4f662a81665ef52933d35d62f
|
|
| BLAKE2b-256 |
5510516085ec33a5abd412f6096e4a1b1ea0f63da79e0646fc7d7f4dcc912af4
|
Provenance
The following attestation bundles were made for flujo-0.4.22.tar.gz:
Publisher:
release.yml on aandresalvarez/flujo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flujo-0.4.22.tar.gz -
Subject digest:
844199a7be92a2fc5197c952a2f0e307b68984db446ea16c83875e611e3b5a43 - Sigstore transparency entry: 248383349
- Sigstore integration time:
-
Permalink:
aandresalvarez/flujo@4b58bfbf28f70a6ff634f5df65cfcc0d80a97389 -
Branch / Tag:
refs/tags/v0.4.22 - Owner: https://github.com/aandresalvarez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4b58bfbf28f70a6ff634f5df65cfcc0d80a97389 -
Trigger Event:
push
-
Statement type:
File details
Details for the file flujo-0.4.22-py3-none-any.whl.
File metadata
- Download URL: flujo-0.4.22-py3-none-any.whl
- Upload date:
- Size: 72.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7ce5d971c338f64a24fad1ada1b9d035304c354873b5835c2fe946e8b3bbec4
|
|
| MD5 |
f187e60f14528c139177153b2a873e2f
|
|
| BLAKE2b-256 |
72256242d47fe199464a8be072a0ef6287fddf7781b8f0cfb8eb0db408b9e529
|
Provenance
The following attestation bundles were made for flujo-0.4.22-py3-none-any.whl:
Publisher:
release.yml on aandresalvarez/flujo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flujo-0.4.22-py3-none-any.whl -
Subject digest:
d7ce5d971c338f64a24fad1ada1b9d035304c354873b5835c2fe946e8b3bbec4 - Sigstore transparency entry: 248383353
- Sigstore integration time:
-
Permalink:
aandresalvarez/flujo@4b58bfbf28f70a6ff634f5df65cfcc0d80a97389 -
Branch / Tag:
refs/tags/v0.4.22 - Owner: https://github.com/aandresalvarez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4b58bfbf28f70a6ff634f5df65cfcc0d80a97389 -
Trigger Event:
push
-
Statement type: