Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/google/adk/models/anthropic_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 63 additions & 0 deletions tests/unittests/models/test_anthropic_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading