RustyFlow
A lightweight, high-performance agent framework for Rust, providing elegant abstractions for building complex AI workflows with type safety and async concurrency.
RustyFlow is a Rust rewrite of the popular Python PocketFlow framework, bringing memory safety, fearless concurrency, and zero-cost abstractions to agent-based computing.
🚀 Features
- 🦀 Rust-First: Built from the ground up in Rust for performance and safety
- ⚡ Async/Concurrent: Full async/await support with parallel and batch processing
- 🔧 Type-Safe Tools: Structured input/output with compile-time guarantees
- 🌐 HTTP Ready: Built-in web server for exposing flows as APIs
- 🔄 Flexible Flows: Sequential, parallel, and batch execution patterns
- 📦 Zero Dependencies: Minimal, focused dependencies for production use
- 🎯 Agent-Oriented: Perfect for AI agents, workflow automation, and data processing
📋 Table of Contents
- Quick Start
- Architecture
- Core Components
- Usage Examples
- HTTP Server
- Installation
- Performance
- Contributing
- License
⚡ Quick Start
Add RustyFlow to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
= { = "1.0", = ["derive"] }
= "1.0"
= "0.1"
Create your first flow:
use async_trait;
use ;
use ;
;
async
🏗️ Architecture
RustyFlow models AI workflows as a Graph + Async Execution:
graph TD
A[Input JSON] --> B[Node 1]
B --> C[Node 2]
C --> D[Node N]
D --> E[Output JSON]
F[Parallel Input] --> G[Node A]
F --> H[Node B]
F --> I[Node C]
G --> J[Merged Output]
H --> J
I --> J
K[Batch Input Array] --> L[Batch Node]
L --> M[Concurrent Processing]
M --> N[Array Output]
Core Abstractions
- Node: Basic computation unit with async execution
- Flow: Sequential orchestration of nodes
- ParallelFlow: Concurrent execution of multiple nodes
- Tool: Type-safe, structured computation with validation
- Batch: Concurrent processing of arrays
- Server: HTTP API exposure for flows
🔧 Core Components
Node
The fundamental building block for all computations:
Flow
Sequential execution pipeline:
let flow = new;
ParallelFlow
Concurrent execution with the same input:
let parallel_flow = new;
Type-Safe Tools
Structured input/output with compile-time validation:
;
Batch Processing
Concurrent processing of arrays:
let processor = new;
let batch_node = new;
let flow = new;
// Input: ["item1", "item2", "item3"]
// Output: ["item1_processed", "item2_processed", "item3_processed"]
📚 Usage Examples
Sequential Processing
use Flow;
async
Parallel Processing
use ParallelFlow;
async
Batch Processing
use Batch;
async
Type-Safe Tool Integration
use ToolNode;
async
🌐 HTTP Server
RustyFlow includes a built-in HTTP server for exposing flows as REST APIs:
use ;
use Flow;
async
API Usage
📦 Installation
Prerequisites
- Rust 1.80 or later
- Cargo package manager
Install from crates.io
Development Installation
Running Examples
# Sequential flow example
# Parallel processing example
# Batch processing example
# HTTP server example
⚡ Performance
RustyFlow leverages Rust's zero-cost abstractions and efficient async runtime:
| Metric | RustyFlow | Python PocketFlow |
|---|---|---|
| Memory Usage | ~2MB base | ~15MB base |
| Startup Time | ~10ms | ~100ms |
| Throughput | ~50K req/s | ~5K req/s |
| Concurrency | Native async | GIL-limited |
Benchmarks
Why Rust?
- Memory Safety: No segfaults, no memory leaks
- Fearless Concurrency: Safe parallel processing
- Zero-Cost Abstractions: High-level code, low-level performance
- Rich Type System: Catch errors at compile time
- Ecosystem: Excellent async and web ecosystem
🤝 Contributing
We welcome contributions! Please see our Contributing Guidelines.
Development Setup
Running Tests
🔧 Error Handling
RustyFlow uses structured error handling with detailed error messages:
📖 Documentation
🛣️ Roadmap
- GraphQL API support
- Built-in observability and metrics
- Visual flow designer
- Plugin system
- Distributed execution
- WASM support
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Inspired by the original Python PocketFlow
- Built with the amazing Rust ecosystem
- Thanks to all contributors and the Rust community