Up and Running in 30 Seconds¶
Install, import, and get a response from any supported provider.
import asyncio
from flux import Agent, Runner
async def main():
agent = Agent(name="assistant", instructions="Tell me a joke")
stream = await Runner.run_streamed(agent, "Tell me a joke")
async for event in stream:
if hasattr(event, "delta"):
print(event.delta, end="", flush=True)
print()
asyncio.run(main())
Everything You Need to Build Agentic Systems¶
Flux gives you a complete toolkit for building, testing, and deploying AI agents -- from single-purpose assistants to complex multi-agent pipelines.
-
Provider Agnostic
Switch between Ollama, OpenAI, Anthropic, Groq, DeepSeek, and OpenRouter with a single import change. No vendor lock-in, ever.
-
Async First
Non-blocking by default for maximum throughput. Need synchronous code?
Runner.run_sync()is always available. -
Protocol Based
Structural typing via
Protocol-- no inheritance required. Any class with the right methods is a valid Tool, Model, or Session. -
Middleware
Composable middleware for logging, caching, retry, and rate-limiting. Wrap any agent run with zero coupling to the core framework.
-
Event Driven
Decoupled event bus for observability and analytics. Subscribe to agent, tool, and session events without modifying the runner.
-
Tools
Decorate any function with
@tooland it becomes callable by agents. Built-in tools for shell, file I/O, and more. -
Handoffs
Agent-to-agent routing for multi-agent systems. Let a router delegate to specialist agents automatically.
-
Guardrails
Input and output validation built in. Length checks, PII detection, profanity filtering, and custom guardrails.
-
Sessions
In-memory sessions for ephemeral chats and SQLite-backed sessions for persistence across restarts.
-
Memory
Conversation memory and vector-based retrieval for long-term knowledge across sessions.
-
Streaming
Real-time token streaming with structured events. Get partial responses as they are generated.
-
Tracing
Console and file-based tracing for debugging and auditing. Capture every model call, tool invocation, and handoff.
Architecture at a Glance¶
A clean, layered design where every component is optional and composable.
graph TB
subgraph User["User Application"]
U[Your Code]
end
subgraph Flux["Flux Framework"]
R[Runner]
A[Agent]
MW[Middleware Stack]
EB[Event Bus]
GR[Guardrails]
end
subgraph Providers["LLM Providers"]
OLL[Ollama]
OAI[OpenAI]
ANT[Anthropic]
GROQ[Groq]
DS[DeepSeek]
OR[OpenRouter]
end
subgraph Storage["Persistence & Memory"]
IM[InMemory Session]
SQL[SQLite Session]
VM[Vector Memory]
end
subgraph Ext["Extensions"]
T[Tools]
HO[Handoffs]
TR[Tracing]
end
U --> R
R --> A
A --> MW
MW --> R
R --> GR
R --> Providers
R --> EB
R --> T
R --> HO
R --> Storage
EB --> TR
style User fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
style Flux fill:#fff3e0,stroke:#f57c00,stroke-width:2px
style Providers fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
style Storage fill:#e3f2fd,stroke:#1565c0,stroke-width:2px
style Ext fill:#fce4ec,stroke:#c62828,stroke-width:2px
Why Flux?¶
Six design principles that set Flux apart.
-
Protocol over ABC
No inheritance required. Any class with the right methods works as a Model, Tool, or Session. Your code stays yours -- no framework coupling.
-
Async First
Every code path is async for maximum concurrency. Sync wrappers are provided for scripts and notebooks, so you never pay for what you don't use.
-
Zero Core Dependencies
The base framework ships with zero third-party dependencies. Provider packages are installed on demand -- no bloated environments.
-
Middleware over Hooks
Composable middleware wraps the entire run cycle. Modify requests, log calls, add caching, or retry failures -- all without touching the runner.
-
Immutable Agents
Agents are immutable dataclasses. Share them across threads without fear. Use
clone()to create modified copies safely. -
:material-broadcast-outline:{ .lg .middle } Event-Driven
A decoupled event bus for observability, analytics, and custom hooks. Subscribe from anywhere -- no framework modification needed.
Installation¶
One command to start. Add providers as you need them.
Zero Dependencies
The core package has no third-party dependencies. Provider SDKs are installed separately.
See It in Action¶
Real patterns you can copy into your projects.
from flux import Agent, Runner, tool
@tool
def calculator(expression: str) -> str:
"""Evaluate a math expression."""
return str(eval(expression))
agent = Agent(
name="math_bot",
instructions="Use calculator for math",
tools=[calculator],
)
result = Runner.run_sync(agent, "What is 15 * 23?")
print(result.final_output)
import asyncio
from flux import Agent, Runner
from flux.handoffs.handoff import Handoff
async def main():
coder = Agent(name="coder", instructions="Write code")
writer = Agent(name="writer", instructions="Write content")
router = Agent(
name="router",
instructions="Route to specialist",
handoffs=(
Handoff(source=router, target=coder),
Handoff(source=router, target=writer),
),
)
result = await Runner.run(router, "Write Python hello world")
print(f"Handled by: {result.last_agent.name}")
asyncio.run(main())
import asyncio
from flux import Agent, Runner, SQLiteSession
async def main():
agent = Agent(name="bot", instructions="Remember everything")
session = SQLiteSession(db_path="chat.db")
r1 = await Runner.run(agent, "My name is Sara", session=session)
r2 = await Runner.run(agent, "What is my name?", session=session)
print(f"Bot: {r2.final_output}")
asyncio.run(main())
from flux import Agent
from flux.middleware.base import Middleware, NextFn, RequestContext, Response
class TimingMiddleware:
async def process(self, ctx: RequestContext, next: NextFn) -> Response:
import time
start = time.time()
response = await next(ctx)
print(f"Elapsed: {time.time() - start:.2f}s")
return response
agent = Agent(
name="timed",
instructions="Be helpful",
middleware=[TimingMiddleware()],
)
from flux import Agent, Runner
from flux.models.base import ModelRequest, ModelResponse, StreamChunk
class MyModel:
async def complete(self, request: ModelRequest) -> ModelResponse:
return ModelResponse(content="Hello from my model!")
async def stream(self, request: ModelRequest):
yield StreamChunk(delta_text="Hello!", done=True)
agent = Agent(name="custom", instructions="Be helpful", model=MyModel())
result = Runner.run_sync(agent, "Hi")
print(result.final_output)
Explore the Documentation¶
-
Getting Started
Installation, quickstart, and your first agent.
-
Core Concepts
Agents, tools, providers, sessions, middleware, and more.
-
API Reference
Complete class and function documentation.
-
Guides
Step-by-step tutorials for real-world patterns.
-
Examples
Copy-paste code samples for every feature.
-
Architecture
Design decisions, directory structure, and execution flow.
Community¶
-
GitHub
Source code, issue tracker, and release notes. Contributions are welcome.
-
:material-pypi:{ .lg .middle } PyPI
Published packages for core and all provider extras.
-
Twitter / X
Announcements, tips, and community highlights.
Roadmap¶
What is coming next for Flux Agents.
Upcoming Features
v0.2 -- Structured Output & Pydantic Integration
Define output schemas with Pydantic models. Agents will return validated, typed data instead of raw strings.
v0.2 -- Agent Cloning with Presets
Pre-built agent templates for common patterns: chatbot, researcher, coder, and summarizer.
v0.3 -- HTTP Server & REST API
Built-in HTTP server to expose agents as API endpoints with streaming support.
v0.3 -- MCP (Model Context Protocol) Support
Connect Flux agents to MCP servers for tool and resource discovery across the ecosystem.
v0.4 -- Evaluation & Benchmarking
Built-in evaluation harness to test agent accuracy, latency, and cost across providers.
v0.4 -- Multi-Modal Support
Vision and audio inputs through provider-specific multi-modal APIs.
Get Involved
Flux is open source and community-driven. Check the Contributing guide to get started, or open an issue on GitHub to request a feature.