Skip to content

Commit 7b1d498

Browse files
yyyu-googlecopybara-github
authored andcommitted
fix: include all fields of a single tool
PiperOrigin-RevId: 923058442
1 parent bbef98e commit 7b1d498

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

google/genai/_transformers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,10 @@ def t_tools(
993993
function_tool.function_declarations += (
994994
transformed_tool.function_declarations
995995
)
996+
tool_copy = transformed_tool.model_copy()
997+
tool_copy.function_declarations = None
998+
if tool_copy.model_dump(exclude_none=True):
999+
tools.append(tool_copy)
9961000
else:
9971001
tools.append(transformed_tool)
9981002
if function_tool.function_declarations:

google/genai/tests/models/test_generate_content_tools.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,75 @@ def test_function_google_search(client):
719719
# bad request to combine function call and google search retrieval
720720
with pytest.raises(errors.ClientError):
721721
client.models.generate_content(
722-
model='gemini-2.5-flash',
722+
model='gemini-3.5-flash',
723+
contents=contents,
724+
config=config,
725+
)
726+
727+
728+
def test_function_google_search_server_side_tool_invocations(client):
729+
contents = (
730+
'What is the weather in Buenos Aires? If it is raining, schedule a'
731+
' meeting.'
732+
)
733+
schedule_meeting = {
734+
'name': 'schedule_meeting',
735+
'description': 'Schedule a meeting',
736+
'parameters': {
737+
'type': 'object',
738+
'properties': {'reason': {'type': 'string'}},
739+
'required': ['reason'],
740+
},
741+
}
742+
config = types.GenerateContentConfig(
743+
tools=[
744+
types.Tool(
745+
google_search=types.GoogleSearch(),
746+
),
747+
types.Tool(
748+
function_declarations=[schedule_meeting],
749+
),
750+
],
751+
tool_config=types.ToolConfig(
752+
include_server_side_tool_invocations=True,
753+
),
754+
)
755+
with pytest_helper.exception_if_vertex(client, ValueError):
756+
client.models.generate_content(
757+
model='gemini-3.5-flash',
758+
contents=contents,
759+
config=config,
760+
)
761+
762+
763+
def test_function_google_search_server_side_tool_invocations_one_tool(client):
764+
contents = (
765+
'What is the weather in Buenos Aires? If it is raining, schedule a'
766+
' meeting.'
767+
)
768+
schedule_meeting = {
769+
'name': 'schedule_meeting',
770+
'description': 'Schedule a meeting',
771+
'parameters': {
772+
'type': 'object',
773+
'properties': {'reason': {'type': 'string'}},
774+
'required': ['reason'],
775+
},
776+
}
777+
config = types.GenerateContentConfig(
778+
tools=[
779+
types.Tool(
780+
google_search=types.GoogleSearch(),
781+
function_declarations=[schedule_meeting],
782+
),
783+
],
784+
tool_config=types.ToolConfig(
785+
include_server_side_tool_invocations=True,
786+
),
787+
)
788+
with pytest_helper.exception_if_vertex(client, ValueError):
789+
client.models.generate_content(
790+
model='gemini-3.5-flash',
723791
contents=contents,
724792
config=config,
725793
)

0 commit comments

Comments
 (0)