KeyError: when using subgraph inside Parent workflow #1008

Closed
opened 2026-02-20 17:42:42 -05:00 by yindo · 3 comments
Owner

Originally created by @BennisonDevadoss on GitHub (Oct 11, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

.py
from langgraph.graph import StateGraph, START, END
from ..scheduler.graph import graph as subgraph

builder = StateGraph(SharedState)
builder.add_node("scheduler_assistant", subgraph)
builder.add_node("enter_scheduler_assistant",
                 create_entry_node("Scheduler Assistant", "scheduler_assistant"))
builder.add_edge("enter_scheduler_assistant", "scheduler_assistant")
builder.add_conditional_edges(
    START,
    route_to_workflow,
    ["primary_assistant", "scheduler_assistant", "generate_query_or_respond"],
)
graph = builder.compile(checkpointer=checkpointer)


.py
builder = StateGraph(SharedState)
# ... define internal assistants, nodes, edges ...
graph = builder.compile()  # Compiled correctly

Error Message and Stack Trace (if applicable)

KeyError: 'scheduler_assistant'
During task with name '__start__' and id '157199d9-7f9e-94bf-896b-f7c9a36469c6'
During task with name 'scheduler_assistant' and id '04143ef8-a134-325c-601d-feed19ab2c31'

Description

I am encountering a KeyError: 'scheduler_assistant' in my LangGraph workflow when running a parent graph that embeds another compiled graph (acting as a subgraph).

This happens during graph execution when the parent graph tries to route to the scheduler_assistant node — which internally wraps my “Scheduler Assistant” subgraph.

Expected Behavior
The graph should correctly hand off execution to the scheduler subgraph or route through the "enter_scheduler_assistant" node without failing on undefined node names.

Actual Behavior
LangGraph raises a KeyError while evaluating conditional edges:

r if isinstance(r, Send) else self.ends[r] for r in result
KeyError: 'scheduler_assistant'

Questions

  1. Is embedding a compiled subgraph directly as a node (builder.add_node("scheduler_assistant", subgraph)) officially supported?
  2. Should subgraphs always be wrapped in callable nodes instead of being added directly?
  3. Is there a way to allow route targets like "scheduler_assistant" to map to an internal subgraph entry automatically?

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:32:05 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T8132
Python Version: 3.12.11 (main, Sep 18 2025, 19:41:45) [Clang 20.1.4 ]

Package Information

langchain_core: 0.3.76
langchain: 0.3.27
langchain_community: 0.3.29
langsmith: 0.4.31
langchain_anthropic: 0.3.20
langchain_chroma: 0.2.6
langchain_google_genai: 2.1.12
langchain_groq: 0.3.8
langchain_huggingface: 0.3.1
langchain_milvus: 0.2.1
langchain_openai: 0.3.33
langchain_postgres: 0.0.15
langchain_text_splitters: 0.3.11
langgraph_sdk: 0.2.9

Originally created by @BennisonDevadoss on GitHub (Oct 11, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python .py from langgraph.graph import StateGraph, START, END from ..scheduler.graph import graph as subgraph builder = StateGraph(SharedState) builder.add_node("scheduler_assistant", subgraph) builder.add_node("enter_scheduler_assistant", create_entry_node("Scheduler Assistant", "scheduler_assistant")) builder.add_edge("enter_scheduler_assistant", "scheduler_assistant") builder.add_conditional_edges( START, route_to_workflow, ["primary_assistant", "scheduler_assistant", "generate_query_or_respond"], ) graph = builder.compile(checkpointer=checkpointer) .py builder = StateGraph(SharedState) # ... define internal assistants, nodes, edges ... graph = builder.compile() # Compiled correctly ``` ### Error Message and Stack Trace (if applicable) ```shell KeyError: 'scheduler_assistant' During task with name '__start__' and id '157199d9-7f9e-94bf-896b-f7c9a36469c6' During task with name 'scheduler_assistant' and id '04143ef8-a134-325c-601d-feed19ab2c31' ``` ### Description I am encountering a KeyError: 'scheduler_assistant' in my LangGraph workflow when running a parent graph that embeds another compiled graph (acting as a subgraph). This happens during graph execution when the parent graph tries to route to the scheduler_assistant node — which internally wraps my “Scheduler Assistant” subgraph. **Expected Behavior** The graph should correctly hand off execution to the scheduler subgraph or route through the "enter_scheduler_assistant" node without failing on undefined node names. **Actual Behavior** LangGraph raises a KeyError while evaluating conditional edges: ```text r if isinstance(r, Send) else self.ends[r] for r in result KeyError: 'scheduler_assistant' ``` **Questions** 1. Is embedding a compiled subgraph directly as a node (builder.add_node("scheduler_assistant", subgraph)) officially supported? 2. Should subgraphs always be wrapped in callable nodes instead of being added directly? 3. Is there a way to allow route targets like "scheduler_assistant" to map to an internal subgraph entry automatically? ### System Info **System Information** > OS: Darwin > OS Version: Darwin Kernel Version 24.4.0: Fri Apr 11 18:32:05 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T8132 > Python Version: 3.12.11 (main, Sep 18 2025, 19:41:45) [Clang 20.1.4 ] **Package Information** > langchain_core: 0.3.76 > langchain: 0.3.27 > langchain_community: 0.3.29 > langsmith: 0.4.31 > langchain_anthropic: 0.3.20 > langchain_chroma: 0.2.6 > langchain_google_genai: 2.1.12 > langchain_groq: 0.3.8 > langchain_huggingface: 0.3.1 > langchain_milvus: 0.2.1 > langchain_openai: 0.3.33 > langchain_postgres: 0.0.15 > langchain_text_splitters: 0.3.11 > langgraph_sdk: 0.2.9
yindo added the bugpending labels 2026-02-20 17:42:42 -05:00
yindo closed this issue 2026-02-20 17:42:43 -05:00
Author
Owner

@sarathak commented on GitHub (Oct 12, 2025):

@BennisonDevadoss not able to reproduce issue with this information.

@sarathak commented on GitHub (Oct 12, 2025): @BennisonDevadoss not able to reproduce issue with this information.
Author
Owner

@BennisonDevadoss commented on GitHub (Oct 12, 2025):

@sarathak, Thank you for looking into this! I understand the minimal snippet might not be helpful to reproduce the issue.

To help with debugging, I’m sharing my GitHub repository link where the full project code is available. In particular, the agentic_rag directory contains my parent agent graph implementation, and the scheduler directory contains the compiled subgraph that agentic_rag references.

Link for repo: https://github.com/BennisonDevadoss/schedule-pro/tree/feature/langgraph-multigraph-handling/app/agents

@BennisonDevadoss commented on GitHub (Oct 12, 2025): @sarathak, Thank you for looking into this! I understand the minimal snippet might not be helpful to reproduce the issue. To help with debugging, I’m sharing my GitHub repository link where the full project code is available. In particular, the `agentic_rag` directory contains my parent agent graph implementation, and the `scheduler` directory contains the compiled subgraph that agentic_rag references. Link for repo: https://github.com/BennisonDevadoss/schedule-pro/tree/feature/langgraph-multigraph-handling/app/agents
Author
Owner

@casparb commented on GitHub (Oct 14, 2025):

Hi @BennisonDevadoss, I am closing this issue as I am unable to repro with the code you provided. Please take some time to come up with a minimal reproducible example that I can run standalone to reproduce this issue, then comment it in this issue thread, and Id be happy to re-open and help you find a solution. Thanks.

@casparb commented on GitHub (Oct 14, 2025): Hi @BennisonDevadoss, I am closing this issue as I am unable to repro with the code you provided. Please take some time to come up with a minimal reproducible example that I can run standalone to reproduce this issue, then comment it **in this issue thread**, and Id be happy to re-open and help you find a solution. Thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1008