PocketFlow
also known as Pocket Flow
Type: full-code · Vendor: The Pocket · Language: Python · License: MIT · Status: active · Status in practice: emerging
Capture the core graph abstraction of LLM frameworks in 100 lines of zero-dependency Python so Agent, Multi-Agent, Workflow, and RAG patterns can be assembled on top.
Description. PocketFlow is a 100-line, zero-dependency minimalist LLM framework. Its only abstractions are Node (a small LLM/task unit) and Flow (which connects Nodes via labelled Actions); batch and async variants extend the same primitives. The Agent design pattern is realised by branching from a decision Node to one of several action Nodes and looping; the Multi-Agent pattern uses message queues in shared storage for peer-to-peer coordination. Workflow and RAG are documented as compositions of the same primitives.
Agent loop shape. Graph of Nodes connected by Action labels. A Node computes (often via an LLM call), returns an Action label, and the Flow uses that label to pick the next Node — enabling branching, looping, and agent-style 'decide-then-act'. Multi-agent coordination is implemented with asyncio.Queue message queues in shared storage; the framework explicitly does not ship a supervisor or scheduler abstraction.
Primary use cases
- learning the core graph abstraction behind LLM frameworks
- tiny tool-using agents with explicit action spaces
- peer-to-peer multi-agent message-queue prototypes
- lightweight workflow decompositions and RAG pipelines
Key concepts
- Node (docs) — Smallest unit of computation; handles a single (LLM) task.
- Flow (docs) — Connects Nodes through Actions (labelled edges); the basis of branching and looping.
- Agent design pattern → react (docs) — Branch from a decision Node to each action Node; let the agent direct flow between Nodes and loop back for multi-step.
- Multi-Agent message queues (docs) — Multi-agent coordination through asyncio.Queue message queues in shared storage; peer-to-peer rather than supervised.
- Batch / Async variants (docs) — Batch Nodes/Flows handle data-intensive tasks; Async Nodes/Flows wait for asynchronous tasks.
Patterns this full-code implements —
- ★★ReAct
The Agent design pattern wires a decision Node to action Nodes and loops back — the canonical decide-then-act ReAct shape, expressed in the framework's own minimal vocabulary.
- ★★Tool Use
Tools are modelled as action Nodes the agent chooses among; the framework names 'Action Space' design (parameterised actions, undo, chunked feeds) as a first-class concern.
- ★Inter-Agent Communication
Multi-agent coordination is documented as message queues in shared storage; this is the explicit communication mechanism between agents.
- ★★Pipes and Filters
Flow connects Nodes through labelled Actions; the core abstraction is a graph of small functional units.
- ★★Supervisor
Multi-agent coordination is peer-to-peer via message queues in shared storage; the Supervisor tutorial example is the closest first-class supervisor analogue.