graph-runtime
Build, compile, invoke, stream, debug, interrupt, and route custom LangGraph StateGraph/Pregel workflows.
- License 许可
- MIT
- 最近更新
- 2026-10-08
- Stars
- ★ 11
- Forks
- 3
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 资源文件 3
- 参考文档references/api-reference.md8.9 KB
- 参考文档references/troubleshooting.md8.3 KB
- 参考文档references/workflows.md7.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
obsidian-clipper-template-creator
Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.
obsidian-clipper-template-creator
Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.
python-api
Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP/mAP semantics, and source-style import diagnostics.
file-evaluation
Folder-based PASCAL VOC AP/mAP evaluation from ground-truth and detection text files.
object-detection-metrics
Guides legacy Object-Detection-Metrics PASCAL VOC AP/mAP evaluation from detection text folders and direct Python API classes.
nx-workspace-patterns
Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.