#artificial-intelligence #workflow-engine #llm #scenario #workflow #cosmoai

cosmoflow

CosmoFlow - A type-safe workflow engine for Rust, inspired by PocketFlow and optimized for LLM applications

6 releases (breaking)

Uses new Rust 2024

0.5.1 Jun 26, 2025
0.5.0 Jun 24, 2025
0.4.0 Jun 20, 2025
0.3.0 Jun 16, 2025
0.1.0 Jun 7, 2025

#478 in Database interfaces

Download history 111/week @ 2025-06-04 236/week @ 2025-06-11 213/week @ 2025-06-18 261/week @ 2025-06-25 5/week @ 2025-07-02

723 downloads per month

MIT license

250KB
3.5K SLoC

CosmoFlow

A lightweight, type-safe workflow engine for Rust, optimized for LLM applications.

CosmoFlow provides a minimal yet powerful framework for building complex workflows with clean abstractions and excellent performance. It is:

  • Lightweight: Minimal dependencies with optional features
  • Type-Safe: Full Rust type safety with async/await support
  • LLM-Optimized: Built-in patterns for AI/LLM workflows
  • Modular: Enable only what you need through feature flags

Crates.io MIT licensed Documentation

Guides | API Docs | Examples | Cookbook

Overview

CosmoFlow is a next-generation workflow engine that brings the elegant design philosophy of PocketFlow to the Rust ecosystem. Built from the ground up for LLM applications, high-performance scenarios, and production reliability. it provides a few major components:

  • A lightweight, async-based workflow scheduler.
  • Pluggable storage system (memory, file, Redis).
  • Asynchronous node execution with retry logic and error handling.

These components provide the runtime infrastructure necessary for building complex workflow applications.

Quick Start

Add to your Cargo.toml:

[dependencies]
cosmoflow = { version = "0.5.1", features = ["storage-memory"] }

Create your first workflow:

use cosmoflow::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create storage
    let mut store = MemoryStorage::new();
    
    // Build workflow  
    let mut flow = FlowBuilder::new()
        .node("start", MyNode::new())
        .terminal_route("start", "complete")
        .build();
    
    // Execute
    let result = flow.execute(&mut store).await?;
    println!("Workflow completed: {:?}", result);
    Ok(())
}

To see a list of the available features flags that can be enabled, check our docs.

Getting Help

First, see if the answer to your question can be found in the Guides or the API documentation. If the answer is not there, there is an active community in the CosmoFlow Discord server. We would be happy to try to answer your question. You can also ask your question on the discussions page.

Project Structure

This workspace contains:

Core Library

  • cosmoflow/ - The main CosmoFlow library with modular features
    • cosmoflow/examples/ - Simple feature demonstrations and basic usage patterns

Cookbook

  • cookbook/ - Production-ready examples and real-world solutions
    • chat-assistant/ - Complete chat assistant implementation
    • llm-request-handler/ - Efficient LLM request handling patterns
    • unified-workflow/ - Advanced workflow composition examples

Quick Start

Basic Examples (Learning):

cd cosmoflow/
cargo run --example hello_world_sync
cargo run --example simple_loops --features async

Production Examples (Real Use Cases):

cd cookbook/chat-assistant/
cargo run

cd cookbook/unified-workflow/
cargo run

Core Modules

CosmoFlow provides a focused set of core modules:

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in CosmoFlow by you, shall be licensed as MIT, without any additional terms or conditions.

Dependencies

~0.8–10MB
~105K SLoC