Pocket Flow Python Project Template
repository·main·Indexed 18 days ago
https://github.com/the-pocket/pocketflow-template-pythonA project template for Agentic Coding using the Pocket Flow LLM framework. It includes configuration rules for AI coding assistants such as Cursor, Cline, Windsurf, Goose, Claude Code, Gemini, and GitHub Copilot. The template provides a structured design process for building agentic workflows using Flow Design, Node Design (Regular, Batch, and Async execution types), and a Shared Store for node communication.
What's inside pocketflow-template-python
- This project is a template designed for Agentic Coding using Pocket Flow, a lightweight (100-line) LLM framework. It provides a pre-configured environment to build LLM-based applications using various AI coding assistants and editors.
Design a workflow using Flow Design and Node Design
mainWhen building an agentic workflow in this template, you should follow a structured design process involving three main layers:
- Flow Design: Define the high-level workflow and applicable design patterns (e.g., Map-Reduce, RAG, Agentic workflows). Use Mermaid diagrams to visualize the sequence of nodes.
- Utility Functions: Identify or define reusable functions (like LLM calls or embeddings) that nodes will consume.
- Node Design: Define individual nodes, specifying their purpose, execution type (Regular, Batch, or Async), and their interaction with the Shared Store.
Each node follows a lifecycle of
prep(reading from the shared store),exec(performing the core logic/utility call), andpost(writing results back to the shared store).Define Node execution types
mainWhen designing a node, you must choose the appropriate execution type based on the workload:
- Regular: Standard sequential execution.
- Batch: For processing multiple items at once.
- Async: For non-blocking or concurrent operations.
Use the Shared Store for node communication
mainThe
sharedstore is a centralized dictionary used to pass data between nodes in a flow. To minimize redundancy, nodes should read necessary inputs during theirprepstep and write their outputs during theirpoststep.Example structure:
shared = { "key": "value" }Configure AI coding assistants with rule files
mainThe template includes specialized rule files to optimize the performance of different AI coding assistants. To use these, ensure the corresponding file exists in your project root so the assistant can follow the project-specific instructions:
- Cursor AI: Uses
.cursorrules - Cline: Uses
.clinerules - Windsurf: Uses
.windsurfrules - Goose: Uses
.goosehints - Claude Code: Uses
CLAUDE.md - Gemini: Uses
GEMINI.md - GitHub Copilot: Uses configuration located in the
.githubdirectory.
- Cursor AI: Uses
Run an agentic flow with create_qa_flow()
mainTo build a QA application, use
create_qa_flow()to instantiate a flow and then call.run(shared)passing a dictionary containing the input state. Theshareddictionary acts as the state container that is mutated by the flow during execution. For a QA flow, the dictionary should include aquestionkey (string) and ananswerkey (initialized toNone).from flow import create_qa_flow # Define the shared state shared = { "question": "In one sentence, what's the end of universe?", "answer": None } # Initialize and execute the flow qa_flow = create_qa_flow() qa_flow.run(shared) # Access the mutated state print("Question:", shared["question"]) print("Answer:", shared["answer"])