From 55493f5d4539351da51e7c24b782b8565b37e524 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Thu, 18 Jan 2024 11:10:39 -0800 Subject: [PATCH] Filter from config_schema properties provided by Pregel class --- langgraph/pregel/__init__.py | 17 +++++++++++++---- langgraph/pregel/read.py | 3 +-- langgraph/pregel/write.py | 2 +- tests/test_pregel.py | 8 ++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/langgraph/pregel/__init__.py b/langgraph/pregel/__init__.py index 6a714f271..115e0cbf6 100644 --- a/langgraph/pregel/__init__.py +++ b/langgraph/pregel/__init__.py @@ -195,10 +195,19 @@ class Pregel( @property def config_specs(self) -> list[ConfigurableFieldSpec]: - return get_unique_config_specs( - [spec for node in self.nodes.values() for spec in node.config_specs] - + (self.checkpointer.config_specs if self.checkpointer is not None else []) - ) + return [ + spec + for spec in get_unique_config_specs( + [spec for node in self.nodes.values() for spec in node.config_specs] + + ( + self.checkpointer.config_specs + if self.checkpointer is not None + else [] + ) + ) + # these are provided by the Pregel class + if spec.id not in [CONFIG_KEY_READ, CONFIG_KEY_SEND] + ] @property def InputType(self) -> Any: diff --git a/langgraph/pregel/read.py b/langgraph/pregel/read.py index 78129b5b0..08903082e 100644 --- a/langgraph/pregel/read.py +++ b/langgraph/pregel/read.py @@ -19,7 +19,6 @@ from langchain_core.runnables.base import ( from langchain_core.runnables.config import merge_configs from langchain_core.runnables.utils import ConfigurableFieldSpec -from langgraph.channels.base import BaseChannel from langgraph.constants import CONFIG_KEY_READ @@ -34,7 +33,7 @@ class ChannelRead(RunnableLambda): name=CONFIG_KEY_READ, description=None, default=None, - annotation=Callable[[BaseChannel], Any], + annotation=None, ), ] diff --git a/langgraph/pregel/write.py b/langgraph/pregel/write.py index e44b3e3db..a43d8d876 100644 --- a/langgraph/pregel/write.py +++ b/langgraph/pregel/write.py @@ -43,7 +43,7 @@ class ChannelWrite(RunnablePassthrough): name=CONFIG_KEY_SEND, description=None, default=None, - annotation=TYPE_SEND, + annotation=None, ), ] diff --git a/tests/test_pregel.py b/tests/test_pregel.py index 0ad0b5752..1dc57988e 100644 --- a/tests/test_pregel.py +++ b/tests/test_pregel.py @@ -1,5 +1,6 @@ import operator import time +import warnings from concurrent.futures import ThreadPoolExecutor from contextlib import contextmanager from typing import Annotated, Generator, Optional, TypedDict, Union @@ -43,6 +44,13 @@ def test_invoke_single_process_in_out(mocker: MockerFixture) -> None: assert app.input_schema.schema() == {"title": "LangGraphInput", "type": "integer"} assert app.output_schema.schema() == {"title": "LangGraphOutput", "type": "integer"} + with warnings.catch_warnings(): + warnings.simplefilter("error") # raise warnings as errors + assert app.config_schema().schema() == { + "properties": {}, + "title": "LangGraphConfig", + "type": "object", + } assert app.invoke(2) == 3 assert app.invoke(2, output_keys=["output"]) == {"output": 3} assert repr(app), "does not raise recursion error"