This commit is contained in:
Harrison Chase
2024-02-07 22:08:16 -08:00
parent b0b792f114
commit f808aa2967
4 changed files with 840 additions and 4 deletions
File diff suppressed because one or more lines are too long
@@ -413,8 +413,7 @@
" print(f\"Output from node '{key}':\")\n",
" print(\"---\")\n",
" print(value)\n",
" print(\"\\n---\\n\")\n",
" history= output['__end__']"
" print(\"\\n---\\n\")"
]
},
{
+2 -2
View File
@@ -1,5 +1,5 @@
from langgraph.graph.graph import END, Graph
from langgraph.graph.graph import END, Graph, START
from langgraph.graph.message import MessageGraph
from langgraph.graph.state import StateGraph
__all__ = ["END", "Graph", "StateGraph", "MessageGraph"]
__all__ = ["END", "START", "Graph", "StateGraph", "MessageGraph"]
+8
View File
@@ -13,6 +13,7 @@ from langgraph.checkpoint import BaseCheckpointSaver
from langgraph.pregel import Channel, Pregel
END = "__end__"
START = "START"
class Branch(NamedTuple):
@@ -34,6 +35,7 @@ class Graph:
self.edges = set[tuple[str, str]]()
self.branches: defaultdict[str, list[Branch]] = defaultdict(list)
self.support_multiple_edges = False
self.entry_point = None
def add_node(self, key: str, action: RunnableLike) -> None:
if key in self.nodes:
@@ -85,6 +87,12 @@ class Graph:
raise ValueError(f"Need to add_node `{key}` first")
self.entry_point = key
def set_entry_route(self, condition: Callable[..., str],
conditional_edge_mapping: Optional[Dict[str, str]] = None) -> None:
self.add_node(START, lambda x: None)
self.add_conditional_edges(START, condition, conditional_edge_mapping)
self.set_entry_point(START)
def set_finish_point(self, key: str) -> None:
return self.add_edge(key, END)