π§ Rust Logic Graph
Current Version: 0.12.0
Reasoning Engine for Distributed Backend & AI Orchestration
A high-performance reasoning engine for distributed backend systems and AI orchestration. Build complex decision workflows, coordinate multiple services, and create intelligent agent systems with GRL (Grule Rule Language) support.
Not a no-code automation tool - Rust Logic Graph is an embeddable library for developers building distributed reasoning systems, not a UI-first workflow platform like n8n or Zapier.
π― What is Rust Logic Graph?
Rust Logic Graph is a reasoning engine library for building intelligent backend systems:
Core Capabilities
π§ Distributed Reasoning
- Connect decisions across multiple databases and services
- Build complex decision trees with business rules (GRL)
- Maintain context as data flows through your system
- Explain how decisions were reached
π€ AI Agent Orchestration
- Coordinate multiple LLMs in reasoning chains
- Build RAG (Retrieval-Augmented Generation) pipelines
- Create multi-agent systems with tool calling
- Native support for OpenAI, Claude, Ollama, and custom models
β‘ High-Performance Execution
- Sub-millisecond latency (embedded library, not service)
- Automatic parallel execution of independent operations
- Memory-efficient context pooling
- Async/await throughout
π§ Production-Ready Patterns
- Circuit breakers for unstable services
- Retry logic with exponential backoff
- Try/catch error handling
- Saga pattern for distributed transactions (v0.12.0)
β¨ Key Features
- π₯ GRL Support - rust-rule-engine v1.18.0-alpha with 50-100x faster parsing
- π Topological Execution - Automatic DAG-based node ordering
- β‘ Async Runtime - Built on Tokio for high concurrency
- β‘ Parallel Execution - Automatic parallel execution of independent nodes (v0.5.0)
- ποΈ Multi-Database Orchestration - Parallel queries, correlation, distributed transactions (v0.10.0) π
- πΎ Caching Layer - High-performance result caching with TTL, eviction policies, and memory limits (v0.5.0)
- π§ Memory Optimization - Context pooling and allocation tracking (v0.7.0)
- π οΈ CLI Developer Tools - Graph validation, dry-run, profiling, and visualization (v0.5.0)
- π¨ Web Graph Editor - Next.js visual editor with drag-and-drop interface (v0.8.0)
- π YAML Configuration - Declarative graph definitions with external config files (v0.8.5)
- π― Advanced Control Flow - Subgraphs, conditionals, loops, error handling (v0.9.0)
- π¨ Rich Error Messages - Unique error codes, actionable suggestions, full context (v0.10.0) π
- π Multiple Node Types - RuleNode, DBNode, AINode, ConditionalNode, LoopNode, TryCatchNode, RetryNode, CircuitBreakerNode
- π JSON/YAML Configuration - Simple workflow definitions
- π― 98% Drools Compatible - Easy migration from Java
- π Streaming Processing - Stream-based execution with backpressure (v0.3.0)
- ποΈ Database Integrations - PostgreSQL, MySQL, Redis, MongoDB (v0.2.0)
- π€ AI/LLM Integrations - OpenAI, Claude, Ollama (v0.2.0)
- π‘οΈ Saga Pattern - Distributed transaction coordinator, compensation, state persistence, timeout/deadline (v0.12.0)
- π E-commerce Saga Example - Real-world order flow with compensation and rollback (v0.12.0)
π Quick Start
Installation
[]
= "0.12.0"
# With specific integrations
= { = "0.12.0", = ["postgres", "openai"] }
# With all integrations
= { = "0.12.0", = ["all-integrations"] }
Example Use Cases
Saga Pattern (E-commerce order flow):
let mut saga = new;
saga.add_step;
// ... more steps (charge_payment, create_shipment, send_confirmation)
saga.execute?;
Financial risk assessment across multiple data sources
let risk_engine = new
.add_node
.add_node
.add_node
.add_node
.add_node;
Multi-step AI reasoning with tool calling
let ai_agent = new
.add_node
.add_node
.add_node
.add_node
.add_retry;
Microservice coordination with fault tolerance
let order_flow = new
.add_node
.add_node
.add_node
.add_circuit_breaker
.add_saga_compensation;
π Documentation
| Document | Description |
|---|---|
| οΏ½π’ Case Study: Purchasing Flow | Real production system with microservices & monolithic implementations |
| π YAML Configuration Guide | Declarative graph configuration with YAML (NEW in v0.8.5) |
| Graph Editor Guide | Visual web-based graph editor with Next.js (NEW in v0.8.0) |
| Memory Optimization Guide | Context pooling and allocation tracking (v0.7.0) |
| CLI Tool Guide | Developer tools for validation, profiling, and visualization (v0.5.0) |
| Cache Guide | Caching layer with TTL and eviction policies (v0.5.0) |
| Migration Guide | Upgrade guide to v0.14.0 with RETE-UL (v0.5.0) |
| Integrations Guide | Database & AI integrations (v0.2.0) |
| GRL Guide | Complete GRL syntax and examples |
| Use Cases | 33+ real-world applications |
| Extending | Create custom nodes and integrations |
| Implementation | Technical details |
π― Use Cases
Rust Logic Graph powers applications in:
- π° Finance - Loan approval, fraud detection, risk assessment
- π E-commerce - Dynamic pricing, recommendations, fulfillment
- π₯ Healthcare - Patient triage, clinical decisions, monitoring
- π Manufacturing - Predictive maintenance, QC automation
- π‘οΈ Insurance - Claims processing, underwriting
- π Marketing - Lead scoring, campaign optimization
- βοΈ Compliance - AML monitoring, GDPR automation
ποΈ Architecture Patterns
Pattern 1: Multi-Database Reasoning
Query multiple databases, apply business rules, make decisions:
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β PostgreSQL βββββΆβ MongoDB βββββΆβ Redis β
β (Users) β β (Analytics) β β (Cache) β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β β β
βββββββββββββββββββββ΄ββββββββββββββββββββ
β
βββββββββΌββββββββ
β Rule Engine βββββ GRL Rules
β (Decision) β
βββββββββ¬ββββββββ
β
βββββββββΌββββββββ
β Actions β
βββββββββββββββββ
Pattern 2: AI Agent with Tools
LLM orchestration with tool calling and validation:
βββββββββββββββ
β User Query β
ββββββββ¬βββββββ
β
ββββββββΌβββββββββββ
β LLM (Claude) ββββββββ
β Understand β β
ββββββββ¬βββββββββββ β
β Tool Calls
ββββββββΌβββββββββββ β
β RAG Subgraph ββββββββ€
β (Vector Search) β β
ββββββββ¬βββββββββββ β
β βββββΌβββββββ
ββββββββΌβββββββββββ β Database β
β LLM (GPT-4) ββββ€ Query β
β Reason β ββββββββββββ
ββββββββ¬βββββββββββ
β
ββββββββΌβββββββββββ
β Validate (GRL) β
β Business Rules β
ββββββββ¬βββββββββββ
β
ββββββββΌβββββββββββ
β Response β
βββββββββββββββββββ
Pattern 3: Saga Pattern for Distributed Transactions
Coordinate microservices with compensation logic:
Order Service βββΆ Inventory Service βββΆ Payment Service βββΆ Shipping Service
β β β β
Success Success Success Success
β β β β
βββββββββββββββββββββ΄βββββββββββββββββββββ΄βββββββββββββββββββββ
β
ββββββββΌβββββββ
β Complete β
βββββββββββββββ
If Payment Fails:
β β β
β β Compensation
β ββββββββββββββββββββββ
β Release Inventory
βββββββββββββββββββββ
Cancel Order
View 6 complete architecture patterns β
ποΈ System Architecture

π₯ GRL Example
rule "HighValueLoan" salience 100 {
when
loan_amount > 100000 &&
credit_score < 750
then
requires_manual_review = true;
approval_tier = "senior";
}
rule "AutoApproval" salience 50 {
when
credit_score >= 700 &&
income >= loan_amount * 3 &&
debt_ratio < 0.4
then
auto_approve = true;
interest_rate = 3.5;
}
π Performance
GRL Parsing Benchmark (v1.18.0-alpha)
| Benchmark | v1.18.0-alpha | v1.3.0 | Speedup |
|---|---|---|---|
| Simple Rule (1 rule) | 2.95 Β΅s | 298 Β΅s | 101x faster |
| Complex Rule (1 rule) | 10.27 Β΅s | 305 Β΅s | 30x faster |
| Purchasing Rules (11 rules) | 71.6 Β΅s | 3,500 Β΅s | 49x faster |
| Rule Execution (11 rules) | 32.66 Β΅s | - | - |
Graph Execution Benchmark (vs dagrs)
| Chain Size | rust-logic-graph | dagrs | Speedup |
|---|---|---|---|
| 5 nodes | 271 Β΅s | 1.7 ms | 6.3x faster |
| 10 nodes | 526 Β΅s | 1.8 ms | 3.5x faster |
| 20 nodes | 996 Β΅s | 2.1 ms | 2.1x faster |
Key Performance Features
- RETE-UL Algorithm: Advanced pattern matching with unlinking
- No-Regex Parser: v1.18.0-alpha uses hand-written parser (50-100x faster)
- 98% Drools Compatible: Easy migration path
- Async by Default: High concurrency support
- Parallel Execution: Automatic layer-based parallelism
- Smart Caching: Result caching with TTL and eviction policies
π§ͺ Testing & CLI Tools
# Run all tests
# Build CLI tool (YAML-only support)
# Validate graph
# Visualize graph structure
# Profile performance
# Dry-run execution
Test Results: β
74/74 tests passing
CLI Format: YAML only (.yaml or .yml files)
Learn more about CLI tools β
π¦ Project Status
Version: 0.11.0 (Latest) Status: Production-ready with YAML-driven multi-database orchestration
What's Working
- β Core graph execution engine
- β RETE-UL algorithm (v0.14.0) - 2-24x faster
- β Three node types (Rule, DB, AI)
- β Topological sorting
- β Async execution
- β JSON I/O
- β Database integrations (PostgreSQL, MySQL, Redis, MongoDB)
- β AI integrations (OpenAI, Claude, Ollama)
- β Streaming processing with backpressure and chunking
- β Parallel execution with automatic layer detection
- β Caching layer with TTL, eviction policies, memory limits (v0.5.0)
- β Memory optimization with context pooling (v0.7.0)
- β CLI Developer Tools - validate, profile, visualize, dry-run (v0.5.0)
- β Web Graph Editor - Next.js visual editor with drag-and-drop (v0.8.0)
- β Production Case Study - Purchasing flow with microservices & monolithic (v0.8.0)
- β YAML Configuration - Declarative graph definitions (v0.8.5)
- β Distributed Context Sharing - MessagePack serialization, shared context, versioning and stores (InMemory/Redis) (v0.11.0)
- π‘οΈ β Fault Tolerance - Circuit breakers, health monitoring, failover, graceful degradation (v0.11.0)
- β Stream operators (map, filter, fold)
- β Comprehensive documentation
Roadmap
- Streaming processing (v0.3.0) - COMPLETED β
- Parallel node execution (v0.4.0) - COMPLETED β
- Caching layer (v0.5.0) - COMPLETED β
- CLI Developer Tools (v0.5.0) - COMPLETED β
- RETE-UL upgrade (v0.5.0) - COMPLETED β
- Memory Optimization (v0.7.0) - COMPLETED β
- Web Graph Editor (v0.8.0) - COMPLETED β
- Production Case Study (v0.8.0) - COMPLETED β
- YAML Configuration (v0.8.5) - COMPLETED β
- GraphQL API (v0.9.0)
- Production release (v1.0.0)
See ROADMAP.md for details
π€ Contributing
Contributions welcome! Please:
- Fork the repository
- Create your feature branch
- Write tests for new features
- Submit a pull request
π Examples
Core Examples
| Example | Description | Lines |
|---|---|---|
simple_flow.rs |
Basic 3-node pipeline | 36 |
advanced_flow.rs |
Complex 6-node workflow | 120 |
grl_rules.rs |
GRL rule examples | 110 |
grl_graph_flow.rs |
GRL + Graph integration | 140 |
postgres_flow.rs |
PostgreSQL integration | 100 |
openai_flow.rs |
OpenAI GPT integration | 150 |
streaming_flow.rs |
Streaming with backpressure | 200 |
parallel_execution.rs |
Parallel node execution | 250 |
Advanced Control Flow Examples (v0.9.0) π
| Example | Description | Features Demonstrated |
|---|---|---|
conditional_flow.rs |
If/else routing based on conditions | ConditionalNode, branch selection |
loop_flow.rs |
Foreach and while loop patterns | LoopNode, iteration over arrays |
retry_flow.rs |
Exponential backoff retry logic | RetryNode, configurable attempts |
error_handling_flow.rs |
Try/catch/finally patterns | TryCatchNode, error recovery |
circuit_breaker_flow.rs |
Circuit breaker fault tolerance | CircuitBreakerNode, failure thresholds |
subgraph_flow.rs |
Nested graph execution | SubgraphNode, input/output mapping |
Multi-Database Orchestration (v0.10.0) π
| Example | Description | Features Demonstrated |
|---|---|---|
real_multi_db_orchestration.rs |
Query multiple databases in parallel with real data | ParallelDBExecutor, QueryCorrelator, DistributedTransaction |
Demo 1: Parallel Queries - Execute queries across 4 databases concurrently
Demo 2: Query Correlation - JOIN results from different databases (Inner/Left/Right/Full)
Demo 3: Distributed Transactions - Two-Phase Commit (2PC) for atomic operations
use ;
// Execute queries in parallel across multiple databases
let mut executor = new;
executor
.add_query
.add_query;
let results = executor.execute_all.await?;
// Correlate results with SQL-like JOINs
let correlator = new;
let joined = correlator.join?;
Run examples:
# Conditional routing
# Loop over products
# Retry with backoff
# Error handling
# Circuit breaker
# Nested subgraphs
# Rich error messages (v0.10.0) π
# Multi-database orchestration (v0.10.0) π
Error Handling (v0.10.0) π
Production-grade error messages with unique codes, actionable suggestions, and full context:
use ;
// Rich error with context
let err = database_connection_error.with_context;
// Output:
// [E002] Failed to connect to PostgreSQL
// Graph: order_processing
// Node: fetch_orders
// database: orders_db
//
// π‘ Suggestion: Verify database connection string, credentials,
// and network connectivity.
// π Documentation: https://docs.rust-logic-graph.dev/errors/E002
// Automatic retry strategy
if err.is_retryable
12 Error Types: Node execution (E001), Database (E002), Rules (E003), Config (E004), Timeout (E005), Validation (E006), Serialization (E007), AI (E008), Cache (E009), Context (E010), Distributed (E011), Transaction (E012)
See docs/ERRORS.md for complete error reference
CLI Tool Examples (v0.5.0)
| File | Description |
|---|---|
examples/sample_graph.yaml |
Linear workflow with 5 nodes |
examples/cyclic_graph.yaml |
Graph with cycle for testing |
examples/sample_context.yaml |
Sample input data |
See CLI_TOOL.md for usage examples
π What Makes Rust Logic Graph Unique?
π§ Reasoning-First Architecture
Traditional workflow engines execute tasks. Rust Logic Graph reasons through decisions:
- Business Rule Engine - GRL integration for complex decision logic
- Context-Aware Execution - Decisions based on accumulated knowledge
- Multi-Step Reasoning - Chain decisions across multiple nodes
- Explainable Decisions - Trace how conclusions were reached
π Built for Distributed Systems
Not a monolithic workflow runner - designed for microservices from day one:
- Multi-Database Orchestration - Query PostgreSQL, MySQL, MongoDB, Redis in one flow
- Service Coordination - Orchestrate gRPC, REST, and internal services
- Fault Tolerance - Circuit breakers, retries, saga patterns
- Distributed Context - Share state across services seamlessly
π€ AI-Native Orchestration
LLMs are first-class citizens, not afterthoughts:
- Multi-Model Workflows - Combine OpenAI, Claude, Ollama in one reasoning chain
- RAG Pipeline Ready - Vector DB integration, embedding generation
- Agent Coordination - Build multi-agent systems with shared context
- Tool Calling Framework - LLMs can invoke graph nodes as tools
β‘ Performance Without Compromise
Embedded library architecture means zero network overhead:
- Sub-Millisecond Latency - Direct function calls, not HTTP
- Memory Efficient - Context pooling, zero-copy where possible
- Parallel by Default - Automatic detection of independent operations
- Async Everything - Built on Tokio for maximum concurrency
π§ Developer Experience
Designed for developers who write code, not click buttons:
- Type-Safe - Rust's type system catches errors at compile time
- YAML + Code - Declarative when possible, programmatic when needed
- Embeddable - Library, not service - runs in your process
- Testable - Unit test your workflows like any other code
π License
MIT License - see LICENSE for details.
π Links
- Repository: https://github.com/KSD-CO/rust-logic-graph
- rust-rule-engine: https://crates.io/crates/rust-rule-engine
- Documentation: docs/
- Issues: GitHub Issues
π₯ Authors
James Vu - Initial work
π Acknowledgments
Built with:
- rust-rule-engine v1.18.0-alpha - GRL support with no-regex parser (50-100x faster)
- Tokio - Async runtime
- Petgraph - Graph algorithms
- Serde - Serialization
- Clap - CLI framework
β Star us on GitHub if you find this useful! β
Documentation β’ Examples β’ Use Cases β’ YAML Config Guide