From 5805e5709af8b46328b5c60fb1d10b146b849cb3 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Tue, 14 Jan 2025 18:16:06 -0800 Subject: [PATCH] Fix ignored goto when a mixed list of command and state updates is returned from a node --- libs/langgraph/langgraph/graph/state.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index 3fbb312299..16bbf7d48b 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -847,14 +847,10 @@ def _control_branch(value: Any) -> Sequence[Union[str, Send]]: commands: list[Command] = [] if isinstance(value, Command): commands.append(value) - elif ( - isinstance(value, (list, tuple)) - and value - and all(isinstance(i, Command) for i in value) - ): - commands.extend(value) - else: - return EMPTY_SEQ + elif isinstance(value, (list, tuple)): + for cmd in value: + if isinstance(cmd, Command): + commands.append(cmd) rtn: list[Union[str, Send]] = [] for command in commands: if command.graph == Command.PARENT: @@ -874,14 +870,10 @@ async def _acontrol_branch(value: Any) -> Sequence[Union[str, Send]]: commands: list[Command] = [] if isinstance(value, Command): commands.append(value) - elif ( - isinstance(value, (list, tuple)) - and value - and all(isinstance(i, Command) for i in value) - ): - commands.extend(value) - else: - return EMPTY_SEQ + elif isinstance(value, (list, tuple)): + for cmd in value: + if isinstance(cmd, Command): + commands.append(cmd) rtn: list[Union[str, Send]] = [] for command in commands: if command.graph == Command.PARENT: