Build LLM systems using PocketFlow's graph-based framework. Guides AI agents through requirements, flow design, utilities, data schema, node implementation, and optimization for agents, RAG, workflows, and more.
Build LLM systems using PocketFlow's minimalist 100-line framework for Agents, Task Decomposition, RAG, and workflow automation.
This skill guides you through building LLM applications using PocketFlow's graph-based abstraction (Node + Flow + Shared Store). It emphasizes human-led design with AI-assisted implementation, following an 8-step methodology from requirements to reliability.
**PocketFlow models LLM workflows as Graph + Shared Store:**
**Human-AI Collaboration Philosophy:**
**Evaluate if an LLM system is appropriate:**
**Define user-centric problem:**
**Identify applicable design patterns:**
**Create high-level flow:**
**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 manually, AI agents can't automate it. Manually solve examples first to develop intuition.
**Define external utility functions (the "body" for the AI "brain"):**
**For each utility function:**
**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 called from Node's `exec()`. Let Node's retry mechanism handle failures.
**Design shared store (data contract between nodes):**
**Example shared store:**
```python
shared = {
"user": {
"id": "user123",
"context": {
"weather": {"temp": 72, "condition": "sunny"},
"location": "San Francisco"
}
},
"results": {}
}
```
**For each Node, specify:**
**Example node specification:**
**File structure:**
```
my_project/
├── main.py
├── nodes.py
├── flow.py
├── utils/
│ ├── __init__.py
│ ├── call_llm.py
│ └── search_web.py
├── requirements.txt
└── docs/
└── design.md
```
**Implementation guidelines:**
**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)
```
**Example main.py:**
```python
from flow import create_qa_flow
def main():
shared = {
"question": None,
"answer": None
}
qa_flow = create_qa_flow()
qa_flow.run(shared)
print(f"Question: {shared['question']}")
print(f"Answer: {shared['answer']}")
if __name__ == "__main__":
main()
```
**Initial evaluation:**
**Flow redesign (back to Step 3):**
**Micro-optimizations:**
**Expect iteration:** Repeat Steps 3–6 hundreds of times.
**Node-level reliability:**
**System-level reliability:**
**Agent:** Autonomous decision-making with context and available actions
**Workflow:** Sequential task chains with conditional branching
**RAG:** Offline indexing (embed documents) + online retrieval (similarity search)
**Map Reduce:** Split input → parallel processing → combine results
**Structured Output:** Format validation and schema enforcement
**Multi-Agent:** Multiple agents coordinating through shared store
**For legacy system automation:**
1. Design hardest utility interfaces first (bottleneck)
2. Build flow around available utilities
3. Fail fast to identify integration issues
**For RAG systems:**
1. Design offline indexing flow (chunk → embed → store)
2. Design online retrieval flow (query → search → rank)
3. Design generation flow (context + query → LLM → answer)
**For agentic workflows:**
1. Define context (what agent knows)
2. Define actions (what agent can do)
3. Design decision loop (observe → decide → act)
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-gcner3/raw