Skip to content

The agent engineering platform.

fix: tool call id bug introduced w/ runtime injection (#34185)

Sydney Runkle8e3ca21bd321
diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.py
index e2da7a5685..22f06f86df 100644
--- a/libs/core/langchain_core/tools/base.py
+++ b/libs/core/langchain_core/tools/base.py
@@ -696,7 +696,9 @@ class ChildTool(BaseTool):
k: getattr(result, k) for k in result_dict if k in tool_input
}
for k in self._injected_args_keys:
- if k == "tool_call_id":
+ if k in tool_input:
+ validated_input[k] = tool_input[k]
+ elif k == "tool_call_id":
if tool_call_id is None:
msg = (
"When tool includes an InjectedToolCallId "
@@ -707,9 +709,6 @@ class ChildTool(BaseTool):
)
raise ValueError(msg)
validated_input[k] = tool_call_id
- if k in tool_input:
- injected_val = tool_input[k]
- validated_input[k] = injected_val
return validated_input
return tool_input
diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py
index 87b3e00465..babb481752 100644
--- a/libs/core/tests/unit_tests/test_tools.py
+++ b/libs/core/tests/unit_tests/test_tools.py
@@ -2396,6 +2396,10 @@ def test_tool_injected_tool_call_id_with_custom_schema() -> None:
):
injected_tool.invoke({"x": 42})
+ # Test that tool_call_id can be passed directly in input dict
+ result = injected_tool.invoke({"x": 42, "tool_call_id": "direct_id"})
+ assert result == ToolMessage("42", tool_call_id="direct_id")
+
def test_tool_injected_arg_with_custom_schema() -> None:
"""Ensure InjectedToolArg works with custom args schema."""