PocketFlow Rust Template

A Rust template project demonstrating how to build LLM applications using the PocketFlow framework in Rust with The-Pocket/PocketFlow-Rust.

PocketFlow Rust Project Template: Agentic Coding

This is a project template for Agentic Coding with Pocket Flow, a 100-line LLM framework, and your editor of choice.

Overview

This template implements a simple Question-Answering system that showcases the core PocketFlow concepts in Rust:

  • Nodes: Modular components that handle specific tasks
  • Flows: Orchestration of nodes through directed graphs
  • Context: Shared state management between nodes
  • Async/Await: Full async support for I/O operations

Project Structure

src/
├── main.rs          # Application entry point
├── flow.rs          # Flow definitions and connections
├── nodes.rs         # Node implementations
└── utils/
    ├── mod.rs       # Utilities module
    └── call_llm.rs  # OpenAI API client
docs/
└── design.md        # High-level design documentation
Cargo.toml           # Dependencies and project configuration

Quick Start

  1. Prerequisites

    • Rust 1.70+ installed
    • OpenAI API key
  2. Setup

    # Set your OpenAI API key
    export OPENAI_API_KEY="your-api-key-here"
    
    # Install dependencies
    cargo build
  3. Run the application

    cargo run
  4. Follow the prompts

    • Enter your question when prompted
    • The system will process it through OpenAI's GPT-4o model
    • Receive your AI-generated answer

Key Features

Rust-Specific Advantages

  • Memory Safety: Zero-cost abstractions with compile-time guarantees
  • Async Performance: Efficient async/await with Tokio runtime
  • Type Safety: Strong typing prevents runtime errors
  • Error Handling: Comprehensive error management with anyhow

PocketFlow Integration

  • Modular Design: Clean separation between nodes, flows, and utilities
  • State Management: Context-based shared state between nodes
  • Flow Control: Declarative flow definition using macros
  • Extensibility: Easy to add new nodes and flows

Customization

  1. Modify the flow in src/flow.rs to add more nodes or change connections
  2. Add new nodes in src/nodes.rs by implementing the Node trait
  3. Extend utilities in src/utils/ for additional external integrations
  4. Update design in docs/design.md to document your changes

Dependencies

  • pocketflow-rs: Core framework for building LLM applications
  • tokio: Async runtime
  • reqwest: HTTP client for API calls
  • serde_json: JSON serialization/deserialization
  • anyhow: Error handling
  • tracing: Structured logging

License

This template is provided as an example for building PocketFlow applications in Rust.