Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
arya18mak opened this issue Feb 10, 2025 · 9 comments
Labels
question Further information is requested

Comments

@arya18mak
Copy link

arya18mak commented Feb 10, 2025

Checked other resources

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

# 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

@junan-trustarc
Copy link

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?

@arya18mak
Copy link
Author

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

@junan-trustarc
Copy link

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.

@vbarda
Copy link
Collaborator

vbarda commented Feb 13, 2025

@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 vbarda added the question Further information is requested label Feb 13, 2025
@affanshahid
Copy link

Also getting the same issue

@vbarda
Copy link
Collaborator

vbarda commented Feb 21, 2025

@affanshahid does the above suggestion resolve the issue?

@junan-trustarc
Copy link

junan-trustarc commented Feb 21, 2025

@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()))

@affanshahid
Copy link

@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)

@arthberman
Copy link
Contributor

same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants