The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
core[patch]: fix empty OpenAI tools when strict=True (#26287)
Bagaturfeb351737c55
diff --git a/libs/core/langchain_core/utils/function_calling.py b/libs/core/langchain_core/utils/function_calling.pyindex 67ac7ebd7f..9e239eba37 100644--- a/libs/core/langchain_core/utils/function_calling.py+++ b/libs/core/langchain_core/utils/function_calling.py@@ -605,9 +605,13 @@ def _recursive_set_additional_properties_false(schema: Dict[str, Any],) -> Dict[str, Any]:if isinstance(schema, dict):- # Check if 'required' is a key at the current level- if "required" in schema:+ # Check if 'required' is a key at the current level or if the schema is empty,+ # in which case additionalProperties still needs to be specified.+ if "required" in schema or (+ "properties" in schema and not schema["properties"]+ ):schema["additionalProperties"] = False+# Recursively check 'properties' and 'items' if they existif "properties" in schema:for value in schema["properties"].values():diff --git a/libs/core/tests/unit_tests/utils/test_function_calling.py b/libs/core/tests/unit_tests/utils/test_function_calling.pyindex 9570c52d4c..fee5f4778b 100644--- a/libs/core/tests/unit_tests/utils/test_function_calling.py+++ b/libs/core/tests/unit_tests/utils/test_function_calling.py@@ -793,3 +793,22 @@ def test_convert_union_type_py_39() -> None:assert result["parameters"]["properties"]["input"] == {"anyOf": [{"type": "integer"}, {"type": "number"}]}+++def test_convert_to_openai_function_no_args() -> None:+ @tool+ def empty_tool() -> str:+ """No args"""+ return "foo"++ actual = convert_to_openai_function(empty_tool, strict=True)+ assert actual == {+ "name": "empty_tool",+ "description": "No args",+ "parameters": {+ "properties": {},+ "additionalProperties": False,+ "type": "object",+ },+ "strict": True,+ }