Skip to main content

Production-ready orchestration for AI agents, built with Pydantic.

Project description

Flujo Logo

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 Default recipe 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

User Guides

Advanced Topics

Development

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:

  1. 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
  2. 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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flujo-0.4.22.tar.gz (143.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flujo-0.4.22-py3-none-any.whl (72.0 kB view details)

Uploaded Python 3

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

Hashes for flujo-0.4.22.tar.gz
Algorithm Hash digest
SHA256 844199a7be92a2fc5197c952a2f0e307b68984db446ea16c83875e611e3b5a43
MD5 981c8eb4f662a81665ef52933d35d62f
BLAKE2b-256 5510516085ec33a5abd412f6096e4a1b1ea0f63da79e0646fc7d7f4dcc912af4

See more details on using hashes here.

Provenance

The following attestation bundles were made for flujo-0.4.22.tar.gz:

Publisher: release.yml on aandresalvarez/flujo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for flujo-0.4.22-py3-none-any.whl
Algorithm Hash digest
SHA256 d7ce5d971c338f64a24fad1ada1b9d035304c354873b5835c2fe946e8b3bbec4
MD5 f187e60f14528c139177153b2a873e2f
BLAKE2b-256 72256242d47fe199464a8be072a0ef6287fddf7781b8f0cfb8eb0db408b9e529

See more details on using hashes here.

Provenance

The following attestation bundles were made for flujo-0.4.22-py3-none-any.whl:

Publisher: release.yml on aandresalvarez/flujo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page