2.0 KiB
2.0 KiB
PocketFlow Project Template
This template provides a best-practice structure for PocketFlow projects.
Source: https://github.com/The-Pocket/PocketFlow-Template-Python
Project Structure
template/
├── main.py # Entry point
├── flow.py # Flow definition
├── nodes.py # Node implementations
├── utils.py # Utility functions (LLM wrappers, etc.)
└── requirements.txt # Python dependencies
Quick Start
-
Install dependencies:
pip install -r requirements.txt -
Configure your LLM: Edit
utils.pyand implementcall_llm()for your provider (OpenAI, Anthropic, or Gemini) -
Set API key:
export OPENAI_API_KEY=sk-... # or export ANTHROPIC_API_KEY=sk-ant-... # or export GEMINI_API_KEY=... -
Run:
python main.py
Customization
- Add nodes: Create new node classes in
nodes.py - Modify flow: Update connections in
flow.py - Add utilities: Implement helpers in
utils.py - Update logic: Customize
main.pyfor your use case
Best Practices Demonstrated
-
Separation of Concerns:
nodes.py- Node logic onlyflow.py- Flow orchestration onlyutils.py- Reusable utilitiesmain.py- Application entry point
-
Factory Pattern:
create_qa_flow()makes flow reusable- Easy to test and modify
-
Clear Data Flow:
- Shared store pattern for data passing
- Explicit state management
-
Configuration:
- Environment variables for API keys
- requirements.txt for dependencies
Next Steps
- Implement your
call_llm()function - Add your business logic to nodes
- Define your workflow in flow.py
- Run and iterate!
Resources
- PocketFlow Docs: https://the-pocket.github.io/PocketFlow/
- GitHub: https://github.com/The-Pocket/PocketFlow
- Examples: See the cookbook/ directory for more patterns