A Rust template project demonstrating how to build LLM applications using the PocketFlow framework in Rust with The-Pocket/PocketFlow-Rust.
This is a project template for Agentic Coding with Pocket Flow, a 100-line LLM framework, and your editor of choice.
-
We have included the Cursor rules, .clinerules, and .windsurfrules files to let Cursor AI (also Cline, or Windsurf) help you build LLM projects.
-
Want to learn how to build LLM projects with Agentic Coding?
-
Check out the Agentic Coding Guidance
-
Check out the YouTube Tutorial
-
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
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
-
Prerequisites
- Rust 1.70+ installed
- OpenAI API key
-
Setup
# Set your OpenAI API key export OPENAI_API_KEY="your-api-key-here" # Install dependencies cargo build
-
Run the application
cargo run
-
Follow the prompts
- Enter your question when prompted
- The system will process it through OpenAI's GPT-4o model
- Receive your AI-generated answer
- 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
- 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
- Modify the flow in
src/flow.rsto add more nodes or change connections - Add new nodes in
src/nodes.rsby implementing theNodetrait - Extend utilities in
src/utils/for additional external integrations - Update design in
docs/design.mdto document your changes
pocketflow-rs: Core framework for building LLM applicationstokio: Async runtimereqwest: HTTP client for API callsserde_json: JSON serialization/deserializationanyhow: Error handlingtracing: Structured logging
This template is provided as an example for building PocketFlow applications in Rust.