PocketFlow: The 100-Line LLM Framework Built for Humans and AI Coders
A minimalist graph engine, a state machine with loops, and a documentation layer that turns Cursor into a collaborator instead of a passenger.
- PocketFlow treats framework design as a collaboration contract, not just an API surface.
- Its real innovation is a tiny core paired with rules that AI coding assistants can reliably follow.
- The prep, exec, post lifecycle isolates state access from computation, which makes retries and branching easier to reason about.
- A Flow can act like a Node, so the system behaves like a state machine instead of a simple chain runner.
PocketFlow is not trying to win by breadth. It is trying to win by being small enough that the whole system fits in your head, and in the context window of the assistant helping you write it. That is a different bet from the usual LLM framework race, where more integrations often mean more surface area for failure.
After a year of struggling with bloated frameworks, I decided to strip away anything unnecessary. The result is Pocket Flow, a minimalist LLM framework in just 100 lines of code.
Why PocketFlow Exists
The origin story starts with frustration, but the real complaint is deeper than dependency bloat. PocketFlow was shaped around a simple idea: if an AI assistant is going to implement and extend workflows, the framework should be easy for that assistant to read without guessing.
That pushes the project toward restraint. No vendor wrapper jungle. No sprawling utility stack. Just enough machinery to express control flow, shared state, and retries without hiding the logic inside layers of abstraction.
The Core Idea Is Smaller Than the Category
PocketFlow’s runtime is built from three primitives: Node, Flow, and Batch. The important part is not that they exist. It is that they stay close to the metal, with almost no extra framework opinion baked in.
class Node:
def prep(self, shared):
return shared.get("input")
def exec(self, prep_res):
return self.run(prep_res)
def post(self, shared, prep_res, exec_res):
shared["result"] = exec_res
return "next"
That split matters because it keeps the expensive, failure-prone part of the node away from shared state. In practice, that makes retries and testing much cleaner. If exec is pure, the framework can rerun it without worrying that the node already mutated the world.
A Flow Is Also a Node
This is where PocketFlow stops feeling like a chain runner and starts feeling like a real state machine. A flow can contain nodes, and a flow can also be treated like a node inside a larger flow. That recursive shape is what makes nesting clean instead of awkward.
Actions are the second half of that design. A node does not just finish and hand off blindly. It can return a named action, and that action can send execution to a different branch, revisit an earlier step, or keep the search going until the workflow resolves.
| Framework | Primary abstraction | Core philosophy | Best fit | Trade-off |
|---|---|---|---|---|
| PocketFlow | Graph runtime | Small core, AI-readable rules | Developers who want control and transparency | Fewer batteries included |
| LangChain | Chains and tools | Broad ecosystem and integrations | Teams that want many ready-made pieces | More abstraction and weight |
| CrewAI | Agents and roles | Multi-agent orchestration | Coordinated agent teams | More opinionated structure |
| LangGraph | Graph | Stateful graph orchestration | Structured agent workflows with cycles | Heavier than a tiny core |
| SmolAgents | Agent | Lightweight agent tooling | Simple agent prototypes | More ecosystem-shaped than PocketFlow |
The comparison is not really about size alone. It is about what the framework asks you to trust. PocketFlow asks you to trust the control model you can see. Bigger frameworks ask you to trust the system around the control model.
The Hidden Product Is the .cursor/rules Layer
The cleverest part of PocketFlow may be the least visible one. The repository does not just contain code. It contains instructions for how an AI assistant should work with that code. The rules layer turns the repo into a collaboration contract.
That changes the role of documentation. It stops being a passive reference and becomes a guide for implementation choices, reliability patterns, and code organization. For agentic coding, that is a stronger product than another abstraction layer.
After a year of building LLM applications from scratch, I had a revelation: beneath all the complexity, LLM systems are fundamentally just simple directed graphs.
What PocketFlow Suggests About the Next Wave of Agent Tools
PocketFlow is not a full platform, and that is the point. It is a constraint system for people who want to own the execution model and let the assistant help fill in the edges. That makes it feel less like a framework marketplace and more like a disciplined design for collaboration.
The larger lesson is simple. In the next wave of agent tools, legibility may matter more than breadth. A small core with strong conventions can be easier to extend, safer to retry, and more honest about what the framework actually does.





