The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(core): prevent recursion error when args_schema is dict (#35260)
KarthikRed2000a565cf85eb67
diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.pyindex fa3df6d397..7026a2e8fb 100644--- a/libs/core/langchain_core/tools/base.py+++ b/libs/core/langchain_core/tools/base.py@@ -819,7 +819,8 @@ class ChildTool(BaseTool):filtered_keys.update(self._injected_args_keys)# If we have an args_schema, use it to identify injected args- if self.args_schema is not None:+ # Skip if args_schema is a dict (JSON Schema) as it's not a Pydantic model+ if self.args_schema is not None and not isinstance(self.args_schema, dict):try:annotations = get_all_basemodel_annotations(self.args_schema)for field_name, field_type in annotations.items():diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.pyindex 5c1144ac22..1067ecfa69 100644--- a/libs/core/tests/unit_tests/test_tools.py+++ b/libs/core/tests/unit_tests/test_tools.py@@ -2,6 +2,7 @@import inspectimport json+import loggingimport sysimport textwrapimport threading@@ -2632,7 +2633,8 @@ def test_tool_mutate_input() -> None:assert my_input == {"x": "hi"}-def test_structured_tool_args_schema_dict() -> None:+def test_structured_tool_args_schema_dict(caplog: pytest.LogCaptureFixture) -> None:+ caplog.set_level(logging.DEBUG)args_schema = {"properties": {"a": {"title": "A", "type": "integer"},@@ -2666,6 +2668,8 @@ def test_structured_tool_args_schema_dict() -> None:"a": {"title": "A", "type": "integer"},"b": {"title": "B", "type": "integer"},}+ # test that we didn't log an error about failing to get args_schema annotations+ assert "Failed to get args_schema annotations for filtering" not in caplog.textdef test_simple_tool_args_schema_dict() -> None: