diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py index f0fe23b4c..926faec0f 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/__init__.py @@ -453,8 +453,13 @@ class PostgresSaver(BasePostgresSaver): ) """, ( - thread_id, checkpoint_ns, channel, channel, - thread_id, checkpoint_ns, checkpoint_id, + thread_id, + checkpoint_ns, + channel, + channel, + thread_id, + checkpoint_ns, + checkpoint_id, ), ) row = cur.fetchone() diff --git a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py index be7625566..cf8ed4210 100644 --- a/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py +++ b/libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py @@ -414,8 +414,13 @@ class AsyncPostgresSaver(BasePostgresSaver): ) """, ( - thread_id, checkpoint_ns, channel, channel, - thread_id, checkpoint_ns, checkpoint_id, + thread_id, + checkpoint_ns, + channel, + channel, + thread_id, + checkpoint_ns, + checkpoint_id, ), ) row = await cur.fetchone() diff --git a/libs/checkpoint/langgraph/checkpoint/base/__init__.py b/libs/checkpoint/langgraph/checkpoint/base/__init__.py index 78af858c7..48a8b98c1 100644 --- a/libs/checkpoint/langgraph/checkpoint/base/__init__.py +++ b/libs/checkpoint/langgraph/checkpoint/base/__init__.py @@ -36,7 +36,9 @@ class DeltaValue: """Returned by DeltaChannel.checkpoint(). Represents one step's writes.""" delta: list[Any] - prev_checkpoint_id: str | None # ID of checkpoint containing previous blob; None = chain root + prev_checkpoint_id: ( + str | None + ) # ID of checkpoint containing previous blob; None = chain root @dataclasses.dataclass diff --git a/libs/checkpoint/tests/test_jsonplus.py b/libs/checkpoint/tests/test_jsonplus.py index 7533092df..d81475c7e 100644 --- a/libs/checkpoint/tests/test_jsonplus.py +++ b/libs/checkpoint/tests/test_jsonplus.py @@ -1004,7 +1004,9 @@ def test_delta_value_serde_round_trip() -> None: from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer serde = JsonPlusSerializer() - original = DeltaValue(delta=[{"type": "human", "content": "hi"}], prev_checkpoint_id="abc-123") + original = DeltaValue( + delta=[{"type": "human", "content": "hi"}], prev_checkpoint_id="abc-123" + ) type_tag, blob = serde.dumps_typed(original) assert type_tag == "diff" loaded = serde.loads_typed((type_tag, blob)) diff --git a/libs/prebuilt/langgraph/prebuilt/tool_node.py b/libs/prebuilt/langgraph/prebuilt/tool_node.py index d8a1f3182..7ad9d208b 100644 --- a/libs/prebuilt/langgraph/prebuilt/tool_node.py +++ b/libs/prebuilt/langgraph/prebuilt/tool_node.py @@ -614,7 +614,6 @@ class _InjectedArgs: store: str | None runtime: str | None all_injected_keys: set[str] - _optional_state_args: set[str] class ToolNode(RunnableCallable): @@ -1336,7 +1335,7 @@ class ToolNode(RunnableCallable): return tool_call tool_call_copy: ToolCall = copy(tool_call) - injected_args: dict[str, Any] = {} + injected_args = {} # Inject state if injected.state: @@ -1364,20 +1363,14 @@ class ToolNode(RunnableCallable): # Extract state values if isinstance(state, dict): for tool_arg, state_field in injected.state.items(): - if not state_field: - injected_args[tool_arg] = state - elif state_field in state: - injected_args[tool_arg] = state[state_field] - elif tool_arg not in injected._optional_state_args: - raise KeyError(state_field) + injected_args[tool_arg] = ( + state[state_field] if state_field else state + ) else: for tool_arg, state_field in injected.state.items(): - if not state_field: - injected_args[tool_arg] = state - elif hasattr(state, state_field): - injected_args[tool_arg] = getattr(state, state_field) - elif tool_arg not in injected._optional_state_args: - raise AttributeError(state_field) + injected_args[tool_arg] = ( + getattr(state, state_field) if state_field else state + ) # Inject store if injected.store: @@ -1870,7 +1863,6 @@ def _get_all_injected_args(tool: BaseTool) -> _InjectedArgs: store_arg: str | None = None runtime_arg: str | None = None all_injected_keys: set[str] = set() - _optional_state_args: set[str] = set() for name, type_ in all_annotations.items(): # Track all InjectedToolArg-annotated params (including custom subclasses) @@ -1885,9 +1877,6 @@ def _get_all_injected_args(tool: BaseTool) -> _InjectedArgs: if state_inj := _get_injection_from_type(type_, InjectedState): if isinstance(state_inj, InjectedState) and state_inj.field: state_args[name] = state_inj.field - field_info = full_schema.model_fields.get(name) - if field_info and not field_info.is_required(): - _optional_state_args.add(name) else: state_args[name] = None @@ -1904,5 +1893,4 @@ def _get_all_injected_args(tool: BaseTool) -> _InjectedArgs: store=store_arg, runtime=runtime_arg, all_injected_keys=all_injected_keys, - _optional_state_args=_optional_state_args, )