langgraph 1.2.18__tar.gz → 1.2.20__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langgraph-1.2.18 → langgraph-1.2.20}/PKG-INFO +1 -1
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_constants.py +3 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_runnable.py +119 -60
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/errors.py +40 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/graph/message.py +8 -11
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_algo.py +15 -9
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_draw.py +4 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_loop.py +33 -3
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_messages.py +21 -8
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_read.py +2 -11
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_retry.py +30 -3
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_tools.py +12 -12
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/main.py +53 -50
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/remote.py +12 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/types.py +15 -3
- {langgraph-1.2.18 → langgraph-1.2.20}/pyproject.toml +1 -1
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/__snapshots__/test_large_cases.ambr +10 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_pregel.py +33 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_pregel_async.py +97 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_remote_graph.py +84 -0
- langgraph-1.2.20/tests/test_stream_namespaces.py +308 -0
- langgraph-1.2.20/tests/test_strict_resume.py +423 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_tool_stream_handler.py +124 -2
- langgraph-1.2.20/tests/test_trace_policy.py +338 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/uv.lock +38 -39
- langgraph-1.2.18/tests/test_trace_policy.py +0 -149
- {langgraph-1.2.18 → langgraph-1.2.20}/.gitignore +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/LICENSE +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/Makefile +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/README.md +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/__main__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/fanout_to_subgraph.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/pydantic_state.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/react_agent.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/sequential.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/serde_allowlist.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/wide_dict.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/bench/wide_state.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_cache.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_config.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_fields.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_future.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_pydantic.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_queue.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_replay.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_retry.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_scratchpad.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_serde.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_timeout.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/_internal/_typing.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/callbacks.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/any_value.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/base.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/binop.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/delta.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/ephemeral_value.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/last_value.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/named_barrier_value.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/topic.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/channels/untracked_value.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/config.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/constants.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/func/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/graph/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/graph/_branch.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/graph/_node.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/graph/state.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/graph/ui.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/managed/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/managed/base.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/managed/is_last_step.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_call.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_checkpoint.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_config.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_executor.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_io.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_log.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_remote_run_stream.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_runner.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_task_status.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_utils.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_validate.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/_write.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/debug.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/protocol.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/pregel/types.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/py.typed +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/runtime.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/stream/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/stream/_convert.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/stream/_mux.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/stream/_types.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/stream/run_stream.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/stream/stream_channel.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/stream/transformers.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/typing.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/utils/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/utils/config.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/utils/runnable.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/version.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/langgraph/warnings.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/__init__.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/__snapshots__/test_pregel.ambr +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/__snapshots__/test_pregel_async.ambr +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/agents.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/any_int.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/any_str.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/compose-postgres.yml +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/compose-redis.yml +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/conftest.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/conftest_checkpointer.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/conftest_store.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/example_app/example_graph.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/example_app/langgraph.json +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/example_app/requirements.txt +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/fake_chat.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/fake_tracer.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/memory_assert.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/messages.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_algo.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_channels.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_checkpoint_migration.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_config_async.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_benchmark.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_exit_mode.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_fork.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_id_stability.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_migration.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_node_cache.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_parallel_order.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_run_input.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_seal_subscribers.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_subgraph.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_supersteps_bound.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_to_plain.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_update_overwrite.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_update_state.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_delta_channel_write_failures.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_deprecation.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_graph_callbacks.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_interleave_arrival_order.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_interrupt_migration.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_interrupt_state.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_interruption.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_large_cases.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_large_cases_async.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_managed_values.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_messages_state.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_parent_command.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_parent_command_async.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_pregel_debug.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_pregel_stream_events_v3.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_prune_postgres.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_pydantic.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_remote_graph_v3.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_retry.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_runnable.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_runtime.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_serde_allowlist.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_state.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_stream_before_builtins.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_stream_data_transformers.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_stream_events_v3.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_stream_events_v3_e2e.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_stream_events_v3_kwarg_forwarding.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_stream_lifecycle_transformer.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_stream_messages_transformer.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_stream_subgraph_transformer.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_subgraph_detection.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_subgraph_persistence.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_subgraph_persistence_async.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_time_travel.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_time_travel_async.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_tracing_interops.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_type_checking.py +0 -0
- {langgraph-1.2.18 → langgraph-1.2.20}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: langgraph
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.20
|
|
4
4
|
Summary: Building stateful, multi-actor applications with LLMs
|
|
5
5
|
Project-URL: Homepage, https://docs.langchain.com/oss/python/langgraph/overview
|
|
6
6
|
Project-URL: Documentation, https://reference.langchain.com/python/langgraph/
|
|
@@ -74,6 +74,8 @@ CONFIG_KEY_RUNTIME = sys.intern("__pregel_runtime")
|
|
|
74
74
|
# holds a `Runtime` instance with context, store, stream writer, etc.
|
|
75
75
|
CONFIG_KEY_RESUME_MAP = sys.intern("__pregel_resume_map")
|
|
76
76
|
# holds a mapping of task ns -> resume value for resuming tasks
|
|
77
|
+
CONFIG_KEY_STRICT_RESUME = sys.intern("__pregel_strict_resume")
|
|
78
|
+
# when True, the root graph refuses a resume that can't be matched to its pending interrupts
|
|
77
79
|
CONFIG_KEY_STREAM_MESSAGES_V2 = sys.intern("__pregel_stream_messages_v2")
|
|
78
80
|
# when True, attach StreamMessagesHandlerV2 so content-block (v2) events
|
|
79
81
|
# flow through stream_mode="messages"; set by StreamingHandler only.
|
|
@@ -134,6 +136,7 @@ RESERVED = {
|
|
|
134
136
|
CONFIG_KEY_CHECKPOINT_NS,
|
|
135
137
|
CONFIG_KEY_TIMED_ATTEMPT_OBSERVER,
|
|
136
138
|
CONFIG_KEY_RESUME_MAP,
|
|
139
|
+
CONFIG_KEY_STRICT_RESUME,
|
|
137
140
|
CONFIG_KEY_STREAM_MESSAGES_V2,
|
|
138
141
|
# other constants
|
|
139
142
|
PUSH,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
+
import copy
|
|
4
5
|
import enum
|
|
5
6
|
import inspect
|
|
6
7
|
import logging
|
|
@@ -23,9 +24,16 @@ from typing import (
|
|
|
23
24
|
Optional,
|
|
24
25
|
Protocol,
|
|
25
26
|
TypeGuard,
|
|
27
|
+
TypeVar,
|
|
26
28
|
cast,
|
|
27
29
|
)
|
|
28
30
|
|
|
31
|
+
from langchain_core.callbacks.base import BaseCallbackHandler, BaseCallbackManager
|
|
32
|
+
from langchain_core.callbacks.manager import (
|
|
33
|
+
AsyncCallbackManagerForChainRun,
|
|
34
|
+
BaseRunManager,
|
|
35
|
+
CallbackManagerForChainRun,
|
|
36
|
+
)
|
|
29
37
|
from langchain_core.runnables.base import (
|
|
30
38
|
Runnable,
|
|
31
39
|
RunnableConfig,
|
|
@@ -41,6 +49,7 @@ from langchain_core.runnables.config import (
|
|
|
41
49
|
var_child_runnable_config,
|
|
42
50
|
)
|
|
43
51
|
from langchain_core.runnables.utils import Input, Output
|
|
52
|
+
from langchain_core.tracers.base import BaseTracer
|
|
44
53
|
from langchain_core.tracers.langchain import LangChainTracer
|
|
45
54
|
from langgraph.store.base import BaseStore
|
|
46
55
|
|
|
@@ -57,7 +66,7 @@ from langgraph._internal._constants import (
|
|
|
57
66
|
)
|
|
58
67
|
from langgraph._internal._typing import MISSING
|
|
59
68
|
from langgraph.errors import NodeError
|
|
60
|
-
from langgraph.types import StreamWriter
|
|
69
|
+
from langgraph.types import StreamWriter, TracePolicy
|
|
61
70
|
|
|
62
71
|
try:
|
|
63
72
|
from langchain_core.tracers._streaming import _StreamingCallbackHandler
|
|
@@ -85,6 +94,29 @@ def _trace_payload(value: Any, transform: Callable[[Any], Any] | None) -> Any:
|
|
|
85
94
|
return value
|
|
86
95
|
|
|
87
96
|
|
|
97
|
+
def _is_stream_handler(handler: BaseCallbackHandler) -> bool:
|
|
98
|
+
# Inheritance, not isinstance on the runtime-checkable protocol, which also
|
|
99
|
+
# matches any exporter that merely has the tap methods: stream handlers get a
|
|
100
|
+
# node's real payload and its streamed output.
|
|
101
|
+
return _StreamingCallbackHandler in type(handler).__mro__
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
_M = TypeVar("_M", bound=BaseCallbackManager | BaseRunManager)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _split_handlers(manager: _M) -> tuple[_M, _M]:
|
|
108
|
+
# The recorded payload exists to keep tracer ingest small, so only tracers get it.
|
|
109
|
+
# `astream_log`'s handler is a tracer too, but it feeds the caller's own stream.
|
|
110
|
+
real, tracers = copy.copy(manager), copy.copy(manager)
|
|
111
|
+
tracers.handlers = [
|
|
112
|
+
h
|
|
113
|
+
for h in manager.handlers
|
|
114
|
+
if isinstance(h, BaseTracer) and not _is_stream_handler(h)
|
|
115
|
+
]
|
|
116
|
+
real.handlers = [h for h in manager.handlers if h not in tracers.handlers]
|
|
117
|
+
return real, tracers
|
|
118
|
+
|
|
119
|
+
|
|
88
120
|
def _set_config_context(
|
|
89
121
|
config: RunnableConfig, run: Any = None
|
|
90
122
|
) -> Token[RunnableConfig | None]:
|
|
@@ -593,13 +625,15 @@ class RunnableSeq(Runnable):
|
|
|
593
625
|
*steps: RunnableLike,
|
|
594
626
|
name: str | None = None,
|
|
595
627
|
trace_inputs: Callable[[Any], Any] | None = None,
|
|
596
|
-
|
|
628
|
+
trace_policy: TracePolicy | None = None,
|
|
597
629
|
) -> None:
|
|
598
630
|
"""Create a new RunnableSeq.
|
|
599
631
|
|
|
600
632
|
Args:
|
|
601
633
|
steps: The steps to include in the sequence.
|
|
602
634
|
name: The name of the `Runnable`.
|
|
635
|
+
trace_inputs: Transforms the input every callback handler receives.
|
|
636
|
+
trace_policy: Processes what tracers record, after `trace_inputs`.
|
|
603
637
|
|
|
604
638
|
Raises:
|
|
605
639
|
ValueError: If the sequence has less than 2 steps.
|
|
@@ -619,7 +653,67 @@ class RunnableSeq(Runnable):
|
|
|
619
653
|
self.steps = steps_flat
|
|
620
654
|
self.name = name
|
|
621
655
|
self.trace_inputs = trace_inputs
|
|
622
|
-
self.
|
|
656
|
+
self.trace_policy = trace_policy or TracePolicy()
|
|
657
|
+
|
|
658
|
+
def _start(self, input: Any, config: RunnableConfig) -> CallbackManagerForChainRun:
|
|
659
|
+
callback_manager = get_callback_manager_for_config(config)
|
|
660
|
+
payload = _trace_payload(input, self.trace_inputs)
|
|
661
|
+
recorded = _trace_payload(payload, self.trace_policy.process_inputs)
|
|
662
|
+
name = config.get("run_name") or self.get_name()
|
|
663
|
+
run_id = config.pop("run_id", None)
|
|
664
|
+
if recorded is payload:
|
|
665
|
+
return callback_manager.on_chain_start(
|
|
666
|
+
None, payload, name=name, run_id=run_id
|
|
667
|
+
)
|
|
668
|
+
real, tracers = _split_handlers(callback_manager)
|
|
669
|
+
run_manager = real.on_chain_start(None, payload, name=name, run_id=run_id)
|
|
670
|
+
tracers.on_chain_start(None, recorded, name=name, run_id=run_manager.run_id)
|
|
671
|
+
run_manager.handlers = callback_manager.handlers
|
|
672
|
+
return run_manager
|
|
673
|
+
|
|
674
|
+
async def _astart(
|
|
675
|
+
self, input: Any, config: RunnableConfig
|
|
676
|
+
) -> AsyncCallbackManagerForChainRun:
|
|
677
|
+
callback_manager = get_async_callback_manager_for_config(config)
|
|
678
|
+
payload = _trace_payload(input, self.trace_inputs)
|
|
679
|
+
recorded = _trace_payload(payload, self.trace_policy.process_inputs)
|
|
680
|
+
name = config.get("run_name") or self.get_name()
|
|
681
|
+
run_id = config.pop("run_id", None)
|
|
682
|
+
if recorded is payload:
|
|
683
|
+
return await callback_manager.on_chain_start(
|
|
684
|
+
None, payload, name=name, run_id=run_id
|
|
685
|
+
)
|
|
686
|
+
real, tracers = _split_handlers(callback_manager)
|
|
687
|
+
# Tracers start last, so a cancellation before then leaves no tracer run open.
|
|
688
|
+
run_manager = await real.on_chain_start(None, payload, name=name, run_id=run_id)
|
|
689
|
+
await tracers.on_chain_start(
|
|
690
|
+
None, recorded, name=name, run_id=run_manager.run_id
|
|
691
|
+
)
|
|
692
|
+
run_manager.handlers = callback_manager.handlers
|
|
693
|
+
return run_manager
|
|
694
|
+
|
|
695
|
+
def _end(self, run_manager: CallbackManagerForChainRun, output: Any) -> None:
|
|
696
|
+
recorded = _trace_payload(output, self.trace_policy.process_outputs)
|
|
697
|
+
if recorded is output:
|
|
698
|
+
run_manager.on_chain_end(output)
|
|
699
|
+
else:
|
|
700
|
+
real, tracers = _split_handlers(run_manager)
|
|
701
|
+
tracers.on_chain_end(recorded)
|
|
702
|
+
real.on_chain_end(output)
|
|
703
|
+
|
|
704
|
+
async def _aend(
|
|
705
|
+
self, run_manager: AsyncCallbackManagerForChainRun, output: Any
|
|
706
|
+
) -> None:
|
|
707
|
+
recorded = _trace_payload(output, self.trace_policy.process_outputs)
|
|
708
|
+
if recorded is output:
|
|
709
|
+
await run_manager.on_chain_end(output)
|
|
710
|
+
else:
|
|
711
|
+
real, tracers = _split_handlers(run_manager)
|
|
712
|
+
# Tracers end first: on_chain_end is shielded once it starts, so a
|
|
713
|
+
# cancellation can only skip the other handlers' end, never leave a
|
|
714
|
+
# tracer run open.
|
|
715
|
+
await tracers.on_chain_end(recorded)
|
|
716
|
+
await real.on_chain_end(output)
|
|
623
717
|
|
|
624
718
|
def __or__(
|
|
625
719
|
self,
|
|
@@ -676,15 +770,8 @@ class RunnableSeq(Runnable):
|
|
|
676
770
|
) -> Any:
|
|
677
771
|
if config is None:
|
|
678
772
|
config = ensure_config()
|
|
679
|
-
# setup callbacks and context
|
|
680
|
-
callback_manager = get_callback_manager_for_config(config)
|
|
681
773
|
# start the root run
|
|
682
|
-
run_manager =
|
|
683
|
-
None,
|
|
684
|
-
_trace_payload(input, self.trace_inputs),
|
|
685
|
-
name=config.get("run_name") or self.get_name(),
|
|
686
|
-
run_id=config.pop("run_id", None),
|
|
687
|
-
)
|
|
774
|
+
run_manager = self._start(input, config)
|
|
688
775
|
# invoke all steps in sequence
|
|
689
776
|
try:
|
|
690
777
|
for i, step in enumerate(self.steps):
|
|
@@ -712,7 +799,7 @@ class RunnableSeq(Runnable):
|
|
|
712
799
|
run_manager.on_chain_error(e)
|
|
713
800
|
raise
|
|
714
801
|
else:
|
|
715
|
-
|
|
802
|
+
self._end(run_manager, input)
|
|
716
803
|
return input
|
|
717
804
|
|
|
718
805
|
async def ainvoke(
|
|
@@ -723,15 +810,8 @@ class RunnableSeq(Runnable):
|
|
|
723
810
|
) -> Any:
|
|
724
811
|
if config is None:
|
|
725
812
|
config = ensure_config()
|
|
726
|
-
# setup callbacks
|
|
727
|
-
callback_manager = get_async_callback_manager_for_config(config)
|
|
728
813
|
# start the root run
|
|
729
|
-
run_manager = await
|
|
730
|
-
None,
|
|
731
|
-
_trace_payload(input, self.trace_inputs),
|
|
732
|
-
name=config.get("run_name") or self.get_name(),
|
|
733
|
-
run_id=config.pop("run_id", None),
|
|
734
|
-
)
|
|
814
|
+
run_manager = await self._astart(input, config)
|
|
735
815
|
|
|
736
816
|
# invoke all steps in sequence
|
|
737
817
|
try:
|
|
@@ -765,7 +845,7 @@ class RunnableSeq(Runnable):
|
|
|
765
845
|
await run_manager.on_chain_error(e)
|
|
766
846
|
raise
|
|
767
847
|
else:
|
|
768
|
-
await
|
|
848
|
+
await self._aend(run_manager, input)
|
|
769
849
|
return input
|
|
770
850
|
|
|
771
851
|
def stream(
|
|
@@ -776,15 +856,8 @@ class RunnableSeq(Runnable):
|
|
|
776
856
|
) -> Iterator[Any]:
|
|
777
857
|
if config is None:
|
|
778
858
|
config = ensure_config()
|
|
779
|
-
# setup callbacks
|
|
780
|
-
callback_manager = get_callback_manager_for_config(config)
|
|
781
859
|
# start the root run
|
|
782
|
-
run_manager =
|
|
783
|
-
None,
|
|
784
|
-
_trace_payload(input, self.trace_inputs),
|
|
785
|
-
name=config.get("run_name") or self.get_name(),
|
|
786
|
-
run_id=config.pop("run_id", None),
|
|
787
|
-
)
|
|
860
|
+
run_manager = self._start(input, config)
|
|
788
861
|
# get the run object
|
|
789
862
|
for h in run_manager.handlers:
|
|
790
863
|
if isinstance(h, LangChainTracer):
|
|
@@ -814,10 +887,9 @@ class RunnableSeq(Runnable):
|
|
|
814
887
|
)
|
|
815
888
|
iterator = step.transform(iterator, config)
|
|
816
889
|
# populates streamed_output in astream_log() output if needed
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
iterator = h.tap_output_iter(run_manager.run_id, iterator)
|
|
890
|
+
for h in run_manager.handlers:
|
|
891
|
+
if _is_stream_handler(h):
|
|
892
|
+
iterator = h.tap_output_iter(run_manager.run_id, iterator)
|
|
821
893
|
# consume into final output
|
|
822
894
|
output = context.run(_consume_iter, iterator)
|
|
823
895
|
# sequence doesn't emit output, yield to mark as generator
|
|
@@ -826,7 +898,7 @@ class RunnableSeq(Runnable):
|
|
|
826
898
|
run_manager.on_chain_error(e)
|
|
827
899
|
raise
|
|
828
900
|
else:
|
|
829
|
-
|
|
901
|
+
self._end(run_manager, output)
|
|
830
902
|
|
|
831
903
|
async def astream(
|
|
832
904
|
self,
|
|
@@ -836,15 +908,8 @@ class RunnableSeq(Runnable):
|
|
|
836
908
|
) -> AsyncIterator[Any]:
|
|
837
909
|
if config is None:
|
|
838
910
|
config = ensure_config()
|
|
839
|
-
# setup callbacks
|
|
840
|
-
callback_manager = get_async_callback_manager_for_config(config)
|
|
841
911
|
# start the root run
|
|
842
|
-
run_manager = await
|
|
843
|
-
None,
|
|
844
|
-
_trace_payload(input, self.trace_inputs),
|
|
845
|
-
name=config.get("run_name") or self.get_name(),
|
|
846
|
-
run_id=config.pop("run_id", None),
|
|
847
|
-
)
|
|
912
|
+
run_manager = await self._astart(input, config)
|
|
848
913
|
# stream the last steps
|
|
849
914
|
# transform the input stream of each step with the next
|
|
850
915
|
# steps that don't natively support transforming an input stream will
|
|
@@ -880,12 +945,11 @@ class RunnableSeq(Runnable):
|
|
|
880
945
|
if hasattr(aiterator, "aclose"):
|
|
881
946
|
stack.push_async_callback(aiterator.aclose)
|
|
882
947
|
# populates streamed_output in astream_log() output if needed
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
aiterator
|
|
887
|
-
|
|
888
|
-
)
|
|
948
|
+
for h in run_manager.handlers:
|
|
949
|
+
if _is_stream_handler(h):
|
|
950
|
+
aiterator = h.tap_output_aiter(
|
|
951
|
+
run_manager.run_id, aiterator
|
|
952
|
+
)
|
|
889
953
|
# consume into final output
|
|
890
954
|
output = await asyncio.create_task(
|
|
891
955
|
_consume_aiter(aiterator), context=context
|
|
@@ -896,9 +960,7 @@ class RunnableSeq(Runnable):
|
|
|
896
960
|
await run_manager.on_chain_error(e)
|
|
897
961
|
raise
|
|
898
962
|
else:
|
|
899
|
-
await
|
|
900
|
-
_trace_payload(output, self.trace_outputs)
|
|
901
|
-
)
|
|
963
|
+
await self._aend(run_manager, output)
|
|
902
964
|
else:
|
|
903
965
|
try:
|
|
904
966
|
async with AsyncExitStack() as stack:
|
|
@@ -914,12 +976,11 @@ class RunnableSeq(Runnable):
|
|
|
914
976
|
if hasattr(aiterator, "aclose"):
|
|
915
977
|
stack.push_async_callback(aiterator.aclose)
|
|
916
978
|
# populates streamed_output in astream_log() output if needed
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
aiterator
|
|
921
|
-
|
|
922
|
-
)
|
|
979
|
+
for h in run_manager.handlers:
|
|
980
|
+
if _is_stream_handler(h):
|
|
981
|
+
aiterator = h.tap_output_aiter(
|
|
982
|
+
run_manager.run_id, aiterator
|
|
983
|
+
)
|
|
923
984
|
# consume into final output
|
|
924
985
|
output = await _consume_aiter(aiterator)
|
|
925
986
|
# sequence doesn't emit output, yield to mark as generator
|
|
@@ -928,9 +989,7 @@ class RunnableSeq(Runnable):
|
|
|
928
989
|
await run_manager.on_chain_error(e)
|
|
929
990
|
raise
|
|
930
991
|
else:
|
|
931
|
-
await
|
|
932
|
-
_trace_payload(output, self.trace_outputs)
|
|
933
|
-
)
|
|
992
|
+
await self._aend(run_manager, output)
|
|
934
993
|
|
|
935
994
|
|
|
936
995
|
def _consume_iter(it: Iterator[Any]) -> Any:
|
|
@@ -28,6 +28,7 @@ __all__ = (
|
|
|
28
28
|
"ParentCommand",
|
|
29
29
|
"EmptyInputError",
|
|
30
30
|
"TaskNotFound",
|
|
31
|
+
"UnknownInterruptError",
|
|
31
32
|
"is_invalid_resume",
|
|
32
33
|
)
|
|
33
34
|
|
|
@@ -146,6 +147,45 @@ class TaskNotFound(Exception):
|
|
|
146
147
|
pass
|
|
147
148
|
|
|
148
149
|
|
|
150
|
+
class UnknownInterruptError(Exception):
|
|
151
|
+
"""Raised in strict resume mode when a resume doesn't match the pending interrupts.
|
|
152
|
+
|
|
153
|
+
`reason` says how it doesn't match:
|
|
154
|
+
|
|
155
|
+
- `"not_pending"`: the resume names interrupts that aren't pending, listed in
|
|
156
|
+
`interrupt_ids`.
|
|
157
|
+
- `"empty_map"`: the resume is an empty map.
|
|
158
|
+
- `"ambiguous"`: the resume is a single value while several interrupts are
|
|
159
|
+
pending.
|
|
160
|
+
|
|
161
|
+
`pending_ids` lists the interrupts still waiting for an answer. The error is
|
|
162
|
+
raised before anything is written, so they can still be answered.
|
|
163
|
+
|
|
164
|
+
A single value with no interrupt pending is accepted, because it resumes a
|
|
165
|
+
graph paused at a static breakpoint (`interrupt_before` or `interrupt_after`).
|
|
166
|
+
|
|
167
|
+
The interrupts one task raises share an id, so an answer retried after the
|
|
168
|
+
task asked its next question answers that question.
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
reason: Literal["not_pending", "empty_map", "ambiguous"]
|
|
172
|
+
interrupt_ids: tuple[str, ...]
|
|
173
|
+
pending_ids: tuple[str, ...]
|
|
174
|
+
|
|
175
|
+
def __init__(
|
|
176
|
+
self,
|
|
177
|
+
message: str,
|
|
178
|
+
*,
|
|
179
|
+
reason: Literal["not_pending", "empty_map", "ambiguous"],
|
|
180
|
+
interrupt_ids: Sequence[str] = (),
|
|
181
|
+
pending_ids: Sequence[str] = (),
|
|
182
|
+
) -> None:
|
|
183
|
+
super().__init__(message)
|
|
184
|
+
self.reason = reason
|
|
185
|
+
self.interrupt_ids = tuple(interrupt_ids)
|
|
186
|
+
self.pending_ids = tuple(pending_ids)
|
|
187
|
+
|
|
188
|
+
|
|
149
189
|
@dataclass(frozen=True, slots=True)
|
|
150
190
|
class NodeError:
|
|
151
191
|
"""Failure context passed to a node-level error handler.
|
|
@@ -22,7 +22,7 @@ from langchain_core.messages import (
|
|
|
22
22
|
)
|
|
23
23
|
from typing_extensions import TypedDict, deprecated
|
|
24
24
|
|
|
25
|
-
from langgraph._internal._constants import CONF, CONFIG_KEY_SEND
|
|
25
|
+
from langgraph._internal._constants import CONF, CONFIG_KEY_SEND
|
|
26
26
|
from langgraph.graph.state import StateGraph
|
|
27
27
|
from langgraph.pregel._messages import (
|
|
28
28
|
_messages_delta_reducer as _messages_delta_reducer,
|
|
@@ -343,7 +343,7 @@ def push_message(
|
|
|
343
343
|
)
|
|
344
344
|
|
|
345
345
|
from langgraph.config import get_config
|
|
346
|
-
from langgraph.pregel._messages import StreamMessagesHandler
|
|
346
|
+
from langgraph.pregel._messages import StreamMessagesHandler, graph_namespace
|
|
347
347
|
|
|
348
348
|
config = get_config()
|
|
349
349
|
message = next(x for x in convert_to_messages([message]))
|
|
@@ -359,15 +359,12 @@ def push_message(
|
|
|
359
359
|
):
|
|
360
360
|
handlers = config["callbacks"]
|
|
361
361
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
metadata,
|
|
369
|
-
)
|
|
370
|
-
stream_handler._emit(message_meta, message, dedupe=False)
|
|
362
|
+
metadata = config["metadata"]
|
|
363
|
+
for handler in handlers:
|
|
364
|
+
if isinstance(handler, StreamMessagesHandler):
|
|
365
|
+
ns = graph_namespace(metadata)
|
|
366
|
+
if handler.subgraphs or not ns or ns == handler.parent_ns:
|
|
367
|
+
handler._emit((ns, metadata), message, dedupe=False)
|
|
371
368
|
|
|
372
369
|
if state_key:
|
|
373
370
|
config[CONF][CONFIG_KEY_SEND]([(state_key, message)])
|
|
@@ -85,6 +85,7 @@ from langgraph.types import (
|
|
|
85
85
|
RetryPolicy,
|
|
86
86
|
Send,
|
|
87
87
|
TimeoutPolicy,
|
|
88
|
+
_interrupt_id,
|
|
88
89
|
)
|
|
89
90
|
|
|
90
91
|
GetNextVersion = Callable[[V | None, None], V]
|
|
@@ -626,7 +627,7 @@ def prepare_single_task(
|
|
|
626
627
|
config[CONF].get(CONFIG_KEY_SCRATCHPAD),
|
|
627
628
|
pending_writes,
|
|
628
629
|
task_id,
|
|
629
|
-
|
|
630
|
+
task_checkpoint_ns,
|
|
630
631
|
config[CONF].get(CONFIG_KEY_RESUME_MAP),
|
|
631
632
|
step,
|
|
632
633
|
stop,
|
|
@@ -873,7 +874,7 @@ def prepare_push_task_functional(
|
|
|
873
874
|
configurable.get(CONFIG_KEY_SCRATCHPAD),
|
|
874
875
|
pending_writes,
|
|
875
876
|
task_id,
|
|
876
|
-
|
|
877
|
+
task_checkpoint_ns,
|
|
877
878
|
configurable.get(CONFIG_KEY_RESUME_MAP),
|
|
878
879
|
step,
|
|
879
880
|
stop,
|
|
@@ -1035,7 +1036,7 @@ def prepare_push_task_send(
|
|
|
1035
1036
|
config[CONF].get(CONFIG_KEY_SCRATCHPAD),
|
|
1036
1037
|
pending_writes,
|
|
1037
1038
|
task_id,
|
|
1038
|
-
|
|
1039
|
+
task_checkpoint_ns,
|
|
1039
1040
|
config[CONF].get(CONFIG_KEY_RESUME_MAP),
|
|
1040
1041
|
step,
|
|
1041
1042
|
stop,
|
|
@@ -1184,7 +1185,7 @@ def prepare_node_error_handler_task(
|
|
|
1184
1185
|
config[CONF].get(CONFIG_KEY_SCRATCHPAD),
|
|
1185
1186
|
pending_writes,
|
|
1186
1187
|
task_id,
|
|
1187
|
-
|
|
1188
|
+
task_checkpoint_ns,
|
|
1188
1189
|
config[CONF].get(CONFIG_KEY_RESUME_MAP),
|
|
1189
1190
|
step,
|
|
1190
1191
|
stop,
|
|
@@ -1280,7 +1281,7 @@ def _scratchpad(
|
|
|
1280
1281
|
parent_scratchpad: PregelScratchpad | None,
|
|
1281
1282
|
pending_writes: list[PendingWrite],
|
|
1282
1283
|
task_id: str,
|
|
1283
|
-
|
|
1284
|
+
task_checkpoint_ns: str,
|
|
1284
1285
|
resume_map: dict[str, Any] | None,
|
|
1285
1286
|
step: int,
|
|
1286
1287
|
stop: int,
|
|
@@ -1307,10 +1308,15 @@ def _scratchpad(
|
|
|
1307
1308
|
task_resume_write = []
|
|
1308
1309
|
del w
|
|
1309
1310
|
|
|
1310
|
-
# find
|
|
1311
|
-
if resume_map
|
|
1312
|
-
|
|
1313
|
-
|
|
1311
|
+
# find the resume value for the task's next interrupt
|
|
1312
|
+
if resume_map:
|
|
1313
|
+
next_id = _interrupt_id(task_checkpoint_ns, len(task_resume_write))
|
|
1314
|
+
first_id = _interrupt_id(task_checkpoint_ns, 0)
|
|
1315
|
+
if next_id in resume_map:
|
|
1316
|
+
task_resume_write.append(resume_map[next_id])
|
|
1317
|
+
# Older versions gave all of a task's interrupts the first id.
|
|
1318
|
+
elif first_id in resume_map:
|
|
1319
|
+
task_resume_write.append(resume_map[first_id])
|
|
1314
1320
|
|
|
1315
1321
|
else:
|
|
1316
1322
|
null_resume_write = None
|
|
@@ -228,6 +228,10 @@ def draw_graph(
|
|
|
228
228
|
metadata["__interrupt"] = "before"
|
|
229
229
|
elif name in interrupt_after_nodes:
|
|
230
230
|
metadata["__interrupt"] = "after"
|
|
231
|
+
# Duck-typed so core doesn't import ToolNode from langgraph-prebuilt.
|
|
232
|
+
tools_by_name = getattr(node.bound, "tools_by_name", None)
|
|
233
|
+
if isinstance(tools_by_name, Mapping) and tools_by_name:
|
|
234
|
+
metadata["__tools"] = list(tools_by_name)
|
|
231
235
|
graph.add_node(node.bound, name, metadata=metadata or None)
|
|
232
236
|
# add start node
|
|
233
237
|
if START not in nodes:
|
|
@@ -48,6 +48,7 @@ from langgraph._internal._constants import (
|
|
|
48
48
|
CONFIG_KEY_RUNTIME,
|
|
49
49
|
CONFIG_KEY_SCRATCHPAD,
|
|
50
50
|
CONFIG_KEY_STREAM,
|
|
51
|
+
CONFIG_KEY_STRICT_RESUME,
|
|
51
52
|
CONFIG_KEY_TASK_ID,
|
|
52
53
|
CONFIG_KEY_THREAD_ID,
|
|
53
54
|
ERROR,
|
|
@@ -77,6 +78,7 @@ from langgraph.constants import TAG_HIDDEN
|
|
|
77
78
|
from langgraph.errors import (
|
|
78
79
|
EmptyInputError,
|
|
79
80
|
GraphInterrupt,
|
|
81
|
+
UnknownInterruptError,
|
|
80
82
|
)
|
|
81
83
|
from langgraph.managed.base import (
|
|
82
84
|
ManagedValueMapping,
|
|
@@ -1024,17 +1026,45 @@ class PregelLoop:
|
|
|
1024
1026
|
"Cannot use Command(resume=...) without checkpointer"
|
|
1025
1027
|
)
|
|
1026
1028
|
|
|
1029
|
+
strict = (
|
|
1030
|
+
self.config[CONF].get(CONFIG_KEY_STRICT_RESUME, False)
|
|
1031
|
+
# Nested calls inherit the parent's configurable.
|
|
1032
|
+
and not self.is_nested
|
|
1033
|
+
# A finished task can rerun and interrupt again on replay, while
|
|
1034
|
+
# its earlier output still makes its interrupt look answered.
|
|
1035
|
+
and not self._addressed_checkpoint_superseded
|
|
1036
|
+
)
|
|
1027
1037
|
if resume_is_map := (
|
|
1028
1038
|
isinstance(resume, dict)
|
|
1029
1039
|
and all(is_xxh3_128_hexdigest(k) for k in resume)
|
|
1030
1040
|
):
|
|
1041
|
+
if strict:
|
|
1042
|
+
pending = self._pending_interrupts()
|
|
1043
|
+
if not resume:
|
|
1044
|
+
raise UnknownInterruptError(
|
|
1045
|
+
"The resume map names no interrupt",
|
|
1046
|
+
reason="empty_map",
|
|
1047
|
+
pending_ids=sorted(pending),
|
|
1048
|
+
)
|
|
1049
|
+
if unknown := sorted(resume.keys() - pending):
|
|
1050
|
+
raise UnknownInterruptError(
|
|
1051
|
+
f"Unknown or already-consumed interrupt: {unknown[0]}",
|
|
1052
|
+
reason="not_pending",
|
|
1053
|
+
interrupt_ids=unknown,
|
|
1054
|
+
pending_ids=sorted(pending),
|
|
1055
|
+
)
|
|
1031
1056
|
self.config[CONF][CONFIG_KEY_RESUME_MAP] = resume
|
|
1032
1057
|
else:
|
|
1033
|
-
if len(self._pending_interrupts()) > 1:
|
|
1034
|
-
|
|
1058
|
+
if len(pending := self._pending_interrupts()) > 1:
|
|
1059
|
+
message = (
|
|
1035
1060
|
"When there are multiple pending interrupts, you must specify the interrupt id when resuming. "
|
|
1036
|
-
"Docs: https://docs.langchain.com/oss/python/langgraph/
|
|
1061
|
+
"Docs: https://docs.langchain.com/oss/python/langgraph/interrupts#handling-multiple-interrupts."
|
|
1037
1062
|
)
|
|
1063
|
+
if strict:
|
|
1064
|
+
raise UnknownInterruptError(
|
|
1065
|
+
message, reason="ambiguous", pending_ids=sorted(pending)
|
|
1066
|
+
)
|
|
1067
|
+
raise RuntimeError(message)
|
|
1038
1068
|
|
|
1039
1069
|
writes: defaultdict[str, list[tuple[str, Any]]] = defaultdict(list)
|
|
1040
1070
|
# group writes by task ID
|
|
@@ -23,7 +23,7 @@ from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, LLMResul
|
|
|
23
23
|
from pydantic import BaseModel
|
|
24
24
|
|
|
25
25
|
from langgraph._internal._config import filter_to_user_tags
|
|
26
|
-
from langgraph._internal._constants import NS_SEP
|
|
26
|
+
from langgraph._internal._constants import NS_SEP, PUSH
|
|
27
27
|
from langgraph.channels.binop import _get_overwrite
|
|
28
28
|
from langgraph.channels.delta import DeltaChannel
|
|
29
29
|
from langgraph.constants import TAG_HIDDEN, TAG_NOSTREAM
|
|
@@ -55,6 +55,23 @@ def _state_values(obj: Any) -> Sequence[Any]:
|
|
|
55
55
|
return ()
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
def graph_namespace(metadata: Mapping[str, Any]) -> tuple[str, ...]:
|
|
59
|
+
"""Namespace of the graph a task runs in, from the task's run metadata.
|
|
60
|
+
|
|
61
|
+
Drops the task's own segment, plus one per enclosing `@task` call: a call
|
|
62
|
+
runs in its caller's graph but nests its segment under the caller's. A
|
|
63
|
+
call's `langgraph_path` is `(PUSH, <caller's path>, <index>, True)`, while
|
|
64
|
+
a `Send` task's ends in `False`.
|
|
65
|
+
"""
|
|
66
|
+
ns = tuple(cast(str, metadata["langgraph_checkpoint_ns"]).split(NS_SEP))
|
|
67
|
+
path = metadata.get("langgraph_path", ())
|
|
68
|
+
drop = 1
|
|
69
|
+
while len(path) == 4 and path[0] == PUSH and path[-1] is True:
|
|
70
|
+
drop += 1
|
|
71
|
+
path = path[1]
|
|
72
|
+
return ns[:-drop]
|
|
73
|
+
|
|
74
|
+
|
|
58
75
|
class StreamMessagesHandler(BaseCallbackHandler, _StreamingCallbackHandler):
|
|
59
76
|
"""A callback handler that implements stream_mode=messages.
|
|
60
77
|
|
|
@@ -148,9 +165,7 @@ class StreamMessagesHandler(BaseCallbackHandler, _StreamingCallbackHandler):
|
|
|
148
165
|
**kwargs: Any,
|
|
149
166
|
) -> Any:
|
|
150
167
|
if metadata and (not tags or (TAG_NOSTREAM not in tags)):
|
|
151
|
-
ns =
|
|
152
|
-
:-1
|
|
153
|
-
]
|
|
168
|
+
ns = graph_namespace(metadata)
|
|
154
169
|
if not self.subgraphs and len(ns) > 0 and ns != self.parent_ns:
|
|
155
170
|
return
|
|
156
171
|
if (filtered_tags := filter_to_user_tags(tags)) is not None:
|
|
@@ -213,10 +228,8 @@ class StreamMessagesHandler(BaseCallbackHandler, _StreamingCallbackHandler):
|
|
|
213
228
|
and kwargs.get("name") == metadata.get("langgraph_node")
|
|
214
229
|
and (not tags or TAG_HIDDEN not in tags)
|
|
215
230
|
):
|
|
216
|
-
ns =
|
|
217
|
-
|
|
218
|
-
]
|
|
219
|
-
if not self.subgraphs and len(ns) > 0:
|
|
231
|
+
ns = graph_namespace(metadata)
|
|
232
|
+
if not self.subgraphs and len(ns) > 0 and ns != self.parent_ns:
|
|
220
233
|
return
|
|
221
234
|
self.metadata[run_id] = (ns, metadata)
|
|
222
235
|
for value in _state_values(inputs):
|
|
@@ -227,23 +227,14 @@ class PregelNode:
|
|
|
227
227
|
def node(self) -> Runnable[Any, Any] | None:
|
|
228
228
|
"""Get a runnable that combines `bound` and `writers`."""
|
|
229
229
|
writers = self.flat_writers
|
|
230
|
-
trace_inputs = self.trace_policy.process_inputs if self.trace_policy else None
|
|
231
|
-
trace_outputs = self.trace_policy.process_outputs if self.trace_policy else None
|
|
232
230
|
if self.bound is DEFAULT_BOUND and not writers:
|
|
233
231
|
return None
|
|
234
232
|
elif self.bound is DEFAULT_BOUND and len(writers) == 1:
|
|
235
233
|
return writers[0]
|
|
236
234
|
elif self.bound is DEFAULT_BOUND:
|
|
237
|
-
return RunnableSeq(
|
|
238
|
-
*writers, trace_inputs=trace_inputs, trace_outputs=trace_outputs
|
|
239
|
-
)
|
|
235
|
+
return RunnableSeq(*writers, trace_policy=self.trace_policy)
|
|
240
236
|
elif writers:
|
|
241
|
-
return RunnableSeq(
|
|
242
|
-
self.bound,
|
|
243
|
-
*writers,
|
|
244
|
-
trace_inputs=trace_inputs,
|
|
245
|
-
trace_outputs=trace_outputs,
|
|
246
|
-
)
|
|
237
|
+
return RunnableSeq(self.bound, *writers, trace_policy=self.trace_policy)
|
|
247
238
|
else:
|
|
248
239
|
return self.bound
|
|
249
240
|
|