mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-31 20:29:46 +02:00
feat(langgraph): Handle ParentCommand in RemoteGraph (#5600)
- when receiving a "command" stream event raise ParentCommand exception for caller graph to handle
This commit is contained in:
@@ -40,7 +40,7 @@ from langgraph.constants import (
|
||||
INTERRUPT,
|
||||
NS_SEP,
|
||||
)
|
||||
from langgraph.errors import GraphInterrupt
|
||||
from langgraph.errors import GraphInterrupt, ParentCommand
|
||||
from langgraph.pregel.protocol import PregelProtocol
|
||||
from langgraph.pregel.types import All, PregelTask, StateSnapshot, StreamMode
|
||||
from langgraph.types import Command, Interrupt, StreamProtocol
|
||||
@@ -672,6 +672,9 @@ class RemoteGraph(PregelProtocol):
|
||||
ns = tuple(ns_.split(NS_SEP))
|
||||
else:
|
||||
mode, ns = chunk.event, ()
|
||||
# raise ParentCommand exception for command events
|
||||
if mode == "command" and chunk.data.get("graph") == Command.PARENT:
|
||||
raise ParentCommand(Command(**chunk.data))
|
||||
# prepend caller ns (as it is not passed to remote graph)
|
||||
if caller_ns := (config or {}).get(CONF, {}).get(CONFIG_KEY_CHECKPOINT_NS):
|
||||
caller_ns = tuple(caller_ns.split(NS_SEP))
|
||||
@@ -771,6 +774,9 @@ class RemoteGraph(PregelProtocol):
|
||||
ns = tuple(ns_.split(NS_SEP))
|
||||
else:
|
||||
mode, ns = chunk.event, ()
|
||||
# raise ParentCommand exception for command events
|
||||
if mode == "command" and chunk.data.get("graph") == Command.PARENT:
|
||||
raise ParentCommand(Command(**chunk.data))
|
||||
# prepend caller ns (as it is not passed to remote graph)
|
||||
if caller_ns := (config or {}).get(CONF, {}).get(CONFIG_KEY_CHECKPOINT_NS):
|
||||
caller_ns = tuple(caller_ns.split(NS_SEP))
|
||||
|
||||
Reference in New Issue
Block a user