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

MULTIPLE_SUBGRAPHS exception raised incorrectly #2737

Open
1 task done
eyurtsev opened this issue Dec 12, 2024 · 1 comment
Open
1 task done

MULTIPLE_SUBGRAPHS exception raised incorrectly #2737

eyurtsev opened this issue Dec 12, 2024 · 1 comment

Comments

@eyurtsev
Copy link
Contributor

eyurtsev commented Dec 12, 2024

Privileged issue

  • I am a LangChain maintainer, or was asked directly by a LangChain maintainer to create an issue here.

Issue Content

This should probably be a different exception -- we're just returning the wrong thing (the subgraph instead of the return value from the subgraph)

import uuid
from typing import TypedDict, Optional

from langgraph.graph import StateGraph
from langgraph.constants import START 
from langgraph.checkpoint.memory import MemorySaver


class State(TypedDict):
    """The graph state."""
    state_counter: int

def child_node(state: State):
    return state


subgraph_builder = StateGraph(State)
subgraph_builder.add_node("child_node", child_node)
subgraph_builder.add_edge(START, "child_node")
subgraph = subgraph_builder.compile() 

def parent_node(state: State):
    """This parent node will invoke the subgraph."""
    subgraph_state = subgraph.invoke(state)
    return subgraph # <--- THIS IS THE BUG IN USER CODE (typo), exception claims multiple subgraph calls (based on ast parsing?)

checkpointer = MemorySaver()


builder = StateGraph(State)
builder.add_node("parent_node", parent_node)
builder.add_edge(START, "parent_node")

# A checkpointer must be enabled for interrupts to work!
checkpointer = MemorySaver()
graph = builder.compile(checkpointer=checkpointer)

config = {
    "configurable": {
        "thread_id": uuid.uuid4(),
    }
}

for chunk in graph.stream({"state_counter": 1}, config):
    print(chunk)
@isatyamks
Copy link

image

@eyurtsev Since the code now returns subgraph_state instead of state, it seems the issue is resolved. Let me know if I'm misunderstanding something

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

No branches or pull requests

2 participants