mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: make LlmAgent.model optional with a default fallback
LlmAgent now resolves model from ancestors or a system default (gemini-2.5-flash) when unset. Added LlmAgent.set_default_model() to override the default globally Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 853006116
This commit is contained in:
committed by
Copybara-Service
parent
742c9265a2
commit
b28721508a
@@ -52,11 +52,24 @@ async def _create_readonly_context(
|
||||
return ReadonlyContext(invocation_context)
|
||||
|
||||
|
||||
def test_canonical_model_empty():
|
||||
agent = LlmAgent(name='test_agent')
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
_ = agent.canonical_model
|
||||
@pytest.mark.parametrize(
|
||||
('default_model', 'expected_model_name', 'expected_model_type'),
|
||||
[
|
||||
(LlmAgent.DEFAULT_MODEL, LlmAgent.DEFAULT_MODEL, Gemini),
|
||||
('gemini-2.0-flash', 'gemini-2.0-flash', Gemini),
|
||||
],
|
||||
)
|
||||
def test_canonical_model_default_fallback(
|
||||
default_model, expected_model_name, expected_model_type
|
||||
):
|
||||
original_default = LlmAgent._default_model
|
||||
LlmAgent.set_default_model(default_model)
|
||||
try:
|
||||
agent = LlmAgent(name='test_agent')
|
||||
assert isinstance(agent.canonical_model, expected_model_type)
|
||||
assert agent.canonical_model.model == expected_model_name
|
||||
finally:
|
||||
LlmAgent.set_default_model(original_default)
|
||||
|
||||
|
||||
def test_canonical_model_str():
|
||||
|
||||
@@ -110,7 +110,9 @@ class TestBasicLlmRequestProcessor:
|
||||
assert llm_request.config.response_mime_type != 'application/json'
|
||||
|
||||
# Should have checked if output schema can be used with tools
|
||||
can_use_output_schema_with_tools.assert_called_once_with(agent.model)
|
||||
can_use_output_schema_with_tools.assert_called_once_with(
|
||||
agent.canonical_model
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sets_output_schema_when_tools_present(self, mocker):
|
||||
@@ -141,7 +143,9 @@ class TestBasicLlmRequestProcessor:
|
||||
assert llm_request.config.response_mime_type == 'application/json'
|
||||
|
||||
# Should have checked if output schema can be used with tools
|
||||
can_use_output_schema_with_tools.assert_called_once_with(agent.model)
|
||||
can_use_output_schema_with_tools.assert_called_once_with(
|
||||
agent.canonical_model
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_no_output_schema_no_tools(self):
|
||||
|
||||
@@ -191,7 +191,9 @@ async def test_output_schema_request_processor(
|
||||
assert not llm_request.config.system_instruction
|
||||
|
||||
# Should have checked if output schema can be used with tools
|
||||
can_use_output_schema_with_tools.assert_called_once_with(agent.model)
|
||||
can_use_output_schema_with_tools.assert_called_once_with(
|
||||
agent.canonical_model
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user