From d12c2bae6b4a9aeebc3953fa65e9b312504f094f Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Mon, 29 Apr 2024 14:58:25 -0700 Subject: [PATCH] add arguments to chat agent executor --- langgraph/graph/graph.py | 4 +--- langgraph/prebuilt/chat_agent_executor.py | 17 ++++++++++++++--- langgraph/pregel/__init__.py | 12 ++++-------- langgraph/serde/base.py | 6 ++---- langgraph/version.py | 1 + 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/langgraph/graph/graph.py b/langgraph/graph/graph.py index 7291b4e15..36cc01cc0 100644 --- a/langgraph/graph/graph.py +++ b/langgraph/graph/graph.py @@ -15,9 +15,7 @@ from typing import ( from langchain_core.runnables import Runnable from langchain_core.runnables.base import RunnableLike from langchain_core.runnables.config import RunnableConfig -from langchain_core.runnables.graph import ( - Node as RunnableGraphNode, -) +from langchain_core.runnables.graph import Node as RunnableGraphNode from langgraph.channels.ephemeral_value import EphemeralValue from langgraph.checkpoint import BaseCheckpointSaver diff --git a/langgraph/prebuilt/chat_agent_executor.py b/langgraph/prebuilt/chat_agent_executor.py index fbc254b96..03d90c890 100644 --- a/langgraph/prebuilt/chat_agent_executor.py +++ b/langgraph/prebuilt/chat_agent_executor.py @@ -1,5 +1,5 @@ import json -from typing import Annotated, Sequence, TypedDict, Union +from typing import Annotated, Optional, Sequence, TypedDict, Union from langchain_core.language_models import LanguageModelLike from langchain_core.messages import BaseMessage, FunctionMessage @@ -7,6 +7,7 @@ from langchain_core.runnables import RunnableLambda from langchain_core.tools import BaseTool from langchain_core.utils.function_calling import convert_to_openai_function +from langgraph.checkpoint import BaseCheckpointSaver from langgraph.graph import END, StateGraph from langgraph.graph.graph import CompiledGraph from langgraph.graph.message import add_messages @@ -134,7 +135,12 @@ def create_function_calling_executor( def create_tool_calling_executor( - model: LanguageModelLike, tools: Union[ToolExecutor, Sequence[BaseTool]] + model: LanguageModelLike, + tools: Union[ToolExecutor, Sequence[BaseTool]], + checkpointer: Optional[BaseCheckpointSaver] = None, + interrupt_before: Optional[Sequence[str]] = None, + interrupt_after: Optional[Sequence[str]] = None, + debug: bool = False, ) -> CompiledGraph: """Creates a graph that works with a chat model that utilizes tool calling. @@ -231,4 +237,9 @@ def create_tool_calling_executor( # Finally, we compile it! # This compiles it into a LangChain Runnable, # meaning you can use it as you would any other runnable - return workflow.compile() + return workflow.compile( + checkpointer=checkpointer, + interrupt_before=interrupt_before, + interrupt_after=interrupt_after, + debug=debug, + ) diff --git a/langgraph/pregel/__init__.py b/langgraph/pregel/__init__.py index 5d5f90633..c26b05241 100644 --- a/langgraph/pregel/__init__.py +++ b/langgraph/pregel/__init__.py @@ -116,8 +116,7 @@ class Channel: *, key: Optional[str] = None, tags: Optional[list[str]] = None, - ) -> PregelNode: - ... + ) -> PregelNode: ... @overload @classmethod @@ -127,8 +126,7 @@ class Channel: *, key: None = None, tags: Optional[list[str]] = None, - ) -> PregelNode: - ... + ) -> PregelNode: ... @classmethod def subscribe_to( @@ -1212,8 +1210,7 @@ def _prepare_next_tasks( processes: Mapping[str, PregelNode], channels: Mapping[str, BaseChannel], for_execution: Literal[False], -) -> tuple[Checkpoint, list[PregelTaskDescription]]: - ... +) -> tuple[Checkpoint, list[PregelTaskDescription]]: ... @overload @@ -1222,8 +1219,7 @@ def _prepare_next_tasks( processes: Mapping[str, PregelNode], channels: Mapping[str, BaseChannel], for_execution: Literal[True], -) -> tuple[Checkpoint, list[PregelExecutableTask]]: - ... +) -> tuple[Checkpoint, list[PregelExecutableTask]]: ... def _prepare_next_tasks( diff --git a/langgraph/serde/base.py b/langgraph/serde/base.py index 2fbb0ab71..5f1250d1e 100644 --- a/langgraph/serde/base.py +++ b/langgraph/serde/base.py @@ -10,8 +10,6 @@ class SerializerProtocol(Protocol): Valid implementations include the `pickle`, `json` and `orjson` modules. """ - def dumps(self, obj: Any) -> bytes: - ... + def dumps(self, obj: Any) -> bytes: ... - def loads(self, data: bytes) -> Any: - ... + def loads(self, data: bytes) -> Any: ... diff --git a/langgraph/version.py b/langgraph/version.py index ac7aeef6f..3368893c0 100644 --- a/langgraph/version.py +++ b/langgraph/version.py @@ -1,4 +1,5 @@ """Main entrypoint into package.""" + from importlib import metadata try: