mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-06 09:47:51 +02:00
Add ns to subgraph stream events
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user