A minimalist LLM framework for building AI systems through human-AI collaboration. Implements agents, workflows, RAG, map-reduce patterns using a graph-based architecture with nodes, flows, and shared stores.
A 100-line minimalist LLM framework for building complex AI systems through human-AI collaboration. Supports Agents, Task Decomposition, RAG, Map-Reduce, and multi-agent patterns.
This framework models LLM workflows as **Graph + Shared Store**, enabling expressive AI systems with zero dependencies and vendor lock-in. The core principle: **Humans Design, Agents Code**.
The framework uses three fundamental abstractions:
1. **Node**: Handles simple LLM tasks with `prep()`, `exec()`, `post()` methods
2. **Flow**: Connects nodes through labeled edges (actions)
3. **Shared Store**: Data contract for inter-node communication (in-memory dict or database)
Additional patterns: **Batch** (data-intensive), **Async** (asynchronous tasks), **Parallel** (I/O-bound).
Follow this 8-step collaboration between human design and AI implementation:
Example flow 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]
```
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))
```
Example shared store:
```python
shared = {
"user": {
"id": "user123",
"context": {
"weather": {"temp": 72, "condition": "sunny"},
"location": "San Francisco"
}
},
"results": {}
}
```
- **Type**: Regular, Batch, or Async
- **prep()**: What data to read from shared store
- **exec()**: Which utility functions to call (NO exception handling)
- **post()**: What data to write to shared store
Example node specification:
Example node implementation:
```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:
```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:
```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()
```
- **Prompt Engineering**: Clear, specific instructions with examples
- **In-Context Learning**: Provide robust examples for hard-to-specify tasks
Organize your project as follows:
```
my_project/
├── main.py # Entry point
├── nodes.py # All node definitions
├── flow.py # Flow creation functions
├── utils/ # Utility functions (one file per API)
│ ├── __init__.py
│ ├── call_llm.py
│ └── search_web.py
├── requirements.txt
└── docs/
└── design.md # High-level, no-code documentation
```
1. **Start Simple**: Begin with minimal solutions, iterate rapidly
2. **Design First**: Always create high-level design in `docs/design.md` before implementation
3. **Fail Fast**: Use built-in retry mechanisms to identify weak points quickly
4. **Don't Repeat Yourself**: Use references/keys in shared store
5. **Frequent Feedback**: Ask humans for clarification and validation
6. **No Vendor Lock-in**: Implement your own utility wrappers for APIs
The framework supports these patterns out-of-box:
1. **If humans can't specify the flow, AI can't automate it** - Manually solve examples first
2. **Design utilities before flow** when integrating with legacy systems
3. **Avoid exception handling in utilities** - Let Node's retry mechanism manage failures
4. **Document everything** in `docs/design.md` at a high level
5. **Each utility should have a main() test function**
6. **Use intuition for quick evaluation** before building metrics
**Good for:**
**Not good for:**
You know you're succeeding when:
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/agentic-coding-framework/raw