# PocketFlow Cookbook Guide Complete guide to the 47 real-world examples from the official PocketFlow cookbook. **Source:** https://github.com/The-Pocket/PocketFlow/tree/main/cookbook --- ## πŸ“š Included Examples (6 Complete Implementations) This skill includes 6 fully-functional cookbook examples in `assets/examples/`: ### 1. Chat Bot (β˜†β˜†β˜† Dummy) **File:** `01_chat.py` Interactive chat with conversation history. - Self-looping node for continuous interaction - Message history management - Graceful exit handling **Run it:** ```bash cd assets/examples/ python 01_chat.py ``` --- ### 2. Article Writing Workflow (β˜†β˜†β˜† Dummy) **File:** `02_workflow.py` Multi-step content creation pipeline. - Generate outline - Write draft - Refine and polish **Run it:** ```bash python 02_workflow.py "Your Topic Here" ``` --- ### 3. Research Agent (β˜†β˜†β˜† Dummy) **File:** `03_agent.py` Agent with web search and decision-making. - Dynamic action selection - Branching logic (search vs answer) - Iterative research loop **Run it:** ```bash python 03_agent.py "Who won the Nobel Prize 2024?" ``` --- ### 4. RAG System (β˜†β˜†β˜† Dummy) **File:** `04_rag.py` Complete retrieval-augmented generation. - Offline: Document embedding and indexing - Online: Query processing and answer generation - Context-based responses **Run it:** ```bash python 04_rag.py --"How to install PocketFlow?" ``` --- ### 5. Structured Output Parser (β˜†β˜†β˜† Dummy) **File:** `05_structured_output.py` Resume parser with YAML output. - Structured LLM responses - Schema validation - Skill matching with indexes **Run it:** ```bash python 05_structured_output.py ``` --- ### 6. Multi-Agent Game (β˜…β˜†β˜† Beginner) **File:** `06_multi_agent.py` Two async agents playing Taboo. - Async message queues - Inter-agent communication - Game logic with termination **Run it:** ```bash python 06_multi_agent.py ``` --- ## πŸ—ΊοΈ Full Cookbook Index (47 Examples) ### Dummy Level (β˜†β˜†β˜†) - Foundational Patterns | Example | Description | Included | |---------|-------------|----------| | **Chat** | Basic chat bot with history | βœ… `01_chat.py` | | **Structured Output** | Extract data with YAML | βœ… `05_structured_output.py` | | **Workflow** | Multi-step article writing | βœ… `02_workflow.py` | | **Agent** | Research agent with search | βœ… `03_agent.py` | | **RAG** | Simple retrieval-augmented generation | βœ… `04_rag.py` | | **Map-Reduce** | Batch processing pattern | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-mapreduce) | | **Streaming** | Real-time LLM streaming | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-streaming) | | **Chat Guardrail** | Travel advisor with filtering | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-chat-guardrail) | ### Beginner Level (β˜…β˜†β˜†) - Intermediate Patterns | Example | Description | Included | |---------|-------------|----------| | **Multi-Agent** | Async agents (Taboo game) | βœ… `06_multi_agent.py` | | **Supervisor** | Research supervision | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-supervisor) | | **Parallel (3x)** | 3x speedup with parallel | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-parallel) | | **Parallel (8x)** | 8x speedup demonstration | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-parallel-flow) | | **Thinking** | Chain-of-Thought reasoning | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-thinking) | | **Memory** | Short & long-term memory | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-memory) | | **MCP** | Model Context Protocol | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-mcp) | | **Tracing** | Execution visualization | πŸ“– [GitHub](https://github.com/The-Pocket/PocketFlow/tree/main/cookbook/pocketflow-tracing) | ### Additional Examples (47 total) Browse the complete cookbook on GitHub for all patterns including: **Core Patterns:** - Node basics, Communication, Batch operations (Node, Flow, Standard) - Async basics, Nested batches, Hello World, Majority vote **Integrations:** - FastAPI (background, HITL, WebSocket) - Gradio HITL, Streamlit, Google Calendar **Tools:** - Web crawler, Database, Embeddings, PDF Vision, Search **Advanced:** - Code generator, Text-to-SQL, Voice chat - A2A (Agent-to-Agent), Website chatbot **Full List:** https://github.com/The-Pocket/PocketFlow/tree/main/cookbook --- ## πŸŽ“ Learning Path ### Step 1: Start with Dummy Level 1. **01_chat.py** - Learn self-looping and state management 2. **02_workflow.py** - Understand sequential flows 3. **03_agent.py** - See branching and decision-making 4. **04_rag.py** - Multi-stage pipelines (offline + online) 5. **05_structured_output.py** - Structured LLM responses ### Step 2: Progress to Beginner Level 6. **06_multi_agent.py** - Async communication between agents ### Step 3: Explore GitHub Cookbook - Browse all 47 examples for advanced patterns - Find examples matching your use case - Study progressively more complex implementations --- ## πŸ’‘ How to Use These Examples ### Run Locally ```bash cd assets/examples/ # Make sure you have pocketflow installed pip install pocketflow # Run any example python 01_chat.py python 02_workflow.py "My Topic" python 03_agent.py "My Question" ``` ### Modify for Your Needs 1. Copy example to your project 2. Implement `call_llm()` in a utils.py file 3. Customize prompts and logic 4. Add your business requirements ### Learn Patterns - Study the code structure - See how nodes are connected - Understand shared store usage - Learn error handling approaches --- ## πŸ› οΈ Python Template Use the official Python template as your starting point: **Location:** `assets/template/` **Files:** - `main.py` - Entry point - `flow.py` - Flow definition - `nodes.py` - Node implementations - `utils.py` - LLM wrappers - `requirements.txt` - Dependencies **Quick Start:** ```bash cd assets/template/ pip install -r requirements.txt # Edit utils.py to add your LLM provider # Then run: python main.py ``` --- ## πŸ“– Additional Resources - **Official Docs:** https://the-pocket.github.io/PocketFlow/ - **GitHub Repo:** https://github.com/The-Pocket/PocketFlow - **Full Cookbook:** https://github.com/The-Pocket/PocketFlow/tree/main/cookbook - **Python Template:** https://github.com/The-Pocket/PocketFlow-Template-Python --- ## 🎯 Quick Reference: Which Example for What? | Need | Use Example | |------|-------------| | Interactive chat | `01_chat.py` | | Content generation pipeline | `02_workflow.py` | | Decision-making agent | `03_agent.py` | | Document Q&A | `04_rag.py` | | Parse/extract data | `05_structured_output.py` | | Multiple agents | `06_multi_agent.py` | | Batch processing | Map-Reduce (GitHub) | | Real-time streaming | Streaming (GitHub) | | Memory/context | Memory (GitHub) | | Parallel speedup | Parallel examples (GitHub) | --- ## βœ… Next Steps 1. **Pick an example** that matches your use case 2. **Run it** to see how it works 3. **Study the code** to understand patterns 4. **Copy and modify** for your project 5. **Implement** your LLM provider 6. **Iterate** and improve! --- *This guide covers the 6 included examples plus references to all 47 cookbook patterns. All examples are production-ready and demonstrate PocketFlow best practices.*