diff --git a/docs/docs/reference/constants.md b/docs/docs/reference/constants.md index f23e941fa..fe26ce727 100644 --- a/docs/docs/reference/constants.md +++ b/docs/docs/reference/constants.md @@ -2,5 +2,6 @@ options: members: - TAG_HIDDEN + - TAG_NOSTREAM - START - - END \ No newline at end of file + - END diff --git a/libs/langgraph/langgraph/_internal/_config.py b/libs/langgraph/langgraph/_internal/_config.py index 1c1428bb0..0b4739c98 100644 --- a/libs/langgraph/langgraph/_internal/_config.py +++ b/libs/langgraph/langgraph/_internal/_config.py @@ -18,8 +18,7 @@ from langchain_core.runnables.config import ( var_child_runnable_config, ) -from langgraph.checkpoint.base import CheckpointMetadata -from langgraph.constants import ( +from langgraph._internal._constants import ( CONF, CONFIG_KEY_CHECKPOINT_ID, CONFIG_KEY_CHECKPOINT_MAP, @@ -27,6 +26,7 @@ from langgraph.constants import ( NS_END, NS_SEP, ) +from langgraph.checkpoint.base import CheckpointMetadata DEFAULT_RECURSION_LIMIT = int(getenv("LANGGRAPH_DEFAULT_RECURSION_LIMIT", "25")) diff --git a/libs/langgraph/langgraph/_internal/_constants.py b/libs/langgraph/langgraph/_internal/_constants.py new file mode 100644 index 000000000..82b44bc15 --- /dev/null +++ b/libs/langgraph/langgraph/_internal/_constants.py @@ -0,0 +1,110 @@ +"""Constants used for Pregel operations.""" + +import sys +from typing import Literal, cast + +# --- Reserved write keys --- +INPUT = sys.intern("__input__") +# for values passed as input to the graph +INTERRUPT = sys.intern("__interrupt__") +# for dynamic interrupts raised by nodes +RESUME = sys.intern("__resume__") +# for values passed to resume a node after an interrupt +ERROR = sys.intern("__error__") +# for errors raised by nodes +NO_WRITES = sys.intern("__no_writes__") +# marker to signal node didn't write anything +TASKS = sys.intern("__pregel_tasks") +# for Send objects returned by nodes/edges, corresponds to PUSH below +RETURN = sys.intern("__return__") +# for writes of a task where we simply record the return value +PREVIOUS = sys.intern("__previous__") +# the implicit branch that handles each node's Control values + + +# --- Reserved cache namespaces --- +CACHE_NS_WRITES = sys.intern("__pregel_ns_writes") +# cache namespace for node writes + +# --- Reserved config.configurable keys --- +CONFIG_KEY_SEND = sys.intern("__pregel_send") +# holds the `write` function that accepts writes to state/edges/reserved keys +CONFIG_KEY_READ = sys.intern("__pregel_read") +# holds the `read` function that returns a copy of the current state +CONFIG_KEY_CALL = sys.intern("__pregel_call") +# holds the `call` function that accepts a node/func, args and returns a future +CONFIG_KEY_CHECKPOINTER = sys.intern("__pregel_checkpointer") +# holds a `BaseCheckpointSaver` passed from parent graph to child graphs +CONFIG_KEY_STREAM = sys.intern("__pregel_stream") +# holds a `StreamProtocol` passed from parent graph to child graphs +CONFIG_KEY_CACHE = sys.intern("__pregel_cache") +# holds a `BaseCache` made available to subgraphs +CONFIG_KEY_RESUMING = sys.intern("__pregel_resuming") +# holds a boolean indicating if subgraphs should resume from a previous checkpoint +CONFIG_KEY_TASK_ID = sys.intern("__pregel_task_id") +# holds the task ID for the current task +CONFIG_KEY_THREAD_ID = sys.intern("thread_id") +# holds the thread ID for the current invocation +CONFIG_KEY_CHECKPOINT_MAP = sys.intern("checkpoint_map") +# holds a mapping of checkpoint_ns -> checkpoint_id for parent graphs +CONFIG_KEY_CHECKPOINT_ID = sys.intern("checkpoint_id") +# holds the current checkpoint_id, if any +CONFIG_KEY_CHECKPOINT_NS = sys.intern("checkpoint_ns") +# holds the current checkpoint_ns, "" for root graph +CONFIG_KEY_NODE_FINISHED = sys.intern("__pregel_node_finished") +# holds a callback to be called when a node is finished +CONFIG_KEY_SCRATCHPAD = sys.intern("__pregel_scratchpad") +# holds a mutable dict for temporary storage scoped to the current task +CONFIG_KEY_RUNNER_SUBMIT = sys.intern("__pregel_runner_submit") +# holds a function that receives tasks from runner, executes them and returns results +CONFIG_KEY_CHECKPOINT_DURING = sys.intern("__pregel_checkpoint_during") +# holds a boolean indicating whether to checkpoint during the run (or only at the end) +CONFIG_KEY_RUNTIME = sys.intern("__pregel_runtime") +# holds a `Runtime` instance with context, store, stream writer, etc. +CONFIG_KEY_RESUME_MAP = sys.intern("__pregel_resume_map") +# holds a mapping of task ns -> resume value for resuming tasks + +# --- Other constants --- +PUSH = sys.intern("__pregel_push") +# denotes push-style tasks, ie. those created by Send objects +PULL = sys.intern("__pregel_pull") +# denotes pull-style tasks, ie. those triggered by edges +NS_SEP = sys.intern("|") +# for checkpoint_ns, separates each level (ie. graph|subgraph|subsubgraph) +NS_END = sys.intern(":") +# for checkpoint_ns, for each level, separates the namespace from the task_id +CONF = cast(Literal["configurable"], sys.intern("configurable")) +# key for the configurable dict in RunnableConfig +NULL_TASK_ID = sys.intern("00000000-0000-0000-0000-000000000000") +# the task_id to use for writes that are not associated with a task + +# redefined to avoid circular import with langgraph.constants +_TAG_HIDDEN = sys.intern("langsmith:hidden") + +RESERVED = { + _TAG_HIDDEN, + # reserved write keys + INPUT, + INTERRUPT, + RESUME, + ERROR, + NO_WRITES, + # reserved config.configurable keys + CONFIG_KEY_SEND, + CONFIG_KEY_READ, + CONFIG_KEY_CHECKPOINTER, + CONFIG_KEY_STREAM, + CONFIG_KEY_CHECKPOINT_MAP, + CONFIG_KEY_RESUMING, + CONFIG_KEY_TASK_ID, + CONFIG_KEY_CHECKPOINT_MAP, + CONFIG_KEY_CHECKPOINT_ID, + CONFIG_KEY_CHECKPOINT_NS, + CONFIG_KEY_RESUME_MAP, + # other constants + PUSH, + PULL, + NS_SEP, + NS_END, + CONF, +} diff --git a/libs/langgraph/langgraph/_internal/_runnable.py b/libs/langgraph/langgraph/_internal/_runnable.py index 22d1b0515..efa0dc825 100644 --- a/libs/langgraph/langgraph/_internal/_runnable.py +++ b/libs/langgraph/langgraph/_internal/_runnable.py @@ -48,11 +48,11 @@ from langgraph._internal._config import ( get_callback_manager_for_config, patch_config, ) -from langgraph._internal._typing import MISSING -from langgraph.constants import ( +from langgraph._internal._constants import ( CONF, CONFIG_KEY_RUNTIME, ) +from langgraph._internal._typing import MISSING from langgraph.store.base import BaseStore from langgraph.types import StreamWriter diff --git a/libs/langgraph/langgraph/config.py b/libs/langgraph/langgraph/config.py index d5f9db8fb..660924e46 100644 --- a/libs/langgraph/langgraph/config.py +++ b/libs/langgraph/langgraph/config.py @@ -5,7 +5,7 @@ from typing import Any from langchain_core.runnables import RunnableConfig from langchain_core.runnables.config import var_child_runnable_config -from langgraph.constants import CONF, CONFIG_KEY_RUNTIME +from langgraph._internal._constants import CONF, CONFIG_KEY_RUNTIME from langgraph.store.base import BaseStore from langgraph.types import StreamWriter diff --git a/libs/langgraph/langgraph/constants.py b/libs/langgraph/langgraph/constants.py index 726f15e45..5b7e52aae 100644 --- a/libs/langgraph/langgraph/constants.py +++ b/libs/langgraph/langgraph/constants.py @@ -1,7 +1,12 @@ import sys -from typing import Any, Literal, cast +from typing import Any from warnings import warn +from langgraph._internal._constants import ( + CONF, + CONFIG_KEY_CHECKPOINTER, + TASKS, +) from langgraph.warnings import LangGraphDeprecatedSinceV10 __all__ = ( @@ -9,10 +14,22 @@ __all__ = ( "TAG_HIDDEN", "START", "END", - "SELF", - "PREVIOUS", + # retained for backwards compatibility (mostly langgraph-api), should be removed in v2 (or earlier) + "CONF", + "TASKS", + "CONFIG_KEY_CHECKPOINTER", ) +# --- Public constants --- +TAG_NOSTREAM = sys.intern("nostream") +"""Tag to disable streaming for a chat model.""" +TAG_HIDDEN = sys.intern("langsmith:hidden") +"""Tag to hide a node/edge from certain tracing/streaming environments.""" +END = sys.intern("__end__") +"""The last (maybe virtual) node in graph-style Pregel.""" +START = sys.intern("__start__") +"""The first (maybe virtual) node in graph-style Pregel.""" + def __getattr__(name: str) -> Any: if name in ["Send", "Interrupt"]: @@ -28,117 +45,20 @@ def __getattr__(name: str) -> Any: module = import_module("langgraph.types") return getattr(module, name) + try: + from importlib import import_module + + private_constants = import_module("langgraph._internal._constants") + attr = getattr(private_constants, name) + warn( + f"Importing {name} from langgraph.constants is deprecated. " + f"This constant is now private and should not be used directly. " + "Please let the LangGraph team know if you need this value.", + LangGraphDeprecatedSinceV10, + stacklevel=2, + ) + return attr + except AttributeError: + pass + raise AttributeError(f"module has no attribute '{name}'") - - -# --- Public constants --- -TAG_NOSTREAM = sys.intern("nostream") -"""Tag to disable streaming for a chat model.""" -TAG_HIDDEN = sys.intern("langsmith:hidden") -"""Tag to hide a node/edge from certain tracing/streaming environments.""" -START = sys.intern("__start__") -"""The first (maybe virtual) node in graph-style Pregel.""" -END = sys.intern("__end__") -"""The last (maybe virtual) node in graph-style Pregel.""" -SELF = sys.intern("__self__") -"""The implicit branch that handles each node's Control values.""" -PREVIOUS = sys.intern("__previous__") - -# --- Reserved write keys --- -INPUT = sys.intern("__input__") -# for values passed as input to the graph -INTERRUPT = sys.intern("__interrupt__") -# for dynamic interrupts raised by nodes -RESUME = sys.intern("__resume__") -# for values passed to resume a node after an interrupt -ERROR = sys.intern("__error__") -# for errors raised by nodes -NO_WRITES = sys.intern("__no_writes__") -# marker to signal node didn't write anything -TASKS = sys.intern("__pregel_tasks") -# for Send objects returned by nodes/edges, corresponds to PUSH below -RETURN = sys.intern("__return__") -# for writes of a task where we simply record the return value - -# --- Reserved cache namespaces --- -CACHE_NS_WRITES = sys.intern("__pregel_ns_writes") -# cache namespace for node writes - -# --- Reserved config.configurable keys --- -CONFIG_KEY_SEND = sys.intern("__pregel_send") -# holds the `write` function that accepts writes to state/edges/reserved keys -CONFIG_KEY_READ = sys.intern("__pregel_read") -# holds the `read` function that returns a copy of the current state -CONFIG_KEY_CALL = sys.intern("__pregel_call") -# holds the `call` function that accepts a node/func, args and returns a future -CONFIG_KEY_CHECKPOINTER = sys.intern("__pregel_checkpointer") -# holds a `BaseCheckpointSaver` passed from parent graph to child graphs -CONFIG_KEY_STREAM = sys.intern("__pregel_stream") -# holds a `StreamProtocol` passed from parent graph to child graphs -CONFIG_KEY_CACHE = sys.intern("__pregel_cache") -# holds a `BaseCache` made available to subgraphs -CONFIG_KEY_RESUMING = sys.intern("__pregel_resuming") -# holds a boolean indicating if subgraphs should resume from a previous checkpoint -CONFIG_KEY_TASK_ID = sys.intern("__pregel_task_id") -# holds the task ID for the current task -CONFIG_KEY_THREAD_ID = sys.intern("thread_id") -# holds the thread ID for the current invocation -CONFIG_KEY_CHECKPOINT_MAP = sys.intern("checkpoint_map") -# holds a mapping of checkpoint_ns -> checkpoint_id for parent graphs -CONFIG_KEY_CHECKPOINT_ID = sys.intern("checkpoint_id") -# holds the current checkpoint_id, if any -CONFIG_KEY_CHECKPOINT_NS = sys.intern("checkpoint_ns") -# holds the current checkpoint_ns, "" for root graph -CONFIG_KEY_NODE_FINISHED = sys.intern("__pregel_node_finished") -# holds a callback to be called when a node is finished -CONFIG_KEY_SCRATCHPAD = sys.intern("__pregel_scratchpad") -# holds a mutable dict for temporary storage scoped to the current task -CONFIG_KEY_RUNNER_SUBMIT = sys.intern("__pregel_runner_submit") -# holds a function that receives tasks from runner, executes them and returns results -CONFIG_KEY_CHECKPOINT_DURING = sys.intern("__pregel_checkpoint_during") -# holds a boolean indicating whether to checkpoint during the run (or only at the end) -CONFIG_KEY_RUNTIME = sys.intern("__pregel_runtime") -# holds a `Runtime` instance with context, store, stream writer, etc. - -# --- Other constants --- -PUSH = sys.intern("__pregel_push") -# denotes push-style tasks, ie. those created by Send objects -PULL = sys.intern("__pregel_pull") -# denotes pull-style tasks, ie. those triggered by edges -NS_SEP = sys.intern("|") -# for checkpoint_ns, separates each level (ie. graph|subgraph|subsubgraph) -NS_END = sys.intern(":") -# for checkpoint_ns, for each level, separates the namespace from the task_id -CONF = cast(Literal["configurable"], sys.intern("configurable")) -# key for the configurable dict in RunnableConfig -NULL_TASK_ID = sys.intern("00000000-0000-0000-0000-000000000000") -# the task_id to use for writes that are not associated with a task -CONFIG_KEY_RESUME_MAP = sys.intern("__pregel_resume_map") -# holds a mapping of task ns -> resume value for resuming tasks - -RESERVED = { - TAG_HIDDEN, - # reserved write keys - INPUT, - INTERRUPT, - RESUME, - ERROR, - NO_WRITES, - # reserved config.configurable keys - CONFIG_KEY_SEND, - CONFIG_KEY_READ, - CONFIG_KEY_CHECKPOINTER, - CONFIG_KEY_STREAM, - CONFIG_KEY_CHECKPOINT_MAP, - CONFIG_KEY_RESUMING, - CONFIG_KEY_TASK_ID, - CONFIG_KEY_CHECKPOINT_MAP, - CONFIG_KEY_CHECKPOINT_ID, - CONFIG_KEY_CHECKPOINT_NS, - # other constants - PUSH, - PULL, - NS_SEP, - NS_END, - CONF, -} diff --git a/libs/langgraph/langgraph/func/__init__.py b/libs/langgraph/langgraph/func/__init__.py index d1e6d07bf..d62995ab5 100644 --- a/libs/langgraph/langgraph/func/__init__.py +++ b/libs/langgraph/langgraph/func/__init__.py @@ -20,12 +20,13 @@ from typing import ( from typing_extensions import Unpack +from langgraph._internal._constants import CACHE_NS_WRITES, PREVIOUS 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 from langgraph.checkpoint.base import BaseCheckpointSaver -from langgraph.constants import CACHE_NS_WRITES, END, PREVIOUS, START +from langgraph.constants import END, START from langgraph.pregel import Pregel from langgraph.pregel._call import ( P, diff --git a/libs/langgraph/langgraph/graph/message.py b/libs/langgraph/langgraph/graph/message.py index fc3355eb6..e20c22185 100644 --- a/libs/langgraph/langgraph/graph/message.py +++ b/libs/langgraph/langgraph/graph/message.py @@ -24,7 +24,7 @@ from langchain_core.messages import ( ) from typing_extensions import TypedDict -from langgraph.constants import CONF, CONFIG_KEY_SEND +from langgraph._internal._constants import CONF, CONFIG_KEY_SEND, NS_SEP from langgraph.graph.state import StateGraph __all__ = ( @@ -320,7 +320,6 @@ def push_message( ) from langgraph.config import get_config - from langgraph.constants import NS_SEP from langgraph.pregel._messages import StreamMessagesHandler config = get_config() diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index a4654a8c2..40be8a8ee 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -27,6 +27,12 @@ from langchain_core.runnables import Runnable, RunnableConfig from pydantic import BaseModel, TypeAdapter from typing_extensions import Self, Unpack, is_typeddict +from langgraph._internal._constants import ( + INTERRUPT, + NS_END, + NS_SEP, + TASKS, +) from langgraph._internal._fields import ( get_cached_annotated_keys, get_field_default, @@ -45,15 +51,7 @@ from langgraph.channels.named_barrier_value import ( NamedBarrierValueAfterFinish, ) from langgraph.checkpoint.base import Checkpoint -from langgraph.constants import ( - END, - INTERRUPT, - NS_END, - NS_SEP, - START, - TAG_HIDDEN, - TASKS, -) +from langgraph.constants import END, START, TAG_HIDDEN from langgraph.errors import ( ErrorCode, InvalidUpdateError, diff --git a/libs/langgraph/langgraph/graph/ui.py b/libs/langgraph/langgraph/graph/ui.py index e829eff2e..f2fe5a1c2 100644 --- a/libs/langgraph/langgraph/graph/ui.py +++ b/libs/langgraph/langgraph/graph/ui.py @@ -7,7 +7,7 @@ from langchain_core.messages import AnyMessage from typing_extensions import TypedDict from langgraph.config import get_config, get_stream_writer -from langgraph.constants import CONF, CONFIG_KEY_SEND +from langgraph.constants import CONF __all__ = ( "UIMessage", @@ -96,6 +96,8 @@ def push_ui_message( ) """ + from langgraph._internal._constants import CONFIG_KEY_SEND + writer = get_stream_writer() config = get_config() @@ -148,6 +150,8 @@ def delete_ui_message(id: str, *, state_key: str = "ui") -> RemoveUIMessage: delete_ui_message("message-123") """ + from langgraph._internal._constants import CONFIG_KEY_SEND + writer = get_stream_writer() config = get_config() diff --git a/libs/langgraph/langgraph/pregel/_algo.py b/libs/langgraph/langgraph/pregel/_algo.py index c813a6805..adb8cdb64 100644 --- a/libs/langgraph/langgraph/pregel/_algo.py +++ b/libs/langgraph/langgraph/pregel/_algo.py @@ -26,18 +26,7 @@ from langchain_core.runnables.config import RunnableConfig 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 ( - BaseCheckpointSaver, - ChannelVersions, - Checkpoint, - PendingWrite, - V, -) -from langgraph.constants import ( +from langgraph._internal._constants import ( CACHE_NS_WRITES, CONF, CONFIG_KEY_CHECKPOINT_ID, @@ -62,9 +51,20 @@ from langgraph.constants import ( RESERVED, RESUME, RETURN, - TAG_HIDDEN, TASKS, ) +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 ( + BaseCheckpointSaver, + ChannelVersions, + Checkpoint, + PendingWrite, + V, +) +from langgraph.constants import TAG_HIDDEN from langgraph.managed.base import ManagedValueMapping from langgraph.pregel._call import get_runnable_for_task, identifier from langgraph.pregel._io import read_channels diff --git a/libs/langgraph/langgraph/pregel/_call.py b/libs/langgraph/langgraph/pregel/_call.py index 6bcd93f05..5956160aa 100644 --- a/libs/langgraph/langgraph/pregel/_call.py +++ b/libs/langgraph/langgraph/pregel/_call.py @@ -13,6 +13,7 @@ from typing import Any, Callable, Generic, TypeVar, cast from langchain_core.runnables import Runnable from typing_extensions import ParamSpec +from langgraph._internal._constants import CONF, CONFIG_KEY_CALL, RETURN from langgraph._internal._runnable import ( RunnableCallable, RunnableSeq, @@ -20,7 +21,6 @@ from langgraph._internal._runnable import ( run_in_executor, ) from langgraph.config import get_config -from langgraph.constants import CONF, CONFIG_KEY_CALL, RETURN from langgraph.pregel._write import ChannelWrite, ChannelWriteEntry from langgraph.types import CachePolicy, RetryPolicy diff --git a/libs/langgraph/langgraph/pregel/_config.py b/libs/langgraph/langgraph/pregel/_config.py new file mode 100644 index 000000000..e69de29bb diff --git a/libs/langgraph/langgraph/pregel/_draw.py b/libs/langgraph/langgraph/pregel/_draw.py index 9720f10e7..b8ae73389 100644 --- a/libs/langgraph/langgraph/pregel/_draw.py +++ b/libs/langgraph/langgraph/pregel/_draw.py @@ -7,9 +7,10 @@ from typing import Any, cast from langchain_core.runnables.config import RunnableConfig from langchain_core.runnables.graph import Graph, Node +from langgraph._internal._constants import CONF, CONFIG_KEY_SEND, INPUT from langgraph.channels.base import BaseChannel from langgraph.checkpoint.base import BaseCheckpointSaver -from langgraph.constants import CONF, CONFIG_KEY_SEND, END, INPUT, START +from langgraph.constants import END, START from langgraph.managed.base import ManagedValueSpec from langgraph.pregel._algo import ( PregelTaskWrites, diff --git a/libs/langgraph/langgraph/pregel/_io.py b/libs/langgraph/langgraph/pregel/_io.py index a5af16c23..3c05dbda7 100644 --- a/libs/langgraph/langgraph/pregel/_io.py +++ b/libs/langgraph/langgraph/pregel/_io.py @@ -4,18 +4,17 @@ 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 ( +from langgraph._internal._constants import ( ERROR, INTERRUPT, NULL_TASK_ID, RESUME, RETURN, - START, - TAG_HIDDEN, TASKS, ) +from langgraph._internal._typing import EMPTY_SEQ, MISSING +from langgraph.channels.base import BaseChannel, EmptyChannelError +from langgraph.constants import START, TAG_HIDDEN from langgraph.errors import InvalidUpdateError from langgraph.pregel._log import logger from langgraph.types import Command, PregelExecutableTask, Send diff --git a/libs/langgraph/langgraph/pregel/_loop.py b/libs/langgraph/langgraph/pregel/_loop.py index 7b1663d15..687b1d209 100644 --- a/libs/langgraph/langgraph/pregel/_loop.py +++ b/libs/langgraph/langgraph/pregel/_loop.py @@ -28,19 +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 ( - WRITES_IDX_MAP, - BaseCheckpointSaver, - ChannelVersions, - Checkpoint, - CheckpointMetadata, - CheckpointTuple, - PendingWrite, -) -from langgraph.constants import ( +from langgraph._internal._constants import ( CONF, CONFIG_KEY_CHECKPOINT_ID, CONFIG_KEY_CHECKPOINT_MAP, @@ -59,8 +47,20 @@ from langgraph.constants import ( NULL_TASK_ID, PUSH, RESUME, - TAG_HIDDEN, ) +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 ( + WRITES_IDX_MAP, + BaseCheckpointSaver, + ChannelVersions, + Checkpoint, + CheckpointMetadata, + CheckpointTuple, + PendingWrite, +) +from langgraph.constants import TAG_HIDDEN from langgraph.errors import ( EmptyInputError, GraphInterrupt, diff --git a/libs/langgraph/langgraph/pregel/_messages.py b/libs/langgraph/langgraph/pregel/_messages.py index b06991ba3..550ea789c 100644 --- a/libs/langgraph/langgraph/pregel/_messages.py +++ b/libs/langgraph/langgraph/pregel/_messages.py @@ -13,7 +13,8 @@ from langchain_core.callbacks import BaseCallbackHandler from langchain_core.messages import BaseMessage from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, LLMResult -from langgraph.constants import NS_SEP, TAG_HIDDEN, TAG_NOSTREAM +from langgraph._internal._constants import NS_SEP +from langgraph.constants import TAG_HIDDEN, TAG_NOSTREAM from langgraph.pregel.protocol import StreamChunk from langgraph.types import Command diff --git a/libs/langgraph/langgraph/pregel/_read.py b/libs/langgraph/langgraph/pregel/_read.py index a3edf2c31..bb3a6bf12 100644 --- a/libs/langgraph/langgraph/pregel/_read.py +++ b/libs/langgraph/langgraph/pregel/_read.py @@ -11,8 +11,8 @@ from typing import ( from langchain_core.runnables import Runnable, RunnableConfig from langgraph._internal._config import merge_configs +from langgraph._internal._constants import CONF, CONFIG_KEY_READ from langgraph._internal._runnable import RunnableCallable, RunnableSeq -from langgraph.constants import CONF, CONFIG_KEY_READ from langgraph.pregel._utils import find_subgraph_pregel from langgraph.pregel._write import ChannelWrite from langgraph.pregel.protocol import PregelProtocol diff --git a/libs/langgraph/langgraph/pregel/_retry.py b/libs/langgraph/langgraph/pregel/_retry.py index 4873e6824..d54797108 100644 --- a/libs/langgraph/langgraph/pregel/_retry.py +++ b/libs/langgraph/langgraph/pregel/_retry.py @@ -10,7 +10,7 @@ from dataclasses import replace from typing import Any, Callable from langgraph._internal._config import patch_configurable -from langgraph.constants import ( +from langgraph._internal._constants import ( CONF, CONFIG_KEY_CHECKPOINT_NS, CONFIG_KEY_RESUMING, diff --git a/libs/langgraph/langgraph/pregel/_runner.py b/libs/langgraph/langgraph/pregel/_runner.py index 835525a76..d38afcfd6 100644 --- a/libs/langgraph/langgraph/pregel/_runner.py +++ b/libs/langgraph/langgraph/pregel/_runner.py @@ -19,9 +19,7 @@ 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 ( +from langgraph._internal._constants import ( CONF, CONFIG_KEY_CALL, CONFIG_KEY_SCRATCHPAD, @@ -30,8 +28,10 @@ from langgraph.constants import ( NO_WRITES, RESUME, RETURN, - TAG_HIDDEN, ) +from langgraph._internal._future import chain_future, run_coroutine_threadsafe +from langgraph._internal._typing import MISSING +from langgraph.constants import TAG_HIDDEN from langgraph.errors import GraphBubbleUp, GraphInterrupt from langgraph.pregel._algo import Call from langgraph.pregel._executor import Submit diff --git a/libs/langgraph/langgraph/pregel/_validate.py b/libs/langgraph/langgraph/pregel/_validate.py index 9a8910703..fcfb54c9a 100644 --- a/libs/langgraph/langgraph/pregel/_validate.py +++ b/libs/langgraph/langgraph/pregel/_validate.py @@ -3,8 +3,8 @@ from __future__ import annotations from collections.abc import Mapping, Sequence from typing import Any +from langgraph._internal._constants import RESERVED from langgraph.channels.base import BaseChannel -from langgraph.constants import RESERVED from langgraph.managed.base import ManagedValueMapping from langgraph.pregel._read import PregelNode from langgraph.types import All diff --git a/libs/langgraph/langgraph/pregel/_write.py b/libs/langgraph/langgraph/pregel/_write.py index dcefb2a36..6a6e4b612 100644 --- a/libs/langgraph/langgraph/pregel/_write.py +++ b/libs/langgraph/langgraph/pregel/_write.py @@ -13,9 +13,9 @@ from typing import ( from langchain_core.runnables import Runnable, RunnableConfig +from langgraph._internal._constants import CONF, CONFIG_KEY_SEND, TASKS from langgraph._internal._runnable import RunnableCallable 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 aeaf99ad7..d6fb1d630 100644 --- a/libs/langgraph/langgraph/pregel/debug.py +++ b/libs/langgraph/langgraph/pregel/debug.py @@ -9,10 +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 ( +from langgraph._internal._constants import ( CONF, CONFIG_KEY_CHECKPOINT_NS, ERROR, @@ -20,8 +17,11 @@ from langgraph.constants import ( NS_END, NS_SEP, RETURN, - TAG_HIDDEN, ) +from langgraph._internal._typing import MISSING +from langgraph.channels.base import BaseChannel +from langgraph.checkpoint.base import CheckpointMetadata, PendingWrite +from langgraph.constants import TAG_HIDDEN from langgraph.pregel._io import read_channels from langgraph.types import PregelExecutableTask, PregelTask, StateSnapshot diff --git a/libs/langgraph/langgraph/pregel/main.py b/libs/langgraph/langgraph/pregel/main.py index 1d7324f65..22a02a88d 100644 --- a/libs/langgraph/langgraph/pregel/main.py +++ b/libs/langgraph/langgraph/pregel/main.py @@ -36,6 +36,31 @@ from langgraph._internal._config import ( patch_configurable, recast_checkpoint_ns, ) +from langgraph._internal._constants import ( + CACHE_NS_WRITES, + CONF, + CONFIG_KEY_CACHE, + CONFIG_KEY_CHECKPOINT_DURING, + CONFIG_KEY_CHECKPOINT_ID, + CONFIG_KEY_CHECKPOINT_NS, + CONFIG_KEY_CHECKPOINTER, + CONFIG_KEY_NODE_FINISHED, + CONFIG_KEY_READ, + CONFIG_KEY_RUNNER_SUBMIT, + CONFIG_KEY_RUNTIME, + CONFIG_KEY_SEND, + CONFIG_KEY_STREAM, + CONFIG_KEY_TASK_ID, + CONFIG_KEY_THREAD_ID, + ERROR, + INPUT, + INTERRUPT, + NS_END, + NS_SEP, + NULL_TASK_ID, + PUSH, + TASKS, +) from langgraph._internal._pydantic import create_model from langgraph._internal._queue import ( # type: ignore[attr-defined] AsyncQueue, @@ -57,32 +82,7 @@ from langgraph.checkpoint.base import ( CheckpointTuple, ) from langgraph.config import get_config -from langgraph.constants import ( - CACHE_NS_WRITES, - CONF, - CONFIG_KEY_CACHE, - CONFIG_KEY_CHECKPOINT_DURING, - CONFIG_KEY_CHECKPOINT_ID, - CONFIG_KEY_CHECKPOINT_NS, - CONFIG_KEY_CHECKPOINTER, - CONFIG_KEY_NODE_FINISHED, - CONFIG_KEY_READ, - CONFIG_KEY_RUNNER_SUBMIT, - CONFIG_KEY_RUNTIME, - CONFIG_KEY_SEND, - CONFIG_KEY_STREAM, - CONFIG_KEY_TASK_ID, - CONFIG_KEY_THREAD_ID, - END, - ERROR, - INPUT, - INTERRUPT, - NS_END, - NS_SEP, - NULL_TASK_ID, - PUSH, - TASKS, -) +from langgraph.constants import END from langgraph.errors import ( ErrorCode, GraphRecursionError, diff --git a/libs/langgraph/langgraph/pregel/remote.py b/libs/langgraph/langgraph/pregel/remote.py index c5e0e8dcd..837efa364 100644 --- a/libs/langgraph/langgraph/pregel/remote.py +++ b/libs/langgraph/langgraph/pregel/remote.py @@ -30,8 +30,7 @@ from langgraph_sdk.schema import StreamMode as StreamModeSDK from typing_extensions import Self from langgraph._internal._config import merge_configs -from langgraph.checkpoint.base import CheckpointMetadata -from langgraph.constants import ( +from langgraph._internal._constants import ( CONF, CONFIG_KEY_CHECKPOINT_ID, CONFIG_KEY_CHECKPOINT_MAP, @@ -41,6 +40,7 @@ from langgraph.constants import ( INTERRUPT, NS_SEP, ) +from langgraph.checkpoint.base import CheckpointMetadata from langgraph.errors import GraphInterrupt from langgraph.pregel.protocol import PregelProtocol, StreamProtocol from langgraph.types import ( diff --git a/libs/langgraph/langgraph/runtime.py b/libs/langgraph/langgraph/runtime.py index cfaa8dbe9..e793e007c 100644 --- a/libs/langgraph/langgraph/runtime.py +++ b/libs/langgraph/langgraph/runtime.py @@ -3,8 +3,8 @@ from __future__ import annotations from dataclasses import dataclass from typing import Any, Generic, cast +from langgraph._internal._constants import CONF, CONFIG_KEY_RUNTIME from langgraph.config import get_config -from langgraph.constants import CONF, CONFIG_KEY_RUNTIME from langgraph.store.base import BaseStore from langgraph.types import _DC_KWARGS, StreamWriter from langgraph.typing import ContextT diff --git a/libs/langgraph/langgraph/types.py b/libs/langgraph/langgraph/types.py index 95c2d708d..2cb6d58ab 100644 --- a/libs/langgraph/langgraph/types.py +++ b/libs/langgraph/langgraph/types.py @@ -473,13 +473,13 @@ def interrupt(value: Any) -> Any: Raises: GraphInterrupt: On the first invocation within the node, halts execution and surfaces the provided value to the client. """ - from langgraph.config import get_config - from langgraph.constants import ( + from langgraph._internal._constants import ( CONFIG_KEY_CHECKPOINT_NS, CONFIG_KEY_SCRATCHPAD, CONFIG_KEY_SEND, RESUME, ) + from langgraph.config import get_config from langgraph.errors import GraphInterrupt conf = get_config()["configurable"] diff --git a/libs/langgraph/tests/test_algo.py b/libs/langgraph/tests/test_algo.py index f32fa4334..0bf988173 100644 --- a/libs/langgraph/tests/test_algo.py +++ b/libs/langgraph/tests/test_algo.py @@ -1,4 +1,4 @@ -from langgraph.constants import PULL, PUSH +from langgraph._internal._constants import PULL, PUSH from langgraph.pregel._algo import prepare_next_tasks, task_path_str from langgraph.pregel._checkpoint import channels_from_checkpoint, empty_checkpoint diff --git a/libs/langgraph/tests/test_deprecation.py b/libs/langgraph/tests/test_deprecation.py index dee208c4b..d33b1a8ac 100644 --- a/libs/langgraph/tests/test_deprecation.py +++ b/libs/langgraph/tests/test_deprecation.py @@ -142,6 +142,7 @@ def test_config_type_deprecation_pregel(mocker: MockerFixture) -> None: ) +@pytest.mark.filterwarnings("ignore:`interrupt_id` is deprecated. Use `id` instead.") def test_interrupt_attributes_deprecation() -> None: interrupt = Interrupt(value="question", id="abc") @@ -152,9 +153,18 @@ def test_interrupt_attributes_deprecation() -> None: interrupt.interrupt_id +@pytest.mark.filterwarnings("ignore:NodeInterrupt is deprecated.") def test_node_interrupt_deprecation() -> None: with pytest.warns( LangGraphDeprecatedSinceV10, match="NodeInterrupt is deprecated. Please use `langgraph.types.interrupt` instead.", ): NodeInterrupt(value="test") + + +def test_deprecated_import() -> None: + with pytest.warns( + LangGraphDeprecatedSinceV10, + match="Importing PREVIOUS from langgraph.constants is deprecated. This constant is now private and should not be used directly.", + ): + from langgraph.constants import PREVIOUS # noqa: F401 diff --git a/libs/langgraph/tests/test_large_cases.py b/libs/langgraph/tests/test_large_cases.py index 419686255..463c4542f 100644 --- a/libs/langgraph/tests/test_large_cases.py +++ b/libs/langgraph/tests/test_large_cases.py @@ -11,11 +11,12 @@ from pytest_mock import MockerFixture from syrupy import SnapshotAssertion from typing_extensions import TypedDict +from langgraph._internal._constants import PULL, PUSH from langgraph.channels.last_value import LastValue from langgraph.channels.untracked_value import UntrackedValue from langgraph.checkpoint.base import BaseCheckpointSaver from langgraph.checkpoint.memory import InMemorySaver -from langgraph.constants import END, PULL, PUSH, START +from langgraph.constants import END, START from langgraph.graph import StateGraph from langgraph.graph.message import MessageGraph, MessagesState, add_messages from langgraph.prebuilt.chat_agent_executor import create_react_agent diff --git a/libs/langgraph/tests/test_large_cases_async.py b/libs/langgraph/tests/test_large_cases_async.py index 29f92d8b9..8be3e84c6 100644 --- a/libs/langgraph/tests/test_large_cases_async.py +++ b/libs/langgraph/tests/test_large_cases_async.py @@ -16,10 +16,11 @@ from langchain_core.runnables import RunnableConfig, RunnablePick from pytest_mock import MockerFixture from typing_extensions import TypedDict +from langgraph._internal._constants import PULL, PUSH from langgraph.channels.last_value import LastValue from langgraph.channels.untracked_value import UntrackedValue from langgraph.checkpoint.base import BaseCheckpointSaver -from langgraph.constants import END, PULL, PUSH, START +from langgraph.constants import END, START from langgraph.graph.message import MessageGraph, add_messages from langgraph.graph.state import StateGraph from langgraph.prebuilt.chat_agent_executor import create_react_agent diff --git a/libs/langgraph/tests/test_messages_state.py b/libs/langgraph/tests/test_messages_state.py index a481123a4..0a1e78ecb 100644 --- a/libs/langgraph/tests/test_messages_state.py +++ b/libs/langgraph/tests/test_messages_state.py @@ -14,9 +14,10 @@ from langchain_core.messages import ( from pydantic import BaseModel from typing_extensions import TypedDict +from langgraph.constants import END, START from langgraph.graph import add_messages from langgraph.graph.message import REMOVE_ALL_MESSAGES, MessagesState, push_message -from langgraph.graph.state import END, START, StateGraph +from langgraph.graph.state import StateGraph from tests.messages import _AnyIdHumanMessage _, CORE_MINOR, CORE_PATCH = (int(v) for v in langchain_core.__version__.split(".")) diff --git a/libs/langgraph/tests/test_pregel.py b/libs/langgraph/tests/test_pregel.py index a64f843da..df88212a0 100644 --- a/libs/langgraph/tests/test_pregel.py +++ b/libs/langgraph/tests/test_pregel.py @@ -28,6 +28,7 @@ from pytest_mock import MockerFixture from syrupy import SnapshotAssertion from typing_extensions import TypedDict +from langgraph._internal._constants import CONFIG_KEY_NODE_FINISHED, ERROR, PULL from langgraph.cache.base import BaseCache from langgraph.channels.binop import BinaryOperatorAggregate from langgraph.channels.ephemeral_value import EphemeralValue @@ -41,10 +42,9 @@ from langgraph.checkpoint.base import ( ) from langgraph.checkpoint.memory import InMemorySaver from langgraph.config import get_stream_writer -from langgraph.constants import CONFIG_KEY_NODE_FINISHED, ERROR, PULL, START from langgraph.errors import GraphRecursionError, InvalidUpdateError, ParentCommand from langgraph.func import entrypoint, task -from langgraph.graph import END, StateGraph +from langgraph.graph import END, START, StateGraph from langgraph.graph.message import MessageGraph, MessagesState, add_messages from langgraph.prebuilt.tool_node import ToolNode from langgraph.pregel import ( diff --git a/libs/langgraph/tests/test_pregel_async.py b/libs/langgraph/tests/test_pregel_async.py index b2e99af23..e81cb5e11 100644 --- a/libs/langgraph/tests/test_pregel_async.py +++ b/libs/langgraph/tests/test_pregel_async.py @@ -28,6 +28,7 @@ from pytest_mock import MockerFixture from syrupy import SnapshotAssertion from typing_extensions import TypedDict +from langgraph._internal._constants import CONFIG_KEY_NODE_FINISHED, ERROR, PULL from langgraph.cache.base import BaseCache from langgraph.channels.binop import BinaryOperatorAggregate from langgraph.channels.last_value import LastValue @@ -41,14 +42,13 @@ from langgraph.checkpoint.base import ( ) from langgraph.checkpoint.memory import InMemorySaver from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer -from langgraph.constants import CONFIG_KEY_NODE_FINISHED, ERROR, PULL, START from langgraph.errors import ( GraphRecursionError, InvalidUpdateError, ParentCommand, ) from langgraph.func import entrypoint, task -from langgraph.graph import END, StateGraph +from langgraph.graph import END, START, StateGraph from langgraph.graph.message import MessagesState, add_messages from langgraph.prebuilt.tool_node import ToolNode from langgraph.pregel import NodeBuilder, Pregel diff --git a/libs/langgraph/tests/test_utils.py b/libs/langgraph/tests/test_utils.py index fabac0595..afe486af2 100644 --- a/libs/langgraph/tests/test_utils.py +++ b/libs/langgraph/tests/test_utils.py @@ -27,7 +27,8 @@ from langgraph._internal._runnable import ( is_async_callable, is_async_generator, ) -from langgraph.graph import END, StateGraph +from langgraph.constants import END +from langgraph.graph import StateGraph from langgraph.graph.state import CompiledStateGraph pytestmark = pytest.mark.anyio