graph-runtime
Build, compile, invoke, stream, debug, interrupt, and route custom LangGraph StateGraph/Pregel workflows.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- graph-runtime
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Build, compile, invoke, stream, debug, interrupt, and route custom LangGraph StateGraph/Pregel workflows.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md8.9 KB
- 参考文档references/troubleshooting.md8.3 KB
- 参考文档references/workflows.md7.4 KB
- 脚本scripts/smoke_state_graph.py3.4 KB
03 SKILL.md 正文
Graph Runtime
Use this sub-skill when an agent needs to implement or repair custom LangGraph runtime logic: StateGraph construction, node wiring, conditional routing, reducers, compiled graph invocation, streaming, debug output, interrupts, resume commands, subgraphs, and low-level Pregel channel execution concerns.
When To Use
- Build a custom
StateGraphor compiled graph instead of using a prebuilt agent. - Convert linear workflow code into graph nodes, edges, conditional branches, or subgraphs.
- Add reducer state with
typing_extensions.Annotatedso concurrent node updates merge safely. - Invoke or stream a compiled graph with sync or async APIs.
- Debug missing edges, unknown nodes, recursion-limit failures, invalid updates, interrupts, or stream output shapes.
- Add human-in-the-loop pauses using
interrupt()and resume withCommand(resume=...). - Route with
Command(goto=...),Send(...),add_conditional_edges(...), orset_conditional_entry_point(...).
For prebuilt create_react_agent workflows, route to prebuilt-agents. For checkpoint saver choices, persistent stores, thread history, and production durability, route to persistence. For server deployment and config files, route to cli-deployment. For REST/SDK calls against a deployed graph, route to sdk-clients.
Core Runtime Pattern
- Define a state schema with
TypedDict, dataclass, or Pydantic model. - Use
Annotated[field_type, reducer]on state fields that multiple nodes may update in one step. - Create a
StateGraph(state_schema, context_schema=None, input_schema=None, output_schema=None)builder. - Add nodes with
add_node(name, callable)oradd_sequence([...]). - Add edges with
add_edge(START, node),add_edge(node, END),set_entry_point(node), orset_finish_point(node). - Add routing with
add_conditional_edges(source, route_fn, path_map=...)when the next node depends on state. - Call
compile(...)beforeinvoke,stream,ainvoke, orastream; the builder itself is not executable. - Validate behavior with the bundled smoke script:
python skills/langgraph/sub-skills/graph-runtime/scripts/smoke_state_graph.py.
Minimal example:
from typing_extensions import TypedDict
from langgraph.graph import END, START, StateGraph
class State(TypedDict):
value: int
def inc(state: State) -> State:
return {"value": state["value"] + 1}
builder = StateGraph(State)
builder.add_node("inc", inc)
builder.add_edge(START, "inc")
builder.add_edge("inc", END)
graph = builder.compile()
assert graph.invoke({"value": 1}) == {"value": 2}
Builder APIs To Reach For
StateGraph(...): graph builder for shared-state node workflows; acceptscontext_schema,input_schema, andoutput_schema.add_node(...): adds a callable or runnable; node names must be unique and cannot beSTARTorEND.add_edge(start, end): adds fixed routing; list starts wait for all named nodes before the target runs.add_conditional_edges(source, path, path_map=None): routes after a node based on a callable result.set_entry_point(node)andset_finish_point(node): convenience wrappers forSTARTandENDedges.add_sequence(nodes): creates a linear chain from callables or(name, callable)pairs.set_node_defaults(...): applies default retry, cache, timeout, or error-handler policies at compile time.compile(checkpointer=None, cache=None, store=None, interrupt_before=None, interrupt_after=None, debug=False, name=None): returns the executable compiled graph.
See API Reference for parameter details, deprecations, and output shapes.
Invocation And Streaming
- Use
graph.invoke(input, config=None, *, context=None, stream_mode="values", interrupt_before=None, interrupt_after=None, durability=None)for sync final output. - Use
await graph.ainvoke(...)when any node or surrounding application is async. - Use
graph.stream(input, stream_mode="updates")orasync for chunk in graph.astream(...)for stepwise output. - Valid stream modes include
values,updates,messages,custom,checkpoints,tasks, anddebug. - Passing a list such as
stream_mode=["updates", "values"]yields mode-tagged chunks. - Use
print_modeonly for console debugging; it does not change returned data. - Use
subgraphs=Truewhen you need child graph events included with namespace paths. - Use
version="v2"for typed stream parts fromstream/astream; usestream_events(..., version="v3")when working with event transformers.
See Workflows for reducer, conditional routing, interrupt/resume, subgraph, low-level Pregel, and streaming recipes.
Interrupts And Resume
- Add a checkpointer at compile time when state must persist across interrupts or later resumes.
- Invoke checkpointed graphs with
config={"configurable": {"thread_id": "unique-run-id"}}. - Inside a node, call
interrupt(value)to pause and surface a resumable request. - Resume with
graph.invoke(Command(resume=value), config)or stream the same command. - Multiple simultaneous interrupts may require a resume map keyed by interrupt id.
- Use
interrupt_before=["node"]orinterrupt_after=["node"]at compile or call time to pause around known nodes.
Checkpoint and thread management belongs in persistence, but this sub-skill covers how runtime code calls interrupts and commands.
Debugging Checklist
- If
invokeis missing, confirm you calledcompile()and are not executing the builder. - If compilation fails with missing entrypoint, add an edge from
STARTor callset_entry_point. - If an edge target is unknown, add the node before compiling or fix the path map target.
- If multiple nodes write the same key, add a reducer via
Annotatedor ensure only one update reaches that key per step. - If routing visualizations look too broad, add
path_mapor annotate the routing function return type withLiteral[...]. - If a checkpointed interrupt cannot resume, reuse the same
thread_idand passCommand(resume=...)as the input. - If async code hangs or errors, use
ainvoke/astreamand avoid blocking sync work in async nodes. - If stream output shape surprises you, check
stream_mode, whether a list of modes was supplied, whethersubgraphs=Trueis enabled, and whetherversion="v2"is enabled. - If low-level
Pregelvalidation fails, verify everyinput_channels,output_channels, andstream_channelsentry exists and at least one input channel is subscribed by a node.
See Troubleshooting for error patterns and fixes.
Bundled Script
- scripts/smoke_state_graph.py: self-contained smoke check that builds a reducer-backed conditional graph, compiles it, invokes it, and verifies stream output.
Run:
python skills/langgraph/sub-skills/graph-runtime/scripts/smoke_state_graph.py --help
python skills/langgraph/sub-skills/graph-runtime/scripts/smoke_state_graph.py
python skills/langgraph/sub-skills/graph-runtime/scripts/smoke_state_graph.py --start 3 --limit 5 --json
Expected default result includes a final state with value equal to 3 and a history showing routed node execution.
Evidence And Scope Notes
This guidance is distilled from LangGraph state graph source, runtime types, Pregel execution APIs, runtime tests for state, interruption, Pregel behavior, and stream events, plus public README claims about LangGraph as a durable stateful orchestration framework.
Runtime content intentionally excludes maintainer CI, release tooling, benchmark-only flows, expensive notebooks, and original checkout dependencies. The subgraph notebook evidence was only a moved-document pointer, so subgraph guidance here is based on runtime source/tests rather than a bundled notebook adaptation.
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).