Move START & END to constants.py

This commit is contained in:
William Fu-Hinthorn
2024-06-05 07:42:39 -07:00
parent 03ba503569
commit bcc6e51f87
2 changed files with 14 additions and 11 deletions
+3
View File
@@ -7,6 +7,9 @@ TASKS = "__pregel_tasks"
RESERVED = {INTERRUPT, TASKS, CONFIG_KEY_SEND, CONFIG_KEY_READ}
TAG_HIDDEN = "langsmith:hidden"
START = "__start__"
END = "__end__"
class Send:
"""A message or packet to send to a specific node in the graph.
+11 -11
View File
@@ -26,7 +26,7 @@ from langchain_core.runnables.graph import (
from langgraph.channels.ephemeral_value import EphemeralValue
from langgraph.checkpoint import BaseCheckpointSaver
from langgraph.constants import TAG_HIDDEN, Send
from langgraph.constants import END, START, TAG_HIDDEN, Send
from langgraph.errors import InvalidUpdateError
from langgraph.pregel import Channel, Pregel
from langgraph.pregel.read import PregelNode
@@ -36,9 +36,6 @@ from langgraph.utils import DrawableGraph, RunnableCallable, coerce_to_runnable
logger = logging.getLogger(__name__)
START = "__start__"
END = "__end__"
class Branch(NamedTuple):
path: Runnable[Any, Union[str, list[str]]]
@@ -341,10 +338,11 @@ class Graph:
# validate the graph
self.validate(
interrupt=(interrupt_before if interrupt_before != "*" else [])
+ interrupt_after
if interrupt_after != "*"
else []
interrupt=(
(interrupt_before if interrupt_before != "*" else []) + interrupt_after
if interrupt_after != "*"
else []
)
)
# create empty compiled graph
@@ -404,9 +402,11 @@ class CompiledGraph(Pregel):
def attach_branch(self, start: str, name: str, branch: Branch) -> None:
def branch_writer(packets: list[Union[str, Send]]) -> Optional[ChannelWrite]:
writes = [
ChannelWriteEntry(f"branch:{start}:{name}:{p}" if p != END else END)
if not isinstance(p, Send)
else p
(
ChannelWriteEntry(f"branch:{start}:{name}:{p}" if p != END else END)
if not isinstance(p, Send)
else p
)
for p in packets
]
return ChannelWrite(writes, tags=[TAG_HIDDEN])