From 2153d367267b3027451e19d797807261fc093d5a Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 21 Jul 2025 18:48:40 +0100 Subject: [PATCH] feat(langgraph): Handle ParentCommand in RemoteGraph (#5600) - when receiving a "command" stream event raise ParentCommand exception for caller graph to handle --- libs/langgraph/langgraph/pregel/remote.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/langgraph/langgraph/pregel/remote.py b/libs/langgraph/langgraph/pregel/remote.py index 38b334e46..30b6eed8d 100644 --- a/libs/langgraph/langgraph/pregel/remote.py +++ b/libs/langgraph/langgraph/pregel/remote.py @@ -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))