Build LLM systems using PocketFlow's minimalist graph-based framework. Humans design high-level flows, AI agents implement nodes and utilities. Covers requirements, flow design, utilities, data schemas, and reliability patterns.
Build LLM systems using PocketFlow's 100-line minimalist framework. This skill guides you through collaborative development where humans design high-level system flows and AI agents implement the detailed code.
PocketFlow models LLM workflows as **Graph + Shared Store**: Nodes handle simple tasks, Flows connect nodes through labeled edges (actions), and a Shared Store enables communication between nodes.
**Core principle**: Humans understand requirements and design flows; AI agents implement nodes, utilities, and handle reliability.
Follow these steps in order. Always start simple and iterate frequently.
**Human-led, AI supports**
- ✅ Good for: Routine tasks with common sense (form filling, email replies), creative tasks with defined inputs (slides, SQL)
- ❌ Not good for: Ambiguous problems requiring complex decisions (business strategy)
**AI agent tasks:**
**Collaborative design phase**
**Pattern-specific details:**
**AI agent tasks:**
**Example Mermaid diagram:**
```mermaid
flowchart LR
start[Start] --> batch[Batch]
batch --> check[Check]
check -->|OK| process
check -->|Error| fix[Fix]
fix --> check
subgraph process[Process]
step1[Step 1] --> step2[Step 2]
end
process --> endNode[End]
```
**Critical rule**: If humans can't specify the flow, AI agents can't automate it. Manually solve example inputs first to develop intuition.
**Collaborative implementation**
- Reading inputs (Slack messages, emails)
- Writing outputs (reports, emails)
- Using external tools (LLMs, web search)
**For each utility:**
**Example utility:**
```python
from openai import OpenAI
def call_llm(prompt):
client = OpenAI(api_key="YOUR_API_KEY_HERE")
r = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": prompt}]
)
return r.choices[0].message.content
if __name__ == "__main__":
prompt = "What is the meaning of life?"
print(call_llm(prompt))
```
**Important**: Avoid exception handling in utilities. Let Node's built-in retry mechanism handle failures.
**AI agent tasks:**
**AI-led, human verifies**
**Example shared store:**
```python
shared = {
"user": {
"id": "user123",
"context": {
"weather": {"temp": 72, "condition": "sunny"},
"location": "San Francisco"
}
},
"results": {}
}
```
**AI agent tasks:**
**AI-led, human reviews**
For each Node, specify:
**Example node specification:**
**AI agent tasks:**
**AI-led, human provides feedback**
Now implement nodes and flows based on the design.
**Principles:**
**File structure:**
```
my_project/
├── main.py # Entry point
├── nodes.py # Node definitions
├── flow.py # Flow creation functions
├── utils/ # Utility functions
│ ├── __init__.py
│ ├── call_llm.py
│ └── search_web.py
├── requirements.txt
└── docs/
└── design.md # High-level design documentation
```
**Example nodes.py:**
```python
from pocketflow import Node
from utils.call_llm import call_llm
class GetQuestionNode(Node):
def exec(self, _):
user_question = input("Enter your question: ")
return user_question
def post(self, shared, prep_res, exec_res):
shared["question"] = exec_res
return "default"
class AnswerNode(Node):
def prep(self, shared):
return shared["question"]
def exec(self, question):
return call_llm(question)
def post(self, shared, prep_res, exec_res):
shared["answer"] = exec_res
```
**Example flow.py:**
```python
from pocketflow import Flow
from nodes import GetQuestionNode, AnswerNode
def create_qa_flow():
get_question_node = GetQuestionNode()
answer_node = AnswerNode()
get_question_node >> answer_node
return Flow(start=get_question_node)
```
**AI agent tasks:**
**Collaborative iteration**
- Prompt engineering: Clear, specific instructions with examples
- In-Context Learning: Provide robust examples for difficult-to-specify tasks
**Expect hundreds of iterations through Steps 3-6!**
**AI agent tasks:**
**AI-led, human validates**
**AI agent tasks:**
1. **Design utilities before flow** if interfacing with legacy systems is the bottleneck
2. **No exception handling in utilities** called from Node.exec()—let Node retry mechanism handle it
3. **Keep docs/design.md high-level and no-code**—focus on what, not how
4. **One Python file per API call** in utils/ directory
5. **Include main() test function** in each utility file
6. **Start simple, iterate frequently**—avoid premature optimization
7. **Fail fast with Node retries**—quickly identify weak points
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/agentic-coding-with-pocketflow/raw