Skip to content

KeyError: when using subgraph inside Parent workflow #6272

@BennisonDevadoss

Description

@BennisonDevadoss

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpendingawaiting review/confirmation by maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions