Rename saver to checkpointer, expose in graph, state graph, prebuilt agent exec

This commit is contained in:
Nuno Campos
2024-01-15 13:45:54 -08:00
parent 23f84c9ac9
commit 2e537320c3
6 changed files with 52 additions and 30 deletions
+4 -2
View File
@@ -1,6 +1,6 @@
from asyncio import iscoroutinefunction
from collections import defaultdict
from typing import Any, Callable, Dict, NamedTuple
from typing import Any, Callable, Dict, NamedTuple, Optional
from langchain_core.runnables import Runnable
from langchain_core.runnables.base import (
@@ -9,6 +9,7 @@ from langchain_core.runnables.base import (
coerce_to_runnable,
)
from langgraph.checkpoint import BaseCheckpointSaver
from langgraph.pregel import Channel, Pregel
END = "__end__"
@@ -97,7 +98,7 @@ class Graph:
if node not in all_starts:
raise ValueError(f"Node `{node}` is a dead-end")
def compile(self) -> Pregel:
def compile(self, checkpointer: Optional[BaseCheckpointSaver] = None) -> Pregel:
self.validate()
outgoing_edges = defaultdict(list)
@@ -127,4 +128,5 @@ class Graph:
input=f"{self.entry_point}:inbox",
output=END,
hidden=[f"{node}:inbox" for node in self.nodes],
checkpointer=checkpointer,
)
+3 -1
View File
@@ -8,6 +8,7 @@ from langchain_core.runnables import RunnableConfig, RunnableLambda
from langgraph.channels.base import BaseChannel
from langgraph.channels.binop import BinaryOperatorAggregate
from langgraph.channels.last_value import LastValue
from langgraph.checkpoint import BaseCheckpointSaver
from langgraph.graph.graph import END, Graph
from langgraph.pregel import Channel, Pregel
from langgraph.pregel.read import ChannelRead
@@ -24,7 +25,7 @@ class StateGraph(Graph):
if any(isinstance(c, BinaryOperatorAggregate) for c in self.channels.values()):
self.support_multiple_edges = True
def compile(self) -> Pregel:
def compile(self, checkpointer: Optional[BaseCheckpointSaver] = None) -> Pregel:
self.validate()
if any(key in self.nodes for key in self.channels):
@@ -79,6 +80,7 @@ class StateGraph(Graph):
input=f"{START}:inbox",
output=END,
hidden=[f"{node}:inbox" for node in self.nodes] + [START] + state_keys,
checkpointer=checkpointer,
)