explaingit

the-pocket/pocketflow

10,617PythonAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A tiny 100-line Python library for building AI agent workflows, connect steps into a graph where each step's output decides what runs next, with no vendor lock-in and no heavy dependencies.

Mindmap

mindmap
  root((PocketFlow))
    What it does
      Graph-based AI workflows
      Node transitions
      No vendor lock-in
    Patterns supported
      Chatbot with memory
      Web search agent
      Document pipeline
      Batch processing
    Tech
      Python core
      TypeScript port
      Java and Go ports
    Audience
      Developers
      AI app builders
    Setup
      pip install
      Or copy 100 lines
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a multi-step AI workflow that outlines, writes, and formats a document in sequential stages.

USE CASE 2

Create an AI agent that searches the web for real-time information before generating an answer.

USE CASE 3

Wire together a chatbot that maintains conversation history using a simple graph of nodes.

USE CASE 4

Process a large batch of files through an AI pipeline with multiple parallel or sequential steps.

Tech stack

PythonTypeScriptJavaGoRust

Getting it running

Difficulty · easy Time to first run · 30min

Needs an LLM API key (OpenAI, Anthropic, or any provider), PocketFlow installs in one pip command but does not bundle API client wrappers.

MIT license, use for any purpose including commercial, with no restrictions beyond keeping the copyright notice.

In plain English

PocketFlow is a minimalist Python library for building AI-powered applications that use large language models. Its entire core fits in exactly 100 lines of code, compared to popular alternatives that run into tens of thousands of lines and install hundreds of megabytes of dependencies. The library has no built-in wrappers for specific AI providers or cloud services, so you can connect it to whichever AI model or database you prefer. The central idea is that most AI application patterns, such as autonomous agents, multi-step workflows, and retrieval-augmented generation (a technique where an AI looks up relevant documents before answering), can all be expressed as graphs. A graph here just means a set of steps connected by transitions, where the output of one step decides which step runs next. PocketFlow gives you that graph structure and leaves everything else up to you. The project includes a cookbook of tutorial examples covering common use cases: a basic chatbot that remembers conversation history, an agent that searches the web to answer questions, a workflow that outlines then writes then formats a document, a system that processes a large batch of files, and more. Each example shows how to wire together nodes in a graph to accomplish real tasks. Installation is a single pip command, or you can just copy the 100-line source file directly into your project. The library is also available in TypeScript, Java, C++, Go, Rust, and PHP for teams working in other languages. Documentation and video tutorials are linked from the README. The intended audience is developers who want to build AI agent pipelines without adopting a large opinionated framework. It is MIT licensed and actively maintained with a Discord community.

Copy-paste prompts

Prompt 1
Using PocketFlow, write me a Python workflow that takes a topic, uses an LLM to outline it, then writes each section, then formats the result as markdown, show me the full node graph code.
Prompt 2
Show me how to build a web-search agent with PocketFlow: a node that calls a search API, passes results to an LLM node for summarization, and loops until the question is answered.
Prompt 3
I want to use PocketFlow with the Anthropic Claude API. Write me the connection code and a simple two-node graph that takes user input, calls Claude, and returns the response.
Prompt 4
How do I implement a retry-on-failure pattern in PocketFlow so that if an LLM node fails, the graph automatically retries up to 3 times before moving to a fallback node?
Prompt 5
Copy just the 100-line PocketFlow source into my project and build a batch processor that reads 50 files, summarizes each with an LLM, and writes results to a CSV.
Open on GitHub → Explain another repo

← the-pocket on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.