[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M792CHBTDHYPYWZGR6RC8KXK":3,"skill-same:01M792CHBTDHYPYWZGR6RC8KXK":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":37,"commitSha":38,"skillDirectory":39,"forksCount":40,"repositoryHtmlUrl":41,"repositoryHomepageUrl":6,"ownerHtmlUrl":42,"ownerBlogUrl":43,"ownerDescription":44,"updatedAt":45,"install":46,"resources":59},"01M792CHBTDHYPYWZGR6RC8KXK","langchain-langgraph-subgraphs",null,"Compose LangGraph 1.0 subgraphs correctly — shared state key propagation,\nSend \u002F Command(graph=...) dispatch, callback scoping, per-subgraph recursion\nbudgets, and testing each subgraph in isolation. Use when building a planner +\nexecutor, a nested agent team, or a reusable subgraph library. Trigger with\n\"langgraph subgraph\", \"langgraph composition\", \"langgraph send\",\n\"nested agents\", \"langgraph state propagation\", \"Command(graph=...)\",\n\"langgraph subgraph callbacks\".","jukeyman\u002Fjukeyman-skills","jukeyman","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F142960420?v=4","01M78FR4Y3DHMMCBCC0GXXNB3F","RICK JEFFERSON","01M78FR4Z8RVQRAD31Y5J7V6EB",1,"MIT","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsaas-packs--langchain-py-pack--langchain-langgraph-subgraphs\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: langchain-langgraph-subgraphs\ndescription: |\n  Compose LangGraph 1.0 subgraphs correctly — shared state key propagation,\n  Send \u002F Command(graph=...) dispatch, callback scoping, per-subgraph recursion\n  budgets, and testing each subgraph in isolation. Use when building a planner +\n  executor, a nested agent team, or a reusable subgraph library. Trigger with\n  \"langgraph subgraph\", \"langgraph composition\", \"langgraph send\",\n  \"nested agents\", \"langgraph state propagation\", \"Command(graph=...)\",\n  \"langgraph subgraph callbacks\".\nallowed-tools: Read, Write, Edit, Bash(python:*)\nversion: 2.0.0\nlicense: MIT\nauthor: Jeremy Longshore \u003Cjeremy@intentsolutions.io>\ntags: [saas, langchain, langgraph, python, langchain-1.0, subgraphs, composition]\ncompatible-with: claude-code, codex\n---\n\n# LangGraph Subgraphs and Composition (Python)\n\n## Overview\n\nA parent `StateGraph` invokes a compiled child subgraph as a node. The child\nnode writes `state[\"answer\"] = \"42\"` and returns. The parent's next node reads\n`state[\"answer\"]` and gets `None`. No error, no warning, no deprecation notice —\njust a silent `None` that surfaces as a wrong answer three nodes later when the\nrouter picks the \"couldn't find it\" branch.\n\nThe cause is pain-catalog entry **P21**: LangGraph subgraphs run on an\n**independent state schema**. Only keys declared in *both* the parent's\n`TypedDict` and the child's `TypedDict` propagate across the subgraph boundary.\n`answer` existed in the child schema but not the parent schema, so it was\ndiscarded on return. The fix is to declare `answer` in both schemas (with\nmatching reducers, if the field is a list) or to use explicit\n`Command(graph=ParentGraph, update={\"answer\": \"42\"})` to bubble it up.\n\nThe second silent failure waits one step further. Attach a tracing callback to\nthe parent runnable via `parent.with_config(callbacks=[tracer])` and invoke.\nThe tracer fires on parent nodes and never on child tool calls. This is\npain-catalog entry **P28**: LangGraph creates a fresh runtime per subgraph, so\ncallbacks bound at *definition time* do not inherit. The fix is to pass\ncallbacks at *invocation time* via `config[\"callbacks\"]`, which does propagate.\n\nThis skill walks through the shared-state contract, three dispatch patterns\n(compiled subgraph as a node, `Send` fan-out, `Command(graph=Parent)` bubble-up),\ncallback scoping, per-subgraph `recursion_limit` budgets, and a testing pattern\nthat exercises every subgraph in isolation before composition. Pin:\n`langgraph 1.0.x`, `langchain-core 1.0.x`. Pain-catalog anchors: **P21, P28**,\nwith supporting references to P18 (reducers), P19 (stream modes on nested\ngraphs), and P55 (recursion budget).\n\nA planner-executor is typically **1 parent + 2-4 subgraphs**; a hierarchical\nagent team with a supervisor and N specialists is **1 parent + N subgraphs**.\nEach subgraph has its own independent `recursion_limit` (default 25) — a parent\nat step 20 can still invoke a child that runs 25 of its own steps.\n\n## Prerequisites\n\n- Python 3.10+\n- `langgraph >= 1.0, \u003C 2.0`\n- `langchain-core >= 1.0, \u003C 2.0`\n- Completion of `langchain-langgraph-basics` (L25) — `StateGraph`, `TypedDict`\n  state, `Annotated[list, add_messages]` reducer, `MemorySaver` checkpointing\n- Test tooling: `pytest`, `langchain_core.language_models.fake_chat_models.FakeListChatModel`\n\n## Instructions\n\n### Step 1 — Declare the shared-state contract explicitly\n\nThe single most important decision when composing subgraphs is: **which keys\ncross the boundary?** Every key that must survive the call *must* appear in\nboth `TypedDict` schemas with compatible types and reducers.\n\n```python\nfrom typing import Annotated, TypedDict\nfrom langchain_core.messages import AnyMessage\nfrom langgraph.graph.message import add_messages\n\n# Keys both schemas declare -> these propagate\n# Keys only in parent -> invisible to child\n# Keys only in child -> discarded on return (P21)\n\nclass ParentState(TypedDict):\n    # Shared with every subgraph\n    messages: Annotated[list[AnyMessage], add_messages]  # P18 reducer required\n    session_id: str\n\n    # Parent-only coordination fields\n    plan: list[str]\n    current_step: int\n\nclass ExecutorState(TypedDict):\n    # Shared with parent — must match reducer exactly (P18)\n    messages: Annotated[list[AnyMessage], add_messages]\n    session_id: str\n\n    # Executor-only scratch — parent never sees these\n    tool_result: dict | None\n    retries: int\n```\n\nIf `messages` on the child used a different reducer (or no reducer), list\nupdates would silently replace instead of append on one side of the boundary\n(P18). The `messages` + `session_id` pair is the propagation contract. Everything\nelse is private to its owner.\n\nSee [State Contract](references\u002Fstate-contract.md) for the full\nstate-propagation matrix and the \"subset rule\" for schema inheritance.\n\n### Step 2 — Pick the dispatch pattern\n\nThree ways a parent can invoke a subgraph, and each solves a different problem.\n\n**A. Compiled subgraph as a node** — Simplest. Subgraph runs, returns a state\nupdate, parent continues.\n\n```python\nfrom langgraph.graph import StateGraph, END\n\nexecutor_graph = (\n    StateGraph(ExecutorState)\n    .add_node(\"run_tool\", run_tool_node)\n    .add_node(\"summarize\", summarize_node)\n    .add_edge(\"run_tool\", \"summarize\")\n    .add_edge(\"summarize\", END)\n    .set_entry_point(\"run_tool\")\n    .compile()\n)\n\nparent_graph = (\n    StateGraph(ParentState)\n    .add_node(\"plan\", planner_node)\n    .add_node(\"execute\", executor_graph)   # compiled subgraph as a node\n    .add_node(\"finalize\", finalize_node)\n    .add_edge(\"plan\", \"execute\")\n    .add_edge(\"execute\", \"finalize\")\n    .set_entry_point(\"plan\")\n    .compile()\n)\n```\n\nOnly `messages` and `session_id` cross the boundary in either direction (from\nStep 1). `tool_result` stays inside the child; `plan` stays inside the parent.\n\n**B. `Send(graph, state)` for fan-out** — One parent step spawns N parallel\nsubgraph invocations, each with a different slice of state.\n\n```python\nfrom langgraph.types import Send\n\ndef dispatch_specialists(state: ParentState) -> list[Send]:\n    return [\n        Send(\"specialist_graph\", {\"messages\": state[\"messages\"],\n                                   \"session_id\": state[\"session_id\"],\n                                   \"topic\": topic})\n        for topic in state[\"plan\"]\n    ]\n```\n\nUse `Send` when the number of subgraph calls depends on runtime state.\nReducers on shared keys merge the parallel results.\n\n**C. `Command(graph=ParentGraph, update=...)` to bubble up** — A subgraph node\njumps control back to the parent with an explicit state update, skipping the\nrest of the subgraph.\n\n```python\nfrom langgraph.types import Command\n\ndef specialist_early_exit(state: ExecutorState) -> Command:\n    if state.get(\"tool_result\") and state[\"tool_result\"].get(\"done\"):\n        return Command(\n            graph=Command.PARENT,\n            update={\"messages\": [AIMessage(\"done\")]},\n            goto=\"finalize\",\n        )\n    return {\"retries\": state.get(\"retries\", 0) + 1}\n```\n\n`Command(graph=Command.PARENT)` is the explicit opposite of P21 — it forces a\nfield up to the parent scope regardless of schema overlap.\n\nSee [Dispatch Patterns](references\u002Fdispatch-patterns.md) for the full decision\ntree (inline function vs subgraph-as-node vs `Send` vs `Command` vs separate\nservice) and a sizing guide.\n\n### Step 3 — Scope callbacks at invocation time, not definition time\n\n```python\n# WRONG — callbacks bind at definition time and do NOT propagate to subgraphs (P28)\ntraced_parent = parent_graph.with_config(callbacks=[tracer])\ntraced_parent.invoke({\"messages\": [HumanMessage(\"...\")], \"session_id\": \"s1\"})\n# tracer fires on parent nodes only. Child tool calls are invisible.\n\n# RIGHT — callbacks pass via config at invocation time, propagating into every subgraph\nparent_graph.invoke(\n    {\"messages\": [HumanMessage(\"...\")], \"session_id\": \"s1\"},\n    config={\n        \"configurable\": {\"thread_id\": \"s1\"},\n        \"callbacks\": [tracer],\n    },\n)\n# tracer fires on parent nodes AND every child tool, LLM, and chain event.\n```\n\nEvery production invocation path — API handler, batch worker, test harness —\nshould pass callbacks via `config[\"callbacks\"]`. Lint for\n`with_config(callbacks=` on compiled graphs in CI and flag it.\n\nSee [Callback Scoping](references\u002Fcallback-scoping.md) for the debugging\nplaybook when a callback \"should be firing but isn't.\"\n\n### Step 4 — Budget recursion per subgraph\n\nLangGraph's `recursion_limit` (default **25** supersteps) is **per-graph, not\nglobal**. A parent graph at superstep 20 invoking a subgraph resets the counter\ninside that subgraph to zero. Pros: one runaway subgraph cannot starve the\nparent. Cons: adding subgraphs does not reduce your global budget — a poorly\nbounded specialist can still rack up 25 of its own steps while the parent\nthinks it spent only one.\n\n```python\n# Parent gets 10 steps of its own planning.\n# Each executor call gets its own 15-step budget, independent of the parent's 10.\nparent_graph.invoke(\n    initial_state,\n    config={\n        \"configurable\": {\"thread_id\": \"s1\"},\n        \"recursion_limit\": 10,\n    },\n)\n\nexecutor_graph.invoke(\n    sub_state,\n    config={\"recursion_limit\": 15},\n)\n```\n\nFor a parent that dispatches `N` specialists via `Send`, worst-case step count\nis `parent_limit + N * specialist_limit`. Monitor the actual distribution with\na callback on `on_chain_start` \u002F `on_chain_end` at each graph boundary —\n`GraphRecursionError` with no obvious loop is P55 in the pain catalog, and\nsubgraph composition is the most common cause.\n\n### Step 5 — Test every subgraph in isolation before composing\n\nA subgraph that works alone and breaks in composition is almost always a\nstate-contract bug (Step 1) or a callback-scoping bug (Step 3). Catch both by\nunit-testing each subgraph with a `FakeListChatModel` and an in-memory\ncheckpointer before wiring it into a parent.\n\n```python\nfrom langchain_core.language_models.fake_chat_models import FakeListChatModel\nfrom langgraph.checkpoint.memory import MemorySaver\n\ndef test_executor_subgraph_standalone():\n    fake = FakeListChatModel(responses=['{\"done\": true, \"result\": 42}'])\n    graph = build_executor(llm=fake).compile(checkpointer=MemorySaver())\n    out = graph.invoke(\n        {\"messages\": [HumanMessage(\"do the thing\")],\n         \"session_id\": \"test\",\n         \"tool_result\": None,\n         \"retries\": 0},\n        config={\"configurable\": {\"thread_id\": \"test\"},\n                \"recursion_limit\": 5},\n    )\n    # Assert the shared-contract fields (Step 1) are present on return\n    assert \"messages\" in out\n    assert out[\"session_id\"] == \"test\"\n    # Assert child-only field is scoped correctly\n    assert out[\"tool_result\"] == {\"done\": True, \"result\": 42}\n```\n\nSee [Testing Subgraphs](references\u002Ftesting-subgraphs.md) for the full isolation\npattern — fixtures, state-shape assertions per node, and how to assert callback\npropagation with a capturing handler.\n\n### Step 6 — Version subgraphs independently of the parent\n\nA reusable subgraph should ship with its own semantic version and a pinned\nschema contract. Breaking either the shared-state contract (Step 1) or the\ndispatch signature (Step 2) is a major-version bump; adding a new private\nchild-only field is a patch.\n\n```python\n# executor_subgraph\u002F__init__.py\n__version__ = \"1.2.0\"\n\nSHARED_KEYS = frozenset({\"messages\", \"session_id\"})  # parent must declare these\n\ndef build_executor(llm) -> StateGraph:\n    \"\"\"v1.2.0 executor — adds 'retries' field (child-only, backward-compatible).\"\"\"\n    ...\n```\n\nParents pin `executor_subgraph>=1.2.0,\u003C2.0.0`. A v2.0.0 that renames `session_id`\nforces every parent to re-sync its `TypedDict`. This is how you catch P21 at\n`pip install` time instead of at runtime.\n\n## Output\n\n- `ParentState` + per-subgraph child `TypedDict`s with the shared-key contract\n  declared explicitly; every shared list field has a matching reducer\n- Dispatch pattern chosen per subgraph (node vs `Send` vs `Command(graph=PARENT)`)\n  with rationale recorded in code comments\n- Every invocation path (API, batch, test) passes `callbacks` via\n  `config[\"callbacks\"]` so observability propagates into every subgraph\n- `recursion_limit` set explicitly on parent and each subgraph, with the\n  worst-case superstep count documented\n- Unit tests for each subgraph in isolation, asserting shared-contract fields\n  on return and callback propagation via a capturing handler\n- Reusable subgraphs ship with their own `__version__` and a frozen\n  `SHARED_KEYS` set\n\n## Error Handling\n\n| Error \u002F Symptom | Cause | Fix |\n|---|---|---|\n| Parent reads `state[\"foo\"]` and gets `None` after subgraph call | Key declared only in child schema; discarded on return (P21) | Add `foo` to parent `TypedDict`; use matching reducer; or return `Command(graph=Command.PARENT, update={\"foo\": ...})` |\n| Tracer attached to parent never fires on child tool calls | Callback bound at definition time via `.with_config(callbacks=[...])` (P28) | Pass `callbacks=[tracer]` in `config` at each `invoke()` \u002F `ainvoke()` call |\n| `TypeError: unhashable type` from the message reducer in the parent after a `Send` fan-out | Child schema used `list` instead of `Annotated[list, add_messages]` (P18) | Match reducers on both sides of the boundary |\n| `GraphRecursionError: Recursion limit of 25 reached` inside a subgraph only | Subgraph has its own 25-step budget; long sub-loop (P55) | Set `config={\"recursion_limit\": N}` explicitly or restructure subgraph |\n| Subgraph returns state but parent sees empty `messages` | List field not using `add_messages` reducer on the parent side (P18) | `messages: Annotated[list[AnyMessage], add_messages]` in both `TypedDict`s |\n| `Command(goto=\"next_node\")` halts instead of continuing | `Command` did not set `graph=Command.PARENT` — tried to `goto` a parent node from inside the child scope | Use `Command(graph=Command.PARENT, goto=\"next_node\", update=...)` |\n| Subgraph runs but thread state never persists | Checkpointer attached only to parent; child `invoke()` without `thread_id` | Compile subgraphs with `checkpointer` too, or invoke with a `thread_id` matching the parent |\n\n## Examples\n\n### Planner-executor — shared messages, private scratch\n\nThe prototypical 1 + 2-4 composition: a planner writes a step list, an executor\nruns each step, a finalizer summarizes. `messages` and `session_id` cross every\nboundary; `plan` is parent-only; `tool_result` and `retries` are executor-only.\nUses a compiled-subgraph-as-node dispatch (Step 2A). See\n[Dispatch Patterns](references\u002Fdispatch-patterns.md) for the full worked example.\n\n### Hierarchical agent team — supervisor fans out to N specialists\n\nA supervisor picks which specialists to invoke and calls `Send(\"specialist\",\n...)` in parallel. Each specialist runs its own subgraph with its own recursion\nbudget. Results merge via the `messages` reducer. See\n[Dispatch Patterns](references\u002Fdispatch-patterns.md) for the `Send`-based\nfan-out and the callback propagation pattern needed to trace the team.\n\n### Reusable subgraph library — pinned contract with versioned exports\n\nAn `executor_subgraph` package exports `build_executor(llm)` and a frozen\n`SHARED_KEYS` set, ships with a semantic version, and its CI fails if\n`SHARED_KEYS` changes without a major-version bump. See\n[State Contract](references\u002Fstate-contract.md) for the schema-pinning pattern.\n\n### Testing a specialist with a capturing callback\n\nA `CaptureHandler` subclasses `BaseCallbackHandler`, appends every `on_*` event\nto a list, and asserts both parent and child events are present after a single\n`parent_graph.invoke(..., config={\"callbacks\": [handler]})`. Catches P28 at PR\nreview. See [Testing Subgraphs](references\u002Ftesting-subgraphs.md) for the full\nfixture and assertion pattern.\n\n## Resources\n\n- [LangGraph subgraph concepts](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Fconcepts\u002Fsubgraphs\u002F)\n- [LangGraph subgraph how-to](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Fhow-tos\u002Fsubgraph\u002F)\n- [`Send` API reference](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Freference\u002Ftypes\u002F#langgraph.types.Send)\n- [`Command` API reference](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Freference\u002Ftypes\u002F#langgraph.types.Command)\n- [LangGraph callback propagation](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Fhow-tos\u002Fstreaming\u002F)\n- [LangChain 1.0 release notes](https:\u002F\u002Fblog.langchain.com\u002Flangchain-langgraph-1dot0\u002F)\n- Sibling skill: `langchain-langgraph-basics` (L25) — prerequisite `StateGraph`, reducers, checkpointing\n- Pack pain catalog: `docs\u002Fpain-catalog.md` (entries P18, P19, P21, P28, P55)\n","# LangGraph Subgraphs and Composition (Python)\n\n## Overview\n\nA parent `StateGraph` invokes a compiled child subgraph as a node. The child\nnode writes `state[\"answer\"] = \"42\"` and returns. The parent's next node reads\n`state[\"answer\"]` and gets `None`. No error, no warning, no deprecation notice —\njust a silent `None` that surfaces as a wrong answer three nodes later when the\nrouter picks the \"couldn't find it\" branch.\n\nThe cause is pain-catalog entry **P21**: LangGraph subgraphs run on an\n**independent state schema**. Only keys declared in *both* the parent's\n`TypedDict` and the child's `TypedDict` propagate across the subgraph boundary.\n`answer` existed in the child schema but not the parent schema, so it was\ndiscarded on return. The fix is to declare `answer` in both schemas (with\nmatching reducers, if the field is a list) or to use explicit\n`Command(graph=ParentGraph, update={\"answer\": \"42\"})` to bubble it up.\n\nThe second silent failure waits one step further. Attach a tracing callback to\nthe parent runnable via `parent.with_config(callbacks=[tracer])` and invoke.\nThe tracer fires on parent nodes and never on child tool calls. This is\npain-catalog entry **P28**: LangGraph creates a fresh runtime per subgraph, so\ncallbacks bound at *definition time* do not inherit. The fix is to pass\ncallbacks at *invocation time* via `config[\"callbacks\"]`, which does propagate.\n\nThis skill walks through the shared-state contract, three dispatch patterns\n(compiled subgraph as a node, `Send` fan-out, `Command(graph=Parent)` bubble-up),\ncallback scoping, per-subgraph `recursion_limit` budgets, and a testing pattern\nthat exercises every subgraph in isolation before composition. Pin:\n`langgraph 1.0.x`, `langchain-core 1.0.x`. Pain-catalog anchors: **P21, P28**,\nwith supporting references to P18 (reducers), P19 (stream modes on nested\ngraphs), and P55 (recursion budget).\n\nA planner-executor is typically **1 parent + 2-4 subgraphs**; a hierarchical\nagent team with a supervisor and N specialists is **1 parent + N subgraphs**.\nEach subgraph has its own independent `recursion_limit` (default 25) — a parent\nat step 20 can still invoke a child that runs 25 of its own steps.\n\n## Prerequisites\n\n- Python 3.10+\n- `langgraph >= 1.0, \u003C 2.0`\n- `langchain-core >= 1.0, \u003C 2.0`\n- Completion of `langchain-langgraph-basics` (L25) — `StateGraph`, `TypedDict`\n  state, `Annotated[list, add_messages]` reducer, `MemorySaver` checkpointing\n- Test tooling: `pytest`, `langchain_core.language_models.fake_chat_models.FakeListChatModel`\n\n## Instructions\n\n### Step 1 — Declare the shared-state contract explicitly\n\nThe single most important decision when composing subgraphs is: **which keys\ncross the boundary?** Every key that must survive the call *must* appear in\nboth `TypedDict` schemas with compatible types and reducers.\n\n```python\nfrom typing import Annotated, TypedDict\nfrom langchain_core.messages import AnyMessage\nfrom langgraph.graph.message import add_messages\n\n# Keys both schemas declare -> these propagate\n# Keys only in parent -> invisible to child\n# Keys only in child -> discarded on return (P21)\n\nclass ParentState(TypedDict):\n    # Shared with every subgraph\n    messages: Annotated[list[AnyMessage], add_messages]  # P18 reducer required\n    session_id: str\n\n    # Parent-only coordination fields\n    plan: list[str]\n    current_step: int\n\nclass ExecutorState(TypedDict):\n    # Shared with parent — must match reducer exactly (P18)\n    messages: Annotated[list[AnyMessage], add_messages]\n    session_id: str\n\n    # Executor-only scratch — parent never sees these\n    tool_result: dict | None\n    retries: int\n```\n\nIf `messages` on the child used a different reducer (or no reducer), list\nupdates would silently replace instead of append on one side of the boundary\n(P18). The `messages` + `session_id` pair is the propagation contract. Everything\nelse is private to its owner.\n\nSee [State Contract](references\u002Fstate-contract.md) for the full\nstate-propagation matrix and the \"subset rule\" for schema inheritance.\n\n### Step 2 — Pick the dispatch pattern\n\nThree ways a parent can invoke a subgraph, and each solves a different problem.\n\n**A. Compiled subgraph as a node** — Simplest. Subgraph runs, returns a state\nupdate, parent continues.\n\n```python\nfrom langgraph.graph import StateGraph, END\n\nexecutor_graph = (\n    StateGraph(ExecutorState)\n    .add_node(\"run_tool\", run_tool_node)\n    .add_node(\"summarize\", summarize_node)\n    .add_edge(\"run_tool\", \"summarize\")\n    .add_edge(\"summarize\", END)\n    .set_entry_point(\"run_tool\")\n    .compile()\n)\n\nparent_graph = (\n    StateGraph(ParentState)\n    .add_node(\"plan\", planner_node)\n    .add_node(\"execute\", executor_graph)   # compiled subgraph as a node\n    .add_node(\"finalize\", finalize_node)\n    .add_edge(\"plan\", \"execute\")\n    .add_edge(\"execute\", \"finalize\")\n    .set_entry_point(\"plan\")\n    .compile()\n)\n```\n\nOnly `messages` and `session_id` cross the boundary in either direction (from\nStep 1). `tool_result` stays inside the child; `plan` stays inside the parent.\n\n**B. `Send(graph, state)` for fan-out** — One parent step spawns N parallel\nsubgraph invocations, each with a different slice of state.\n\n```python\nfrom langgraph.types import Send\n\ndef dispatch_specialists(state: ParentState) -> list[Send]:\n    return [\n        Send(\"specialist_graph\", {\"messages\": state[\"messages\"],\n                                   \"session_id\": state[\"session_id\"],\n                                   \"topic\": topic})\n        for topic in state[\"plan\"]\n    ]\n```\n\nUse `Send` when the number of subgraph calls depends on runtime state.\nReducers on shared keys merge the parallel results.\n\n**C. `Command(graph=ParentGraph, update=...)` to bubble up** — A subgraph node\njumps control back to the parent with an explicit state update, skipping the\nrest of the subgraph.\n\n```python\nfrom langgraph.types import Command\n\ndef specialist_early_exit(state: ExecutorState) -> Command:\n    if state.get(\"tool_result\") and state[\"tool_result\"].get(\"done\"):\n        return Command(\n            graph=Command.PARENT,\n            update={\"messages\": [AIMessage(\"done\")]},\n            goto=\"finalize\",\n        )\n    return {\"retries\": state.get(\"retries\", 0) + 1}\n```\n\n`Command(graph=Command.PARENT)` is the explicit opposite of P21 — it forces a\nfield up to the parent scope regardless of schema overlap.\n\nSee [Dispatch Patterns](references\u002Fdispatch-patterns.md) for the full decision\ntree (inline function vs subgraph-as-node vs `Send` vs `Command` vs separate\nservice) and a sizing guide.\n\n### Step 3 — Scope callbacks at invocation time, not definition time\n\n```python\n# WRONG — callbacks bind at definition time and do NOT propagate to subgraphs (P28)\ntraced_parent = parent_graph.with_config(callbacks=[tracer])\ntraced_parent.invoke({\"messages\": [HumanMessage(\"...\")], \"session_id\": \"s1\"})\n# tracer fires on parent nodes only. Child tool calls are invisible.\n\n# RIGHT — callbacks pass via config at invocation time, propagating into every subgraph\nparent_graph.invoke(\n    {\"messages\": [HumanMessage(\"...\")], \"session_id\": \"s1\"},\n    config={\n        \"configurable\": {\"thread_id\": \"s1\"},\n        \"callbacks\": [tracer],\n    },\n)\n# tracer fires on parent nodes AND every child tool, LLM, and chain event.\n```\n\nEvery production invocation path — API handler, batch worker, test harness —\nshould pass callbacks via `config[\"callbacks\"]`. Lint for\n`with_config(callbacks=` on compiled graphs in CI and flag it.\n\nSee [Callback Scoping](references\u002Fcallback-scoping.md) for the debugging\nplaybook when a callback \"should be firing but isn't.\"\n\n### Step 4 — Budget recursion per subgraph\n\nLangGraph's `recursion_limit` (default **25** supersteps) is **per-graph, not\nglobal**. A parent graph at superstep 20 invoking a subgraph resets the counter\ninside that subgraph to zero. Pros: one runaway subgraph cannot starve the\nparent. Cons: adding subgraphs does not reduce your global budget — a poorly\nbounded specialist can still rack up 25 of its own steps while the parent\nthinks it spent only one.\n\n```python\n# Parent gets 10 steps of its own planning.\n# Each executor call gets its own 15-step budget, independent of the parent's 10.\nparent_graph.invoke(\n    initial_state,\n    config={\n        \"configurable\": {\"thread_id\": \"s1\"},\n        \"recursion_limit\": 10,\n    },\n)\n\nexecutor_graph.invoke(\n    sub_state,\n    config={\"recursion_limit\": 15},\n)\n```\n\nFor a parent that dispatches `N` specialists via `Send`, worst-case step count\nis `parent_limit + N * specialist_limit`. Monitor the actual distribution with\na callback on `on_chain_start` \u002F `on_chain_end` at each graph boundary —\n`GraphRecursionError` with no obvious loop is P55 in the pain catalog, and\nsubgraph composition is the most common cause.\n\n### Step 5 — Test every subgraph in isolation before composing\n\nA subgraph that works alone and breaks in composition is almost always a\nstate-contract bug (Step 1) or a callback-scoping bug (Step 3). Catch both by\nunit-testing each subgraph with a `FakeListChatModel` and an in-memory\ncheckpointer before wiring it into a parent.\n\n```python\nfrom langchain_core.language_models.fake_chat_models import FakeListChatModel\nfrom langgraph.checkpoint.memory import MemorySaver\n\ndef test_executor_subgraph_standalone():\n    fake = FakeListChatModel(responses=['{\"done\": true, \"result\": 42}'])\n    graph = build_executor(llm=fake).compile(checkpointer=MemorySaver())\n    out = graph.invoke(\n        {\"messages\": [HumanMessage(\"do the thing\")],\n         \"session_id\": \"test\",\n         \"tool_result\": None,\n         \"retries\": 0},\n        config={\"configurable\": {\"thread_id\": \"test\"},\n                \"recursion_limit\": 5},\n    )\n    # Assert the shared-contract fields (Step 1) are present on return\n    assert \"messages\" in out\n    assert out[\"session_id\"] == \"test\"\n    # Assert child-only field is scoped correctly\n    assert out[\"tool_result\"] == {\"done\": True, \"result\": 42}\n```\n\nSee [Testing Subgraphs](references\u002Ftesting-subgraphs.md) for the full isolation\npattern — fixtures, state-shape assertions per node, and how to assert callback\npropagation with a capturing handler.\n\n### Step 6 — Version subgraphs independently of the parent\n\nA reusable subgraph should ship with its own semantic version and a pinned\nschema contract. Breaking either the shared-state contract (Step 1) or the\ndispatch signature (Step 2) is a major-version bump; adding a new private\nchild-only field is a patch.\n\n```python\n# executor_subgraph\u002F__init__.py\n__version__ = \"1.2.0\"\n\nSHARED_KEYS = frozenset({\"messages\", \"session_id\"})  # parent must declare these\n\ndef build_executor(llm) -> StateGraph:\n    \"\"\"v1.2.0 executor — adds 'retries' field (child-only, backward-compatible).\"\"\"\n    ...\n```\n\nParents pin `executor_subgraph>=1.2.0,\u003C2.0.0`. A v2.0.0 that renames `session_id`\nforces every parent to re-sync its `TypedDict`. This is how you catch P21 at\n`pip install` time instead of at runtime.\n\n## Output\n\n- `ParentState` + per-subgraph child `TypedDict`s with the shared-key contract\n  declared explicitly; every shared list field has a matching reducer\n- Dispatch pattern chosen per subgraph (node vs `Send` vs `Command(graph=PARENT)`)\n  with rationale recorded in code comments\n- Every invocation path (API, batch, test) passes `callbacks` via\n  `config[\"callbacks\"]` so observability propagates into every subgraph\n- `recursion_limit` set explicitly on parent and each subgraph, with the\n  worst-case superstep count documented\n- Unit tests for each subgraph in isolation, asserting shared-contract fields\n  on return and callback propagation via a capturing handler\n- Reusable subgraphs ship with their own `__version__` and a frozen\n  `SHARED_KEYS` set\n\n## Error Handling\n\n| Error \u002F Symptom | Cause | Fix |\n|---|---|---|\n| Parent reads `state[\"foo\"]` and gets `None` after subgraph call | Key declared only in child schema; discarded on return (P21) | Add `foo` to parent `TypedDict`; use matching reducer; or return `Command(graph=Command.PARENT, update={\"foo\": ...})` |\n| Tracer attached to parent never fires on child tool calls | Callback bound at definition time via `.with_config(callbacks=[...])` (P28) | Pass `callbacks=[tracer]` in `config` at each `invoke()` \u002F `ainvoke()` call |\n| `TypeError: unhashable type` from the message reducer in the parent after a `Send` fan-out | Child schema used `list` instead of `Annotated[list, add_messages]` (P18) | Match reducers on both sides of the boundary |\n| `GraphRecursionError: Recursion limit of 25 reached` inside a subgraph only | Subgraph has its own 25-step budget; long sub-loop (P55) | Set `config={\"recursion_limit\": N}` explicitly or restructure subgraph |\n| Subgraph returns state but parent sees empty `messages` | List field not using `add_messages` reducer on the parent side (P18) | `messages: Annotated[list[AnyMessage], add_messages]` in both `TypedDict`s |\n| `Command(goto=\"next_node\")` halts instead of continuing | `Command` did not set `graph=Command.PARENT` — tried to `goto` a parent node from inside the child scope | Use `Command(graph=Command.PARENT, goto=\"next_node\", update=...)` |\n| Subgraph runs but thread state never persists | Checkpointer attached only to parent; child `invoke()` without `thread_id` | Compile subgraphs with `checkpointer` too, or invoke with a `thread_id` matching the parent |\n\n## Examples\n\n### Planner-executor — shared messages, private scratch\n\nThe prototypical 1 + 2-4 composition: a planner writes a step list, an executor\nruns each step, a finalizer summarizes. `messages` and `session_id` cross every\nboundary; `plan` is parent-only; `tool_result` and `retries` are executor-only.\nUses a compiled-subgraph-as-node dispatch (Step 2A). See\n[Dispatch Patterns](references\u002Fdispatch-patterns.md) for the full worked example.\n\n### Hierarchical agent team — supervisor fans out to N specialists\n\nA supervisor picks which specialists to invoke and calls `Send(\"specialist\",\n...)` in parallel. Each specialist runs its own subgraph with its own recursion\nbudget. Results merge via the `messages` reducer. See\n[Dispatch Patterns](references\u002Fdispatch-patterns.md) for the `Send`-based\nfan-out and the callback propagation pattern needed to trace the team.\n\n### Reusable subgraph library — pinned contract with versioned exports\n\nAn `executor_subgraph` package exports `build_executor(llm)` and a frozen\n`SHARED_KEYS` set, ships with a semantic version, and its CI fails if\n`SHARED_KEYS` changes without a major-version bump. See\n[State Contract](references\u002Fstate-contract.md) for the schema-pinning pattern.\n\n### Testing a specialist with a capturing callback\n\nA `CaptureHandler` subclasses `BaseCallbackHandler`, appends every `on_*` event\nto a list, and asserts both parent and child events are present after a single\n`parent_graph.invoke(..., config={\"callbacks\": [handler]})`. Catches P28 at PR\nreview. See [Testing Subgraphs](references\u002Ftesting-subgraphs.md) for the full\nfixture and assertion pattern.\n\n## Resources\n\n- [LangGraph subgraph concepts](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Fconcepts\u002Fsubgraphs\u002F)\n- [LangGraph subgraph how-to](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Fhow-tos\u002Fsubgraph\u002F)\n- [`Send` API reference](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Freference\u002Ftypes\u002F#langgraph.types.Send)\n- [`Command` API reference](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Freference\u002Ftypes\u002F#langgraph.types.Command)\n- [LangGraph callback propagation](https:\u002F\u002Flangchain-ai.github.io\u002Flanggraph\u002Fhow-tos\u002Fstreaming\u002F)\n- [LangChain 1.0 release notes](https:\u002F\u002Fblog.langchain.com\u002Flangchain-langgraph-1dot0\u002F)\n- Sibling skill: `langchain-langgraph-basics` (L25) — prerequisite `StateGraph`, reducers, checkpointing\n- Pack pain catalog: `docs\u002Fpain-catalog.md` (entries P18, P19, P21, P28, P55)\n",{"name":5,"tags":24,"author":32,"license":15,"version":33,"description":34,"allowed-tools":35,"compatible-with":36},[25,26,27,28,29,30,31],"saas","langchain","langgraph","python","langchain-1.0","subgraphs","composition","Jeremy Longshore \u003Cjeremy@intentsolutions.io>","2.0.0","Compose LangGraph 1.0 subgraphs correctly — shared state key propagation,\nSend \u002F Command(graph=...) dispatch, callback scoping, per-subgraph recursion\nbudgets, and testing each subgraph in isolation. Use when building a planner +\nexecutor, a nested agent team, or a reusable subgraph library. Trigger with\n\"langgraph subgraph\", \"langgraph composition\", \"langgraph send\",\n\"nested agents\", \"langgraph state propagation\", \"Command(graph=...)\",\n\"langgraph subgraph callbacks\".\n","Read, Write, Edit, Bash(python:*)","claude-code, codex","main","99825ad3f3bcc6597ddcc7294a14e6e922f2b67b","skills\u002Fsaas-packs--langchain-py-pack--langchain-langgraph-subgraphs",0,"https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills","https:\u002F\u002Fgithub.com\u002Fjukeyman","https:\u002F\u002FRJBUSINESSSOLUTIONS.ORG","Credit and Finance Expert | Developer\r\n\r\nI'm Rick Jefferson, a seasoned credit and finance expert with over a decade of experience in financial literacy,","2026-07-13 07:03:29",{"source":8,"skillName":5,"commands":47,"prompt":57,"zipAvailable":58},[48,51,54],{"tool":49,"command":50},"npx","npx skills add jukeyman\u002Fjukeyman-skills --skill langchain-langgraph-subgraphs",{"tool":52,"command":53},"bunx","bunx skills add jukeyman\u002Fjukeyman-skills --skill langchain-langgraph-subgraphs",{"tool":55,"command":56},"pnpm","pnpm dlx skills add jukeyman\u002Fjukeyman-skills --skill langchain-langgraph-subgraphs","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsaas-packs--langchain-py-pack--langchain-langgraph-subgraphs\u002FSKILL.md",true,[],[61,68,75,82,89,97],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M79ANS2SM329NEP5ZCX106RR","zustand-store-creator","Create zustand store creator operations. Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category. Use when working with zustand store creator functionality. Trigger with phrases like \"zustand store creator\", \"zustand creator\", \"zustand\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M79AMZKP4YDEZ7EHG1Y7PP74","zero-trust-config-helper","Configure with zero trust config helper operations. Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category. Use when configuring systems or services. Trigger with phrases like \"zero trust config helper\", \"zero helper\", \"zero\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M79AMJSBCEJQNBTYNAHYN5HM","zapier-integration-helper","Assist with zapier integration helper operations. Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category. Use when working with APIs or building integrations. Trigger with phrases like \"zapier integration helper\", \"zapier helper\", \"zapier\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M79AHJZGVMARS13VFQYRR1MP","yaml-config-validator","Validate yaml config validator operations. Auto-activating skill for DevOps Basics.\nTriggers on: yaml config validator, yaml config validator\nPart of the DevOps Basics skill category. Use when configuring systems or services. Trigger with phrases like \"yaml config validator\", \"yaml validator\", \"yaml\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fyaml-config-validator\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":93,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M79AHGDZRN0020RDQSQDPAM8","xvary-stock-research","Thesis-driven equity analysis from public SEC EDGAR and market data; \u002Fanalyze, \u002Fscore, \u002Fcompare workflows with bundled Python tools (Claude Code, Cursor, Codex).","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxvary-stock-research\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxvary-stock-research\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M79AHCYJ9FV9RMHQ24HDRN33","xss-vulnerability-scanner","Scan xss vulnerability scanner operations. Auto-activating skill for Security Fundamentals.\nTriggers on: xss vulnerability scanner, xss vulnerability scanner\nPart of the Security Fundamentals skill category. Use when working with xss vulnerability scanner functionality. Trigger with phrases like \"xss vulnerability scanner\", \"xss scanner\", \"xss\".","https:\u002F\u002Fgithub.com\u002Fjukeyman\u002Fjukeyman-skills\u002Fblob\u002Fmain\u002Fskills\u002Fxss-vulnerability-scanner\u002FSKILL.md",[],[]]