pocketflow
Use PocketFlow, a tiny Python graph framework for LLM applications, agents, workflows, RAG, batch processing, async orchestration, and supporting utilities.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- pocketflow
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use PocketFlow, a tiny Python graph framework for LLM applications, agents, workflows, RAG, batch processing, async orchestration, and supporting utilities.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/repo-provenance.md3.2 KB
- 参考文档references/repo-routing-metadata.json502 B
- 参考文档references/troubleshooting.md3.3 KB
- 脚本scripts/check_pocketflow_install.py2.9 KB
03 SKILL.md 正文
PocketFlow Repo Skill
Use this skill when a task asks to build, debug, review, or explain a PocketFlow application or to translate an LLM-system design into PocketFlow nodes and flows. PocketFlow is intentionally minimal: the installed package exposes a compact graph runtime with no built-in LLM provider, vector database, search, UI, audio, or tracing integration. Those integrations live in user utilities that PocketFlow nodes call.
Fast recognition
Read this skill when the user mentions any of these signals:
pocketflow,Pocket Flow, or a 100-line LLM framework.Node,Flow,BatchNode,BatchFlow,AsyncNode,AsyncFlow,AsyncParallelBatchNode, orAsyncParallelBatchFlowin a graph-orchestration context.- A Python LLM app with
prep -> exec -> post, a shared dictionary, action strings, graph transitions, ornode - "action" >> other_nodesyntax. - Building lightweight agents, RAG, map-reduce, structured-output, streaming, FastAPI background jobs, voice/chat workflows, or coding-agent loops without a large framework.
Minimal install and import check
pip install pocketflow
python - <<'PY'
from pocketflow import Node, Flow
class Start(Node):
def prep(self, shared):
shared["seen"] = True
start = Start()
Flow(start=start).run({})
print("pocketflow import ok")
PY
For development from source, an editable install is also valid. The public package version captured for this skill is 0.0.3; see repo provenance for the source snapshot.
Route by task
| If the task is about... | Read |
|---|---|
Public runtime classes, prep/exec/post, transitions, retries, fallback, nested flows, sync/async, batch/parallel behavior, or unit-test-like API debugging |
core-abstraction |
| Designing an LLM app architecture, deciding between workflow/agent/RAG/map-reduce/structured-output/multi-agent patterns, or using cookbook-style recipes | design-patterns |
| Implementing provider wrappers, search/embedding/vector/TTS/database utilities, graph visualization, logging/tracing, chunking, streaming, or external dependency safety | utilities |
| Cross-cutting install/import/provider/config mistakes before choosing a sub-skill | troubleshooting |
| Router placement, source snapshot, or staleness checks | repo provenance and routing metadata |
PocketFlow mental model
- A node has three optional phases.
prep(shared)reads and prepares data,exec(prep_res)performs compute and is the only phase retried, andpost(shared, prep_res, exec_res)writes results and returns the next action. - A flow follows action strings.
a >> bis the default transition.a - "search" >> bis a named transition. Ifpost()returnsNone, PocketFlow looks for the default successor. - The shared store is the durable data contract. Most task state should be in a user-designed dictionary or persistence layer. Nodes communicate by reading/writing it.
- Params are per-run identifiers.
BatchFlow.prep()returns parameter dictionaries; child nodes read them fromself.params. Do not use params as mutable shared state. - PocketFlow is not an integration framework. LLM calls, embeddings, vector search, DB queries, speech, UI, and observability are ordinary utility functions invoked by nodes.
- Start simple. For a new LLM system, write a short design document first, then implement utilities, shared-store schema, nodes, and flows.
Common safe checks
- Run scripts/check_pocketflow_install.py to confirm import, flow branching, fallback, batch, and async basics in the current Python environment.
- Run sub-skills/core-abstraction/scripts/core_flow_smoke.py when debugging runtime semantics.
- Use sub-skills/design-patterns/scripts/design_pattern_templates.py to print safe skeletons for common application patterns.
- Use sub-skills/utilities/scripts/pocketflow_utilities.py for local chunking, Mermaid demo output, or environment-variable validation.
Boundaries and caveats
- Do not claim PocketFlow automatically manages prompts, memory, tools, provider retries, callbacks, vector indexes, web servers, tracing, or credentials. Implement those explicitly as utilities and shared-store fields.
- Avoid writing giant
exec()methods that read/write global state; put input selection inprep()and result persistence inpost(). - Do not run credentialed cookbook-style examples unless the user has provided required keys and approved network or service side effects.
AsyncParallelBatchNodeandAsyncParallelBatchFlowoverlap independent async work; they are not CPU-parallel execution engines.- If a task is primarily about maintaining this repository source code rather than using PocketFlow as a package, also apply normal Python repository maintenance practices.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).