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.

9 min read • View on GitHub • More from the-pocket

A tiny mechanical core marked by three compact components sits inside a vast workshop crowded with tangled frameworks, dependency crates, and broken chains. A small drafting assistant studies the core like a blueprint while the surrounding machinery looms above it, showing the contrast between clarity and bloat.
PocketFlow’s pitch is not just small code. It is a small enough codebase that both humans and coding assistants can hold the whole design in working memory.
Key Takeaways

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.

The model is simple on paper, but the control boundary is the point. PocketFlow separates reading state, computing, and writing results, then uses actions to decide what happens next.

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 close-up machine has three chambers labeled prep, exec, and post. A ribbon of shared data enters prep, exec happens in an isolated sealed chamber, and post writes back to a ledger before flipping a switch that routes control into a loop. The image explains how PocketFlow separates data access, computation, and state mutation.
PocketFlow’s reliability story begins with a hard boundary between reading state, computing, and writing results.

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.

FrameworkPrimary abstractionCore philosophyBest fitTrade-off
PocketFlowGraph runtimeSmall core, AI-readable rulesDevelopers who want control and transparencyFewer batteries included
LangChainChains and toolsBroad ecosystem and integrationsTeams that want many ready-made piecesMore abstraction and weight
CrewAIAgents and rolesMulti-agent orchestrationCoordinated agent teamsMore opinionated structure
LangGraphGraphStateful graph orchestrationStructured agent workflows with cyclesHeavier than a tiny core
SmolAgentsAgentLightweight agent toolingSimple agent prototypesMore 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.