From d935a2d110b5d4de61be4aa9a9448542ac35755b Mon Sep 17 00:00:00 2001 From: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com> Date: Tue, 15 Jul 2025 16:13:34 -0400 Subject: [PATCH] refactor(langgraph): move typing constructs in `constants.py` -> `_internal/_typing.py` (#5518) --- libs/langgraph/langgraph/_internal/_fields.py | 4 +--- libs/langgraph/langgraph/_internal/_runnable.py | 10 +++++----- libs/langgraph/langgraph/_internal/_typing.py | 12 ++++++------ libs/langgraph/langgraph/channels/any_value.py | 6 +++++- libs/langgraph/langgraph/channels/base.py | 12 +++++++----- libs/langgraph/langgraph/channels/binop.py | 2 +- .../langgraph/channels/ephemeral_value.py | 7 ++++++- libs/langgraph/langgraph/channels/last_value.py | 15 +++++++++++---- .../langgraph/channels/named_barrier_value.py | 2 +- libs/langgraph/langgraph/channels/topic.py | 2 +- .../langgraph/channels/untracked_value.py | 11 ++++++++--- libs/langgraph/langgraph/constants.py | 4 ---- libs/langgraph/langgraph/func/__init__.py | 8 ++++---- libs/langgraph/langgraph/graph/_node.py | 2 +- libs/langgraph/langgraph/graph/state.py | 14 ++++++-------- libs/langgraph/langgraph/pregel/_algo.py | 3 +-- libs/langgraph/langgraph/pregel/_checkpoint.py | 2 +- libs/langgraph/langgraph/pregel/_io.py | 3 +-- libs/langgraph/langgraph/pregel/_loop.py | 3 +-- libs/langgraph/langgraph/pregel/_runner.py | 2 +- libs/langgraph/langgraph/pregel/_write.py | 3 ++- libs/langgraph/langgraph/pregel/debug.py | 2 +- libs/langgraph/langgraph/types.py | 4 ++-- libs/langgraph/tests/test_channels.py | 2 +- .../langgraph/prebuilt/chat_agent_executor.py | 6 ++++-- 25 files changed, 78 insertions(+), 63 deletions(-) diff --git a/libs/langgraph/langgraph/_internal/_fields.py b/libs/langgraph/langgraph/_internal/_fields.py index 5b9c8dca6..6979678d1 100644 --- a/libs/langgraph/langgraph/_internal/_fields.py +++ b/libs/langgraph/langgraph/_internal/_fields.py @@ -9,9 +9,7 @@ from typing import Annotated, Any, Optional, Union, get_type_hints from pydantic import BaseModel from typing_extensions import NotRequired, ReadOnly, Required, get_origin -# NOTE: this is redefined here separately from langgraph.constants -# to avoid a circular import -MISSING = object() +from langgraph._internal._typing import MISSING def _is_optional_type(type_: Any) -> bool: diff --git a/libs/langgraph/langgraph/_internal/_runnable.py b/libs/langgraph/langgraph/_internal/_runnable.py index 9a4b76ea0..22d1b0515 100644 --- a/libs/langgraph/langgraph/_internal/_runnable.py +++ b/libs/langgraph/langgraph/_internal/_runnable.py @@ -48,7 +48,7 @@ from langgraph._internal._config import ( get_callback_manager_for_config, patch_config, ) -from langgraph._internal._typing import UNSET +from langgraph._internal._typing import MISSING from langgraph.constants import ( CONF, CONFIG_KEY_RUNTIME, @@ -335,7 +335,7 @@ class RunnableCallable(Runnable): if kw in kwargs: continue - kw_value: Any = UNSET + kw_value: Any = MISSING if kw == "config": kw_value = config elif runtime: @@ -347,7 +347,7 @@ class RunnableCallable(Runnable): except AttributeError: pass - if kw_value is UNSET: + if kw_value is MISSING: if default is inspect.Parameter.empty: raise ValueError( f"Missing required config key '{runtime_key}' for '{self.name}'." @@ -407,7 +407,7 @@ class RunnableCallable(Runnable): if kw in kwargs: continue - kw_value: Any = UNSET + kw_value: Any = MISSING if kw == "config": kw_value = config elif runtime: @@ -418,7 +418,7 @@ class RunnableCallable(Runnable): kw_value = getattr(runtime, runtime_key) except AttributeError: pass - if kw_value is UNSET: + if kw_value is MISSING: if default is inspect.Parameter.empty: raise ValueError( f"Missing required config key '{runtime_key}' for '{self.name}'." diff --git a/libs/langgraph/langgraph/_internal/_typing.py b/libs/langgraph/langgraph/_internal/_typing.py index 79b5478d0..02adb3364 100644 --- a/libs/langgraph/langgraph/_internal/_typing.py +++ b/libs/langgraph/langgraph/_internal/_typing.py @@ -42,13 +42,13 @@ It can either be a `TypedDict`, `dataclass`, or Pydantic `BaseModel`. Note: we cannot use either `TypedDict` or `dataclass` directly due to limitations in type checking. """ - -class Unset: - """A sentinel value to represent an unset type.""" - - -UNSET: Unset = Unset() +MISSING = object() +"""Unset sentinel value.""" class DeprecatedKwargs(TypedDict): """TypedDict to use for extra keyword arguments, enabling type checking warnings for deprecated arguments.""" + + +EMPTY_SEQ: tuple[str, ...] = tuple() +"""An empty sequence of strings.""" diff --git a/libs/langgraph/langgraph/channels/any_value.py b/libs/langgraph/langgraph/channels/any_value.py index 18b008a34..9ba255574 100644 --- a/libs/langgraph/langgraph/channels/any_value.py +++ b/libs/langgraph/langgraph/channels/any_value.py @@ -1,10 +1,12 @@ +from __future__ import annotations + from collections.abc import Sequence from typing import Any, Generic from typing_extensions import Self +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel, Value -from langgraph.constants import MISSING from langgraph.errors import EmptyChannelError __all__ = ("AnyValue",) @@ -16,6 +18,8 @@ class AnyValue(Generic[Value], BaseChannel[Value, Value, Value]): __slots__ = ("typ", "value") + value: Value | Any + def __init__(self, typ: Any, key: str = "") -> None: super().__init__(typ, key) self.value = MISSING diff --git a/libs/langgraph/langgraph/channels/base.py b/libs/langgraph/langgraph/channels/base.py index 5f6ae3f1a..2d00da64f 100644 --- a/libs/langgraph/langgraph/channels/base.py +++ b/libs/langgraph/langgraph/channels/base.py @@ -1,20 +1,22 @@ +from __future__ import annotations + from abc import ABC, abstractmethod from collections.abc import Sequence from typing import Any, Generic, TypeVar from typing_extensions import Self -from langgraph.constants import MISSING +from langgraph._internal._typing import MISSING from langgraph.errors import EmptyChannelError Value = TypeVar("Value") Update = TypeVar("Update") -C = TypeVar("C") +Checkpoint = TypeVar("Checkpoint") __all__ = ("BaseChannel",) -class BaseChannel(Generic[Value, Update, C], ABC): +class BaseChannel(Generic[Value, Update, Checkpoint], ABC): """Base class for all channels.""" __slots__ = ("key", "typ") @@ -41,7 +43,7 @@ class BaseChannel(Generic[Value, Update, C], ABC): Subclasses can override this method with a more efficient implementation.""" return self.from_checkpoint(self.checkpoint()) - def checkpoint(self) -> C: + def checkpoint(self) -> Checkpoint | Any: """Return a serializable representation of the channel's current state. Raises EmptyChannelError if the channel is empty (never updated yet), or doesn't support checkpoints.""" @@ -51,7 +53,7 @@ class BaseChannel(Generic[Value, Update, C], ABC): return MISSING @abstractmethod - def from_checkpoint(self, checkpoint: C) -> Self: + def from_checkpoint(self, checkpoint: Checkpoint | Any) -> Self: """Return a new identical channel, optionally initialized from a checkpoint. If the checkpoint contains complex data structures, they should be copied.""" diff --git a/libs/langgraph/langgraph/channels/binop.py b/libs/langgraph/langgraph/channels/binop.py index 6b34b5533..d47c4e049 100644 --- a/libs/langgraph/langgraph/channels/binop.py +++ b/libs/langgraph/langgraph/channels/binop.py @@ -4,8 +4,8 @@ from typing import Callable, Generic from typing_extensions import NotRequired, Required, Self +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel, Value -from langgraph.constants import MISSING from langgraph.errors import EmptyChannelError __all__ = ("BinaryOperatorAggregate",) diff --git a/libs/langgraph/langgraph/channels/ephemeral_value.py b/libs/langgraph/langgraph/channels/ephemeral_value.py index 98d4f41dd..108588d0b 100644 --- a/libs/langgraph/langgraph/channels/ephemeral_value.py +++ b/libs/langgraph/langgraph/channels/ephemeral_value.py @@ -1,10 +1,12 @@ +from __future__ import annotations + from collections.abc import Sequence from typing import Any, Generic from typing_extensions import Self +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel, Value -from langgraph.constants import MISSING from langgraph.errors import EmptyChannelError, InvalidUpdateError __all__ = ("EphemeralValue",) @@ -15,6 +17,9 @@ class EphemeralValue(Generic[Value], BaseChannel[Value, Value, Value]): __slots__ = ("value", "guard") + value: Value | Any + guard: bool + def __init__(self, typ: Any, guard: bool = True) -> None: super().__init__(typ) self.guard = guard diff --git a/libs/langgraph/langgraph/channels/last_value.py b/libs/langgraph/langgraph/channels/last_value.py index 1c07fc7ab..54caac758 100644 --- a/libs/langgraph/langgraph/channels/last_value.py +++ b/libs/langgraph/langgraph/channels/last_value.py @@ -1,10 +1,12 @@ +from __future__ import annotations + from collections.abc import Sequence from typing import Any, Generic from typing_extensions import Self +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel, Value -from langgraph.constants import MISSING from langgraph.errors import ( EmptyChannelError, ErrorCode, @@ -20,6 +22,8 @@ class LastValue(Generic[Value], BaseChannel[Value, Value, Value]): __slots__ = ("value",) + value: Value | Any + def __init__(self, typ: Any, key: str = "") -> None: super().__init__(typ, key) self.value = MISSING @@ -82,6 +86,9 @@ class LastValueAfterFinish( __slots__ = ("value", "finished") + value: Value | Any + finished: bool + def __init__(self, typ: Any, key: str = "") -> None: super().__init__(typ, key) self.value = MISSING @@ -100,19 +107,19 @@ class LastValueAfterFinish( """The type of the update received by the channel.""" return self.typ - def checkpoint(self) -> tuple[Value, bool]: + def checkpoint(self) -> tuple[Value | Any, bool] | Any: if self.value is MISSING: return MISSING return (self.value, self.finished) - def from_checkpoint(self, checkpoint: tuple[Value, bool]) -> Self: + def from_checkpoint(self, checkpoint: tuple[Value | Any, bool] | Any) -> Self: empty = self.__class__(self.typ) empty.key = self.key if checkpoint is not MISSING: empty.value, empty.finished = checkpoint return empty - def update(self, values: Sequence[Value]) -> bool: + def update(self, values: Sequence[Value | Any]) -> bool: if len(values) == 0: return False diff --git a/libs/langgraph/langgraph/channels/named_barrier_value.py b/libs/langgraph/langgraph/channels/named_barrier_value.py index 7f9c8baa0..d45644110 100644 --- a/libs/langgraph/langgraph/channels/named_barrier_value.py +++ b/libs/langgraph/langgraph/channels/named_barrier_value.py @@ -3,8 +3,8 @@ from typing import Generic from typing_extensions import Self +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel, Value -from langgraph.constants import MISSING from langgraph.errors import EmptyChannelError, InvalidUpdateError __all__ = ("NamedBarrierValue", "NamedBarrierValueAfterFinish") diff --git a/libs/langgraph/langgraph/channels/topic.py b/libs/langgraph/langgraph/channels/topic.py index 4b9113570..917798ff2 100644 --- a/libs/langgraph/langgraph/channels/topic.py +++ b/libs/langgraph/langgraph/channels/topic.py @@ -5,8 +5,8 @@ from typing import Any, Generic, Union from typing_extensions import Self +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel, Value -from langgraph.constants import MISSING from langgraph.errors import EmptyChannelError __all__ = ("Topic",) diff --git a/libs/langgraph/langgraph/channels/untracked_value.py b/libs/langgraph/langgraph/channels/untracked_value.py index e339920dc..bcd55186b 100644 --- a/libs/langgraph/langgraph/channels/untracked_value.py +++ b/libs/langgraph/langgraph/channels/untracked_value.py @@ -1,10 +1,12 @@ +from __future__ import annotations + from collections.abc import Sequence -from typing import Generic +from typing import Any, Generic from typing_extensions import Self +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel, Value -from langgraph.constants import MISSING from langgraph.errors import EmptyChannelError, InvalidUpdateError __all__ = ("UntrackedValue",) @@ -15,6 +17,9 @@ class UntrackedValue(Generic[Value], BaseChannel[Value, Value, Value]): __slots__ = ("value", "guard") + guard: bool + value: Value | Any + def __init__(self, typ: type[Value], guard: bool = True) -> None: super().__init__(typ) self.guard = guard @@ -40,7 +45,7 @@ class UntrackedValue(Generic[Value], BaseChannel[Value, Value, Value]): empty.value = self.value return empty - def checkpoint(self) -> Value: + def checkpoint(self) -> Value | Any: return MISSING def from_checkpoint(self, checkpoint: Value) -> Self: diff --git a/libs/langgraph/langgraph/constants.py b/libs/langgraph/langgraph/constants.py index 94ed8646e..726f15e45 100644 --- a/libs/langgraph/langgraph/constants.py +++ b/libs/langgraph/langgraph/constants.py @@ -31,10 +31,6 @@ def __getattr__(name: str) -> Any: raise AttributeError(f"module has no attribute '{name}'") -# --- Empty read-only containers --- -EMPTY_SEQ: tuple[str, ...] = tuple() -MISSING = object() - # --- Public constants --- TAG_NOSTREAM = sys.intern("nostream") """Tag to disable streaming for a chat model.""" diff --git a/libs/langgraph/langgraph/func/__init__.py b/libs/langgraph/langgraph/func/__init__.py index f31b82948..d1e6d07bf 100644 --- a/libs/langgraph/langgraph/func/__init__.py +++ b/libs/langgraph/langgraph/func/__init__.py @@ -20,7 +20,7 @@ from typing import ( from typing_extensions import Unpack -from langgraph._internal._typing import UNSET, DeprecatedKwargs +from langgraph._internal._typing import MISSING, DeprecatedKwargs from langgraph.cache.base import BaseCache from langgraph.channels.ephemeral_value import EphemeralValue from langgraph.channels.last_value import LastValue @@ -180,7 +180,7 @@ def task( await add_one.ainvoke([1, 2, 3]) # Returns [2, 3, 4] ``` """ - if (retry := kwargs.get("retry", UNSET)) is not UNSET: + if (retry := kwargs.get("retry", MISSING)) is not MISSING: warnings.warn( "`retry` is deprecated and will be removed. Please use `retry_policy` instead.", category=LangGraphDeprecatedSinceV05, @@ -383,7 +383,7 @@ class entrypoint(Generic[ContextT]): **kwargs: Unpack[DeprecatedKwargs], ) -> None: """Initialize the entrypoint decorator.""" - if (config_schema := kwargs.get("config_schema", UNSET)) is not UNSET: + if (config_schema := kwargs.get("config_schema", MISSING)) is not MISSING: warnings.warn( "`config_schema` is deprecated and will be removed. Please use `context_schema` instead.", category=LangGraphDeprecatedSinceV10, @@ -392,7 +392,7 @@ class entrypoint(Generic[ContextT]): if context_schema is None: context_schema = cast(type[ContextT], config_schema) - if (retry := kwargs.get("retry", UNSET)) is not UNSET: + if (retry := kwargs.get("retry", MISSING)) is not MISSING: warnings.warn( "`retry` is deprecated and will be removed. Please use `retry_policy` instead.", category=LangGraphDeprecatedSinceV05, diff --git a/libs/langgraph/langgraph/graph/_node.py b/libs/langgraph/langgraph/graph/_node.py index 48ecf683b..a21f14de5 100644 --- a/libs/langgraph/langgraph/graph/_node.py +++ b/libs/langgraph/langgraph/graph/_node.py @@ -8,7 +8,7 @@ from typing import Any, Generic, Protocol, Union from langchain_core.runnables import Runnable, RunnableConfig from typing_extensions import TypeAlias -from langgraph.constants import EMPTY_SEQ +from langgraph._internal._typing import EMPTY_SEQ from langgraph.runtime import Runtime from langgraph.store.base import BaseStore from langgraph.types import CachePolicy, RetryPolicy, StreamWriter diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index 78d33a804..a4654a8c2 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -34,7 +34,7 @@ from langgraph._internal._fields import ( ) from langgraph._internal._pydantic import create_model from langgraph._internal._runnable import coerce_to_runnable -from langgraph._internal._typing import UNSET, DeprecatedKwargs +from langgraph._internal._typing import EMPTY_SEQ, MISSING, DeprecatedKwargs from langgraph.cache.base import BaseCache from langgraph.channels.base import BaseChannel from langgraph.channels.binop import BinaryOperatorAggregate @@ -46,10 +46,8 @@ from langgraph.channels.named_barrier_value import ( ) from langgraph.checkpoint.base import Checkpoint from langgraph.constants import ( - EMPTY_SEQ, END, INTERRUPT, - MISSING, NS_END, NS_SEP, START, @@ -193,7 +191,7 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): output_schema: type[OutputT] | None = None, **kwargs: Unpack[DeprecatedKwargs], ) -> None: - if (config_schema := kwargs.get("config_schema", UNSET)) is not UNSET: + if (config_schema := kwargs.get("config_schema", MISSING)) is not MISSING: warnings.warn( "`config_schema` is deprecated and will be removed. Please use `context_schema` instead.", category=LangGraphDeprecatedSinceV10, @@ -202,7 +200,7 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): if context_schema is None: context_schema = cast(type[ContextT], config_schema) - if (input_ := kwargs.get("input", UNSET)) is not UNSET: + if (input_ := kwargs.get("input", MISSING)) is not MISSING: warnings.warn( "`input` is deprecated and will be removed. Please use `input_schema` instead.", category=LangGraphDeprecatedSinceV05, @@ -211,7 +209,7 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): if input_schema is None: input_schema = cast(type[InputT], input_) - if (output := kwargs.get("output", UNSET)) is not UNSET: + if (output := kwargs.get("output", MISSING)) is not MISSING: warnings.warn( "`output` is deprecated and will be removed. Please use `output_schema` instead.", category=LangGraphDeprecatedSinceV05, @@ -412,7 +410,7 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): Returns: Self: The instance of the state graph, allowing for method chaining. """ - if (retry := kwargs.get("retry", UNSET)) is not UNSET: + if (retry := kwargs.get("retry", MISSING)) is not MISSING: warnings.warn( "`retry` is deprecated and will be removed. Please use `retry_policy` instead.", category=LangGraphDeprecatedSinceV05, @@ -420,7 +418,7 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): if retry_policy is None: retry_policy = retry # type: ignore[assignment] - if (input_ := kwargs.get("input", UNSET)) is not UNSET: + if (input_ := kwargs.get("input", MISSING)) is not MISSING: warnings.warn( "`input` is deprecated and will be removed. Please use `input_schema` instead.", category=LangGraphDeprecatedSinceV05, diff --git a/libs/langgraph/langgraph/pregel/_algo.py b/libs/langgraph/langgraph/pregel/_algo.py index 14ff02fd4..c813a6805 100644 --- a/libs/langgraph/langgraph/pregel/_algo.py +++ b/libs/langgraph/langgraph/pregel/_algo.py @@ -27,6 +27,7 @@ from xxhash import xxh3_128_hexdigest from langgraph._internal._config import merge_configs, patch_config from langgraph._internal._runtime import patch_runtime_non_null +from langgraph._internal._typing import EMPTY_SEQ, MISSING from langgraph.channels.base import BaseChannel from langgraph.channels.topic import Topic from langgraph.checkpoint.base import ( @@ -49,10 +50,8 @@ from langgraph.constants import ( CONFIG_KEY_SCRATCHPAD, CONFIG_KEY_SEND, CONFIG_KEY_TASK_ID, - EMPTY_SEQ, ERROR, INTERRUPT, - MISSING, NO_WRITES, NS_END, NS_SEP, diff --git a/libs/langgraph/langgraph/pregel/_checkpoint.py b/libs/langgraph/langgraph/pregel/_checkpoint.py index b404ee550..50eb254b8 100644 --- a/libs/langgraph/langgraph/pregel/_checkpoint.py +++ b/libs/langgraph/langgraph/pregel/_checkpoint.py @@ -3,10 +3,10 @@ from __future__ import annotations from collections.abc import Mapping from datetime import datetime, timezone +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel from langgraph.checkpoint.base import Checkpoint from langgraph.checkpoint.base.id import uuid6 -from langgraph.constants import MISSING from langgraph.managed.base import ManagedValueMapping, ManagedValueSpec LATEST_VERSION = 4 diff --git a/libs/langgraph/langgraph/pregel/_io.py b/libs/langgraph/langgraph/pregel/_io.py index 3eff58c8a..a5af16c23 100644 --- a/libs/langgraph/langgraph/pregel/_io.py +++ b/libs/langgraph/langgraph/pregel/_io.py @@ -4,12 +4,11 @@ from collections import Counter from collections.abc import Iterator, Mapping, Sequence from typing import Any, Literal +from langgraph._internal._typing import EMPTY_SEQ, MISSING from langgraph.channels.base import BaseChannel, EmptyChannelError from langgraph.constants import ( - EMPTY_SEQ, ERROR, INTERRUPT, - MISSING, NULL_TASK_ID, RESUME, RETURN, diff --git a/libs/langgraph/langgraph/pregel/_loop.py b/libs/langgraph/langgraph/pregel/_loop.py index 7dc2ec5dc..7b1663d15 100644 --- a/libs/langgraph/langgraph/pregel/_loop.py +++ b/libs/langgraph/langgraph/pregel/_loop.py @@ -28,6 +28,7 @@ from langchain_core.runnables import RunnableConfig from typing_extensions import ParamSpec, Self from langgraph._internal._config import patch_configurable +from langgraph._internal._typing import EMPTY_SEQ, MISSING from langgraph.cache.base import BaseCache from langgraph.channels.base import BaseChannel from langgraph.checkpoint.base import ( @@ -50,11 +51,9 @@ from langgraph.constants import ( CONFIG_KEY_STREAM, CONFIG_KEY_TASK_ID, CONFIG_KEY_THREAD_ID, - EMPTY_SEQ, ERROR, INPUT, INTERRUPT, - MISSING, NS_END, NS_SEP, NULL_TASK_ID, diff --git a/libs/langgraph/langgraph/pregel/_runner.py b/libs/langgraph/langgraph/pregel/_runner.py index 9c29eabca..835525a76 100644 --- a/libs/langgraph/langgraph/pregel/_runner.py +++ b/libs/langgraph/langgraph/pregel/_runner.py @@ -20,13 +20,13 @@ from typing import ( from langchain_core.callbacks import Callbacks from langgraph._internal._future import chain_future, run_coroutine_threadsafe +from langgraph._internal._typing import MISSING from langgraph.constants import ( CONF, CONFIG_KEY_CALL, CONFIG_KEY_SCRATCHPAD, ERROR, INTERRUPT, - MISSING, NO_WRITES, RESUME, RETURN, diff --git a/libs/langgraph/langgraph/pregel/_write.py b/libs/langgraph/langgraph/pregel/_write.py index d16de35a2..dcefb2a36 100644 --- a/libs/langgraph/langgraph/pregel/_write.py +++ b/libs/langgraph/langgraph/pregel/_write.py @@ -14,7 +14,8 @@ from typing import ( from langchain_core.runnables import Runnable, RunnableConfig from langgraph._internal._runnable import RunnableCallable -from langgraph.constants import CONF, CONFIG_KEY_SEND, MISSING, TASKS +from langgraph._internal._typing import MISSING +from langgraph.constants import CONF, CONFIG_KEY_SEND, TASKS from langgraph.errors import InvalidUpdateError from langgraph.types import Send diff --git a/libs/langgraph/langgraph/pregel/debug.py b/libs/langgraph/langgraph/pregel/debug.py index 0ccc168d0..aeaf99ad7 100644 --- a/libs/langgraph/langgraph/pregel/debug.py +++ b/libs/langgraph/langgraph/pregel/debug.py @@ -9,6 +9,7 @@ from langchain_core.runnables import RunnableConfig from typing_extensions import TypedDict from langgraph._internal._config import patch_checkpoint_map +from langgraph._internal._typing import MISSING from langgraph.channels.base import BaseChannel from langgraph.checkpoint.base import CheckpointMetadata, PendingWrite from langgraph.constants import ( @@ -16,7 +17,6 @@ from langgraph.constants import ( CONFIG_KEY_CHECKPOINT_NS, ERROR, INTERRUPT, - MISSING, NS_END, NS_SEP, RETURN, diff --git a/libs/langgraph/langgraph/types.py b/libs/langgraph/langgraph/types.py index 69489bd86..95c2d708d 100644 --- a/libs/langgraph/langgraph/types.py +++ b/libs/langgraph/langgraph/types.py @@ -25,7 +25,7 @@ from xxhash import xxh3_128_hexdigest from langgraph._internal._cache import default_cache_key from langgraph._internal._fields import get_cached_annotated_keys, get_update_as_tuples from langgraph._internal._retry import default_retry_on -from langgraph._internal._typing import UNSET, DeprecatedKwargs +from langgraph._internal._typing import MISSING, DeprecatedKwargs from langgraph.checkpoint.base import BaseCheckpointSaver, CheckpointMetadata from langgraph.warnings import LangGraphDeprecatedSinceV10 @@ -157,7 +157,7 @@ class Interrupt: self.value = value if ( - (ns := deprecated_kwargs.get("ns", UNSET)) is not UNSET + (ns := deprecated_kwargs.get("ns", MISSING)) is not MISSING and (id == _DEFAULT_INTERRUPT_ID) and (isinstance(ns, Sequence)) ): diff --git a/libs/langgraph/tests/test_channels.py b/libs/langgraph/tests/test_channels.py index c8d679ab8..76254c504 100644 --- a/libs/langgraph/tests/test_channels.py +++ b/libs/langgraph/tests/test_channels.py @@ -4,10 +4,10 @@ from typing import Union import pytest +from langgraph._internal._typing import MISSING from langgraph.channels.binop import BinaryOperatorAggregate from langgraph.channels.last_value import LastValue from langgraph.channels.topic import Topic -from langgraph.constants import MISSING from langgraph.errors import EmptyChannelError, InvalidUpdateError pytestmark = pytest.mark.anyio diff --git a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py index 06efc8834..ee86d0ad8 100644 --- a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py @@ -36,7 +36,7 @@ from pydantic import BaseModel from typing_extensions import Annotated, TypedDict from langgraph._internal._runnable import RunnableCallable, RunnableLike -from langgraph._internal._typing import UNSET +from langgraph._internal._typing import MISSING from langgraph.errors import ErrorCode, create_error_message from langgraph.graph import END, StateGraph from langgraph.graph.message import add_messages @@ -405,7 +405,9 @@ def create_react_agent( print(chunk) ``` """ - if (config_schema := deprecated_kwargs.pop("config_schema", UNSET)) is not UNSET: + if ( + config_schema := deprecated_kwargs.pop("config_schema", MISSING) + ) is not MISSING: warn( "`config_schema` is no longer supported. Use `context_schema` instead.", category=LangGraphDeprecatedSinceV10,