Skip to content

Commit 4c6f22e

Browse files
GWealecopybara-github
authored andcommitted
fix: allow http_options.extra_body in generate_content_config
Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 953974464
1 parent 8addc44 commit 4c6f22e

2 files changed

Lines changed: 11 additions & 26 deletions

File tree

src/google/adk/agents/llm_agent.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,18 +1089,14 @@ def validate_generate_content_config(
10891089
raise ValueError(
10901090
'Response schema must be set via LlmAgent.output_schema.'
10911091
)
1092-
if generate_content_config.http_options:
1093-
if generate_content_config.http_options.base_url:
1094-
raise ValueError(
1095-
'Base URL is a transport setting and must be set on the model or'
1096-
' its client, not via LlmAgent.generate_content_config.'
1097-
)
1098-
if generate_content_config.http_options.extra_body:
1099-
raise ValueError(
1100-
'Extra body is merged into the request body and can overwrite the'
1101-
' tools, system instruction and response schema rejected above.'
1102-
' Set it on the model or its client.'
1103-
)
1092+
if (
1093+
generate_content_config.http_options
1094+
and generate_content_config.http_options.base_url
1095+
):
1096+
raise ValueError(
1097+
'Base URL is a transport setting and must be set on the model or'
1098+
' its client, not via LlmAgent.generate_content_config.'
1099+
)
11041100
return generate_content_config
11051101

11061102
@override

tests/unittests/agents/test_llm_agent_fields.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,29 +340,18 @@ def test_validate_generate_content_config_http_options_base_url_throw():
340340
)
341341

342342

343-
def test_validate_generate_content_config_http_options_extra_body_throw():
344-
"""Tests that an extra request body cannot be set directly in config."""
345-
with pytest.raises(ValueError):
346-
_ = LlmAgent(
347-
name='test_agent',
348-
generate_content_config=types.GenerateContentConfig(
349-
http_options=types.HttpOptions(
350-
extra_body={'systemInstruction': {'parts': [{'text': 'hi'}]}}
351-
)
352-
),
353-
)
354-
355-
356343
def test_validate_generate_content_config_http_options_allowed():
357344
"""Tests that request-time http options remain settable in config."""
345+
extra_body = {'tool_config': {'function_calling_config': {'mode': 'AUTO'}}}
358346
agent = LlmAgent(
359347
name='test_agent',
360348
generate_content_config=types.GenerateContentConfig(
361-
http_options=types.HttpOptions(timeout=1000)
349+
http_options=types.HttpOptions(timeout=1000, extra_body=extra_body)
362350
),
363351
)
364352

365353
assert agent.generate_content_config.http_options.timeout == 1000
354+
assert agent.generate_content_config.http_options.extra_body == extra_body
366355

367356

368357
def test_allow_transfer_by_default():

0 commit comments

Comments
 (0)