langgraph icon indicating copy to clipboard operation
langgraph copied to clipboard

In Langgraph studio the subgraph part is not shown when we invoke the subgraphs in the parent graph's node

Open arya18mak opened this issue 11 months ago • 12 comments

Checked other resources

  • [x] This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • [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

# Define subgraph
class SubgraphState(TypedDict):
    # note that none of these keys are shared with the parent graph state
    bar: str
    baz: str


def subgraph_node_1(state: SubgraphState):
    return {"baz": "baz"}


def subgraph_node_2(state: SubgraphState):
    return {"bar": state["bar"] + state["baz"]}


subgraph_builder = StateGraph(SubgraphState)
subgraph_builder.add_node(subgraph_node_1)
subgraph_builder.add_node(subgraph_node_2)
subgraph_builder.add_edge(START, "subgraph_node_1")
subgraph_builder.add_edge("subgraph_node_1", "subgraph_node_2")
subgraph = subgraph_builder.compile()


# Define parent graph
class ParentState(TypedDict):
    foo: str


def node_1(state: ParentState):
    return {"foo": "hi! " + state["foo"]}


def node_2(state: ParentState):
    # transform the state to the subgraph state
    response = subgraph.invoke({"bar": state["foo"]})
    # transform response back to the parent state
    return {"foo": response["bar"]}


builder = StateGraph(ParentState)
builder.add_node("node_1", node_1)
# note that instead of using the compiled subgraph we are using `node_2` function that is calling the subgraph
builder.add_node("node_2", node_2)
builder.add_edge(START, "node_1")
builder.add_edge("node_1", "node_2")
graph = builder.compile()

#In the above case the subgraph does'nt visualize. But here it does:


from langgraph.graph import START, StateGraph
from typing import TypedDict


# Define subgraph
class SubgraphState(TypedDict):
    foo: str  # note that this key is shared with the parent graph state
    bar: str


def subgraph_node_1(state: SubgraphState):
    return {"bar": "bar"}


def subgraph_node_2(state: SubgraphState):
    # note that this node is using a state key ('bar') that is only available in the subgraph
    # and is sending update on the shared state key ('foo')
    return {"foo": state["foo"] + state["bar"]}


subgraph_builder = StateGraph(SubgraphState)
subgraph_builder.add_node(subgraph_node_1)
subgraph_builder.add_node(subgraph_node_2)
subgraph_builder.add_edge(START, "subgraph_node_1")
subgraph_builder.add_edge("subgraph_node_1", "subgraph_node_2")
subgraph = subgraph_builder.compile()


# Define parent graph
class ParentState(TypedDict):
    foo: str


def node_1(state: ParentState):
    return {"foo": "hi! " + state["foo"]}


builder = StateGraph(ParentState)
builder.add_node("node_1", node_1)
# note that we're adding the compiled subgraph as a node to the parent graph
builder.add_node("node_2", subgraph)
builder.add_edge(START, "node_1")
builder.add_edge("node_1", "node_2")
graph = builder.compile()

Error Message and Stack Trace (if applicable)

No error

Description

I am using langgraph cli and langsmith to visual the graph using studio but when invoking a subgraph from parent node. The UI does'nt expand to subgraph level.

System Info

System Information

OS: Darwin OS Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:22:58 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8132 Python Version: 3.11.9 (v3.11.9:de54cf5be3, Apr 2 2024, 07:12:50) [Clang 13.0.0 (clang-1300.0.29.30)]

Package Information

langchain_core: 0.3.34 langchain: 0.3.18 langchain_community: 0.3.17 langsmith: 0.3.8 langchain_ollama: 0.2.3 langchain_openai: 0.3.4 langchain_text_splitters: 0.3.6 langgraph_api: 0.0.22 langgraph_cli: 0.1.71 langgraph_license: Installed. No version info available. langgraph_sdk: 0.1.51 langgraph_storage: Installed. No version info available.

Optional packages not installed

langserve

Other Dependencies

aiohttp<4.0.0,>=3.8.3: Installed. No version info available. async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. click: 8.1.8 cryptography: 44.0.0 dataclasses-json<0.7,>=0.5.7: Installed. No version info available. httpx: 0.28.1 httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. jsonpatch<2.0,>=1.33: Installed. No version info available. jsonschema-rs: 0.29.1 langchain-anthropic;: Installed. No version info available. langchain-aws;: Installed. No version info available. langchain-cohere;: Installed. No version info available. langchain-community;: Installed. No version info available. langchain-core<1.0.0,>=0.3.34: Installed. No version info available. langchain-deepseek;: Installed. No version info available. langchain-fireworks;: Installed. No version info available. langchain-google-genai;: Installed. No version info available. langchain-google-vertexai;: Installed. No version info available. langchain-groq;: Installed. No version info available. langchain-huggingface;: Installed. No version info available. langchain-mistralai;: Installed. No version info available. langchain-ollama;: Installed. No version info available. langchain-openai;: Installed. No version info available. langchain-text-splitters<1.0.0,>=0.3.6: Installed. No version info available. langchain-together;: Installed. No version info available. langchain<1.0.0,>=0.3.18: Installed. No version info available. langgraph: 0.2.70 langgraph-checkpoint: 2.0.12 langsmith-pyo3: Installed. No version info available. langsmith<0.4,>=0.1.125: Installed. No version info available. langsmith<0.4,>=0.1.17: Installed. No version info available. numpy<2,>=1.26.4;: Installed. No version info available. numpy<3,>=1.26.2;: Installed. No version info available. ollama: 0.4.7 openai<2.0.0,>=1.58.1: Installed. No version info available. orjson: 3.10.15 packaging<25,>=23.2: Installed. No version info available. pydantic: 2.10.6 pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available. pydantic<3.0.0,>=2.5.2;: Installed. No version info available. pydantic<3.0.0,>=2.7.4: Installed. No version info available. pydantic<3.0.0,>=2.7.4;: Installed. No version info available. pyjwt: 2.10.1 pytest: Installed. No version info available. python-dotenv: 1.0.1 PyYAML>=5.3: Installed. No version info available. requests: 2.32.3 requests-toolbelt: 1.0.0 requests<3,>=2: Installed. No version info available. rich: Installed. No version info available. SQLAlchemy<3,>=1.4: Installed. No version info available. sse-starlette: 2.2.1 starlette: 0.45.3 structlog: 25.1.0 tenacity: 9.0.0 tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available. tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. tiktoken<1,>=0.7: Installed. No version info available. typing-extensions>=4.7: Installed. No version info available. uvicorn: 0.34.0 watchfiles: 1.0.4 zstandard: 0.23.0

arya18mak avatar Feb 10 '25 18:02 arya18mak

I got same situation after bumped up langgraph to 0.2.70ish(not sure exactly which version broken), 0.2.71 also same. Flow is still working, only visualization broken for sub graph (line doesn't show up and expanding of subgraph doesn't work) any updates?

junan-trustarc avatar Feb 11 '25 23:02 junan-trustarc

I got same situation after bumped up langgraph to 0.2.70ish(not sure exactly which version broken), 0.2.71 also same. Flow is still working, only visualization broken for sub graph (line doesn't show up and expanding of subgraph doesn't work) any updates?

No, still facing the same issue

arya18mak avatar Feb 12 '25 20:02 arya18mak

I got same situation after bumped up langgraph to 0.2.70ish(not sure exactly which version broken), 0.2.71 also same. Flow is still working, only visualization broken for sub graph (line doesn't show up and expanding of subgraph doesn't work) any updates?

No, still facing the same issue

I mean, I got also same issue, I was asking to langgraph team for the any updates.

junan-trustarc avatar Feb 12 '25 20:02 junan-trustarc

@arya18mak thanks for reporting -- we will look into better support, in the meantime you can add an explicit edge w/ END to your subgraph. let me know if this resolves the issue for you

from langgraph.graph import START, END

...
subgraph_builder.add_edge(START, "subgraph_node_1")
subgraph_builder.add_edge("subgraph_node_1", "subgraph_node_2")
subgraph_builder.add_edge("subgraph_node_2", END)
...

vbarda avatar Feb 13 '25 16:02 vbarda

Also getting the same issue

affanshahid avatar Feb 19 '25 08:02 affanshahid

@affanshahid does the above suggestion resolve the issue?

vbarda avatar Feb 21 '25 14:02 vbarda

@affanshahid does the above suggestion resolve the issue?

Can't put explicitly since it is conditional edge using "Command"

graph_builder.set_entry_point("supervisor")
graph_builder.add_edge("tools", "supervisor")
graph_builder.add_edge("subgraph_node_1", "supervisor")
graph_builder.add_edge("subgraph_node_2", "supervisor")
and so on..

and when I display on image, it draws correctly.

from IPython.display import Image, display

display(Image(graph.get_graph(xray=True).draw_mermaid_png()))

junan-trustarc avatar Feb 21 '25 16:02 junan-trustarc

@vbarda I already have an explicit end:

Sub-graph:

builder = StateGraph(WritingTeamState)
retry = RetryPolicy(max_attempts=5)

builder.add_node(PLAN, plan, retry=retry)
builder.add_node(WRITE, write, retry=retry)
builder.add_node(REVIEW, review, retry=retry)
builder.add_node(ADD_DIAGRAMS, add_diagrams, retry=retry)
builder.add_node(REMOVE_DUPLICATES, remove_duplicate_images, retry=retry)

builder.add_edge(START, PLAN)
builder.add_edge(PLAN, WRITE)
builder.add_conditional_edges(
    WRITE, should_review, {REVIEW: REVIEW, ADD_DIAGRAMS: ADD_DIAGRAMS}
)
builder.add_edge(REVIEW, PLAN)
builder.add_edge(ADD_DIAGRAMS, REMOVE_DUPLICATES)
builder.add_edge(REMOVE_DUPLICATES, END)

Main Graph:

builder = StateGraph(RaModelNoteGenerationState)
retry = RetryPolicy(max_attempts=5)

builder.add_node("research", research, retry=retry)
builder.add_node("perform_conversations", perform_conversations, retry=retry)
builder.add_node("refine_outline", refine_outline, retry=retry)
builder.add_node("write", write, retry=retry) # sub-graph
builder.add_node("combine", combine, retry=retry)

builder.add_edge(START, "research")
builder.add_edge("research", "perform_conversations")
builder.add_edge("perform_conversations", "refine_outline")
builder.add_edge("refine_outline", "write")
builder.add_edge("write", "combine")

builder.add_edge("combine", END)

affanshahid avatar Feb 22 '25 12:02 affanshahid

same issue

arthberman avatar Feb 23 '25 15:02 arthberman

@junan-trustarc you can now add explicit annotations for nodes returning Command:

graph.add_node("name", func, destinations=("target_node_1",))

vbarda avatar Mar 11 '25 16:03 vbarda

@junan-trustarc you can now add explicit annotations for nodes returning Command:

graph.add_node("name", func, destinations=("target_node_1",))

Ah, I found issue on my side. I actually used enum for node. For example,

class MainNode(str, Enum):
    SUPERVISOR = "supervisor"
    TOOLS = "tools",
    NOTIFICATION = "notification"

This was not working, because add_node has two methods, it calls with node: RunnableLike, but it supposed to use the one with node: str

graph_builder.add_node(
    MainNode.NOTIFICATION,
    self.notification_service.build_graph(),
)

I had to put like this, after that it is working.

graph_builder.add_node(
    MainNode.NOTIFICATION.value,
    self.notification_service.build_graph(),
)

junan-trustarc avatar Mar 11 '25 22:03 junan-trustarc

This issue still persists and it sucks.

For example, if you call an agent, like reAct agent, inside a graph node, it won't show in LangGraph Studio. It makes it difficult to debug issues and follow the progress of a run. The subgraph does appear at the end of execution.

eyueldk avatar Mar 27 '25 13:03 eyueldk

i also found this bug

hechuancy avatar Aug 21 '25 06:08 hechuancy

我也发现了这个漏洞

But detail result of subgraph can be found in langsmith trace page in langgraph studio.

hechuancy avatar Aug 21 '25 06:08 hechuancy

I'm not 100% sure if this is the same problem I had a couple of weeks ago, but I did develop a workaround by copying state to the parent graph's state and posted about that in the LangGraph forum. Hope this helps someone.

How do I view the state of a subgraph with a persistent sub-thread?

I am working on a system that creates sub-threads between parts of the parent graph and a sub-graph. The sub-graph is responsible for the state of the sub-thread, for the purpose of modularity. When I run this graph in LangGraph Studio the subgraph node does not expand when I click it. The graph otherwise does what I expect it to. It handles a multi-turn conversation (with a doorknob) in the parent graph and the sub-graph in LangGraph Studio. My final state is shown below after 2 messages sent.

aerickson-clt avatar Aug 27 '25 21:08 aerickson-clt