diff --git a/libs/langgraph/langgraph/pregel/__init__.py b/libs/langgraph/langgraph/pregel/__init__.py index 515a33aa4..cee4e16dc 100644 --- a/libs/langgraph/langgraph/pregel/__init__.py +++ b/libs/langgraph/langgraph/pregel/__init__.py @@ -1117,18 +1117,13 @@ class Pregel( def output() -> Iterator: while loop.stream: ns, mode, payload = loop.stream.popleft() - ns = ( - NS_SEP.join(p.split(NS_END)[0] for p in ns.split(NS_SEP)) - if ns - else "" - ) if mode in stream_modes: if subgraphs and isinstance(stream_mode, list): - yield (ns, mode, payload) + yield (tuple(ns.split(NS_SEP)) if ns else (), mode, payload) elif isinstance(stream_mode, list): yield (mode, payload) elif subgraphs: - yield (ns, payload) + yield (tuple(ns.split(NS_SEP)) if ns else (), payload) else: yield payload @@ -1364,18 +1359,13 @@ class Pregel( def output() -> Iterator: while loop.stream: ns, mode, payload = loop.stream.popleft() - ns = ( - NS_SEP.join(p.split(NS_END)[0] for p in ns.split(NS_SEP)) - if ns - else "" - ) if mode in stream_modes: if subgraphs and isinstance(stream_mode, list): - yield (ns, mode, payload) + yield (tuple(ns.split(NS_SEP)) if ns else (), mode, payload) elif isinstance(stream_mode, list): yield (mode, payload) elif subgraphs: - yield (ns, payload) + yield (tuple(ns.split(NS_SEP)) if ns else (), payload) else: yield payload diff --git a/libs/langgraph/tests/test_pregel.py b/libs/langgraph/tests/test_pregel.py index a6a338a75..269e2bbcc 100644 --- a/libs/langgraph/tests/test_pregel.py +++ b/libs/langgraph/tests/test_pregel.py @@ -10898,8 +10898,11 @@ def test_doubly_nested_graph_state( # test invoke w/ nested interrupt config = {"configurable": {"thread_id": "1"}} assert [c for c in app.stream({"my_key": "my value"}, config, subgraphs=True)] == [ - ("", {"parent_1": {"my_key": "hi my value"}}), - ("child|child_1", {"grandchild_1": {"my_key": "hi my value here"}}), + ((), {"parent_1": {"my_key": "hi my value"}}), + ( + (AnyStr("child:"), AnyStr("child_1:")), + {"grandchild_1": {"my_key": "hi my value here"}}, + ), ] # get state without subgraphs outer_state = app.get_state(config) @@ -11121,10 +11124,13 @@ def test_doubly_nested_graph_state( ) # resume assert [c for c in app.stream(None, config, subgraphs=True)] == [ - ("child|child_1", {"grandchild_2": {"my_key": "hi my value here and there"}}), - ("child", {"child_1": {"my_key": "hi my value here and there"}}), - ("", {"child": {"my_key": "hi my value here and there"}}), - ("", {"parent_2": {"my_key": "hi my value here and there and back again"}}), + ( + (AnyStr("child:"), AnyStr("child_1:")), + {"grandchild_2": {"my_key": "hi my value here and there"}}, + ), + ((AnyStr("child:"),), {"child_1": {"my_key": "hi my value here and there"}}), + ((), {"child": {"my_key": "hi my value here and there"}}), + ((), {"parent_2": {"my_key": "hi my value here and there and back again"}}), ] # get state with and without subgraphs assert ( diff --git a/libs/langgraph/tests/test_pregel_async.py b/libs/langgraph/tests/test_pregel_async.py index 830d69238..b24848e6d 100644 --- a/libs/langgraph/tests/test_pregel_async.py +++ b/libs/langgraph/tests/test_pregel_async.py @@ -9341,8 +9341,11 @@ async def test_doubly_nested_graph_state( assert [ c async for c in app.astream({"my_key": "my value"}, config, subgraphs=True) ] == [ - ("", {"parent_1": {"my_key": "hi my value"}}), - ("child|child_1", {"grandchild_1": {"my_key": "hi my value here"}}), + ((), {"parent_1": {"my_key": "hi my value"}}), + ( + (AnyStr("child:"), AnyStr("child_1:")), + {"grandchild_1": {"my_key": "hi my value here"}}, + ), ] # get state without subgraphs outer_state = await app.aget_state(config) @@ -9564,10 +9567,13 @@ async def test_doubly_nested_graph_state( ) # resume assert [c async for c in app.astream(None, config, subgraphs=True)] == [ - ("child|child_1", {"grandchild_2": {"my_key": "hi my value here and there"}}), - ("child", {"child_1": {"my_key": "hi my value here and there"}}), - ("", {"child": {"my_key": "hi my value here and there"}}), - ("", {"parent_2": {"my_key": "hi my value here and there and back again"}}), + ( + (AnyStr("child:"), AnyStr("child_1:")), + {"grandchild_2": {"my_key": "hi my value here and there"}}, + ), + ((AnyStr("child:"),), {"child_1": {"my_key": "hi my value here and there"}}), + ((), {"child": {"my_key": "hi my value here and there"}}), + ((), {"parent_2": {"my_key": "hi my value here and there and back again"}}), ] # get state with and without subgraphs assert (