diff --git a/src/google/adk/models/anthropic_llm.py b/src/google/adk/models/anthropic_llm.py index 9799209695..9811733fea 100644 --- a/src/google/adk/models/anthropic_llm.py +++ b/src/google/adk/models/anthropic_llm.py @@ -218,18 +218,15 @@ def _update_type_string(value_dict: dict[str, Any]): if "type" in value_dict: value_dict["type"] = value_dict["type"].lower() + if "properties" in value_dict: + for _, value in value_dict["properties"].items(): + _update_type_string(value) + if "items" in value_dict: # 'type' field could exist for items as well, this would be the case if # items represent primitive types. _update_type_string(value_dict["items"]) - if "properties" in value_dict["items"]: - # There could be properties as well on the items, especially if the items - # are complex object themselves. We recursively traverse each individual - # property as well and fix the "type" value. - for _, value in value_dict["items"]["properties"].items(): - _update_type_string(value) - def function_declaration_to_tool_param( function_declaration: types.FunctionDeclaration, diff --git a/tests/unittests/models/test_anthropic_llm.py b/tests/unittests/models/test_anthropic_llm.py index fac5f46204..b0a282d170 100644 --- a/tests/unittests/models/test_anthropic_llm.py +++ b/tests/unittests/models/test_anthropic_llm.py @@ -275,6 +275,69 @@ def test_supported_models(): }, ), ), + ( + "function_with_nested_object_parameter", + types.FunctionDeclaration( + name="update_profile", + description="Updates a user profile.", + parameters=types.Schema( + type=types.Type.OBJECT, + properties={ + "profile": types.Schema( + type=types.Type.OBJECT, + description="The profile data", + properties={ + "name": types.Schema( + type=types.Type.STRING, + description="Full name", + ), + "address": types.Schema( + type=types.Type.OBJECT, + description="Mailing address", + properties={ + "city": types.Schema( + type=types.Type.STRING, + ), + "state": types.Schema( + type=types.Type.STRING, + ), + }, + ), + }, + ), + }, + required=["profile"], + ), + ), + anthropic_types.ToolParam( + name="update_profile", + description="Updates a user profile.", + input_schema={ + "type": "object", + "properties": { + "profile": { + "type": "object", + "description": "The profile data", + "properties": { + "name": { + "type": "string", + "description": "Full name", + }, + "address": { + "type": "object", + "description": "Mailing address", + "properties": { + "city": {"type": "string"}, + "state": {"type": "string"}, + }, + }, + }, + }, + }, + "required": ["profile"], + }, + ), + ), ( "function_with_parameters_json_schema", types.FunctionDeclaration(