PocketFlow: An LLM framework in ~100 lines of Python
Project Overview
The LLM framework landscape has become increasingly top-heavy, with tools like LangChain and CrewAI ballooning into complex ecosystems that often obscure their core functionality behind layers of abstraction. Pocket Flow takes a radically different approach, distilling the essence of an agentic framework into roughly 100 lines of Python. This isn’t just a stripped-down alternative; it’s a philosophical counterpoint. The project’s core insight is that the fundamental patterns of agentic workflows—chaining, branching, and state management—don’t require thousands of lines of code or vendor-specific wrappers. By keeping the core library minimal, Pocket Flow forces developers to engage directly with the architecture of their agents rather than configuring a framework’s opinionated abstractions. The project has gained significant traction with over 10,000 stars[1], suggesting that this contrarian bet on simplicity resonates with developers fatigued by the complexity of the existing ecosystem. The README’s comparison table is a deliberate provocation, highlighting how frameworks like LangGraph and AutoGen, despite their power, carry substantial dependency overhead that may be unnecessary for many use cases[2].
What It’s For
Pocket Flow is designed for developers who want to build custom agentic workflows without inheriting a framework’s entire dependency tree. It’s particularly well-suited for projects where the core logic is straightforward but the orchestration of multiple LLM calls, tool executions, and conditional branching requires a structured approach. The framework’s minimal surface area makes it ideal for learning and experimentation; you can understand the entire codebase in a single sitting, which is nearly impossible with larger frameworks. However, this minimalism comes with tradeoffs. Pocket Flow explicitly avoids the app-specific wrappers (like LangChain’s QA chains or document loaders) that make other frameworks more immediately productive for common tasks. If your project requires deep integration with vector stores, complex retrieval pipelines, or vendor-specific toolkits, you’ll be building those integrations yourself. The framework is best considered when the problem is simple enough to benefit from structure but not so complex that it demands the batteries-included approach of LangChain or the graph-based state management of LangGraph. It also has ports to TypeScript, Java, C++, Go, Rust, and PHP[3], which is notable for a project of this scale.
How to Use It
The core workflow revolves around defining Node subclasses that encapsulate discrete units of work, then composing them into a Flow that manages execution order and state passing. The Node class provides prep, exec, and post methods that form a consistent lifecycle for each step. This pattern is reminiscent of the chain-of-responsibility design pattern but adapted for asynchronous LLM calls. The framework’s state management is intentionally minimal—a shared dictionary passed between nodes—which means developers have full control over how state evolves but also full responsibility for handling concurrency and data consistency. The Flow class supports branching, retries, and batch processing without introducing new abstractions. The project’s documentation emphasizes building agents and multi-agent systems using this same node-flow pattern, demonstrating that complex behaviors emerge from simple composition rather than framework-level magic.
Install the framework via pip, or alternatively copy the single source file directly into your project for zero-dependency usage.
pip install pocketflow
Define a custom node by subclassing Node and implementing the exec method, which contains the core logic for that step in the workflow.
class MyNode(Node):
def exec(self, prep_res):
return call_llm(prep_res)
Compose nodes into a flow and execute it, with the framework handling the orchestration of node execution and state passing.
flow = Flow(start=MyNode())
flow.run()
Recent Updates
Latest Release: v0.0.0 (undefined)
Initial release establishing the minimal core framework with basic Node and Flow abstractions.
The project has seen rapid community growth with over 10,000 stars, and the ecosystem has expanded significantly with community ports to TypeScript, Java, C++, Go, Rust, and PHP. The documentation site and Discord community suggest active development beyond the core Python library, though the README provides limited visibility into recent commit activity or version history.
Sources & Attributions
[1] The repository has accumulated over 10,579 stars on GitHub. — The-Pocket/PocketFlow [2] Comparison table in README shows LangChain at 405K lines and +166MB, while Pocket Flow is 100 lines. — The-Pocket/PocketFlow#readme [3] Pocket Flow has official ports to multiple languages including TypeScript, Java, C++, Go, Rust, and PHP. — The-Pocket/PocketFlow#readme