This commit is contained in:
Nuno Campos
2025-04-25 15:38:41 -07:00
parent 460edde3a7
commit d90126b34e
3 changed files with 8 additions and 6 deletions
+3 -4
View File
@@ -34,7 +34,7 @@ from langgraph.utils.runnable import (
)
Writer = Callable[
[Sequence[Union[str, Send]]],
[Sequence[Union[str, Send]], bool],
Sequence[Union[ChannelWriteEntry, Send]],
]
@@ -142,7 +142,7 @@ class Branch(NamedTuple):
),
list(
zip_longest(
writer([e for e in self.ends.values()]),
writer([e for e in self.ends.values()], True),
[str(la) for la, e in self.ends.items()],
)
)
@@ -211,12 +211,11 @@ class Branch(NamedTuple):
]
else:
destinations = cast(Sequence[Union[Send, str]], result)
destinations = [d for d in destinations if d != END]
if any(dest is None or dest == START for dest in destinations):
raise ValueError("Branch did not return a valid destination")
if any(p.node == END for p in destinations if isinstance(p, Send)):
raise InvalidUpdateError("Cannot send a packet to the END node")
entries = writer(destinations)
entries = writer(destinations, False)
if not entries:
return input
else:
+1 -1
View File
@@ -374,7 +374,7 @@ class CompiledGraph(Pregel):
def attach_branch(self, start: str, name: str, branch: Branch) -> None:
def get_writes(
packets: Sequence[Union[str, Send]],
packets: Sequence[Union[str, Send]], static: bool = False
) -> Sequence[Union[ChannelWriteEntry, Send]]:
return [
(
+4 -1
View File
@@ -843,7 +843,7 @@ class CompiledStateGraph(CompiledGraph):
self, start: str, name: str, branch: Branch, *, with_reader: bool = True
) -> None:
def get_writes(
packets: Sequence[Union[str, Send]],
packets: Sequence[Union[str, Send]], static: bool = False
) -> Sequence[Union[ChannelWriteEntry, Send]]:
writes = [
(
@@ -852,7 +852,10 @@ class CompiledStateGraph(CompiledGraph):
else p
)
for p in packets
if (True if static else p != END)
]
if not writes:
return []
if branch.then and branch.then != END:
writes.append(
ChannelWriteEntry(