@@ -1487,8 +1487,15 @@ async def mock_receive_2():
14871487
14881488
14891489@pytest .mark .asyncio
1490- async def test_run_live_history_config_set_for_gemini_api_backend ():
1491- """history_config is auto-set when seeding history on the Gemini API backend."""
1490+ @pytest .mark .parametrize (
1491+ 'api_backend' ,
1492+ [
1493+ GoogleLLMVariant .GEMINI_API ,
1494+ GoogleLLMVariant .VERTEX_AI ,
1495+ ],
1496+ )
1497+ async def test_run_live_history_config_set_for_all_backends (api_backend ):
1498+ """Test that run_live sets history_config for all backends."""
14921499
14931500 real_model = Gemini (model = 'gemini-3.1-flash-live-preview' )
14941501 mock_connection = mock .AsyncMock ()
@@ -1535,7 +1542,7 @@ async def mock_receive():
15351542 Gemini ,
15361543 '_api_backend' ,
15371544 new_callable = mock .PropertyMock ,
1538- return_value = GoogleLLMVariant . GEMINI_API ,
1545+ return_value = api_backend ,
15391546 ):
15401547 try :
15411548 async for _ in flow .run_live (invocation_context ):
@@ -1553,75 +1560,6 @@ async def mock_receive():
15531560 )
15541561
15551562
1556- @pytest .mark .asyncio
1557- async def test_run_live_history_config_not_set_for_vertex_backend ():
1558- """history_config is NOT auto-set on the Vertex backend (it rejects it).
1559-
1560- The Vertex AI / Gemini Enterprise Agent Platform live setup message has no
1561- ``history``/``history_config`` field. ADK seeds Vertex history via
1562- ``send_history`` (``send_client_content``) instead, so the auto-injection of
1563- ``history_config`` must be skipped for this backend.
1564- """
1565-
1566- real_model = Gemini (model = 'gemini-3.1-flash-live-preview' )
1567- mock_connection = mock .AsyncMock ()
1568-
1569- class StopTestError (Exception ):
1570- pass
1571-
1572- async def mock_receive ():
1573- yield LlmResponse (
1574- content = types .Content (parts = [types .Part .from_text (text = 'hi' )])
1575- )
1576- raise StopTestError ('stop' )
1577-
1578- mock_connection .receive = mock .Mock (side_effect = mock_receive )
1579-
1580- agent = Agent (name = 'test_agent' , model = real_model )
1581- invocation_context = await testing_utils .create_invocation_context (
1582- agent = agent
1583- )
1584- invocation_context .live_request_queue = LiveRequestQueue ()
1585-
1586- flow = BaseLlmFlowForTesting ()
1587-
1588- with mock .patch .object (flow , '_send_to_model' , new_callable = AsyncMock ):
1589-
1590- async def mock_preprocess (ctx , req ):
1591- req .contents = [
1592- types .Content (parts = [types .Part .from_text (text = 'history' )])
1593- ]
1594- yield Event (id = Event .new_id (), author = 'test' )
1595-
1596- with mock .patch .object (
1597- flow , '_preprocess_async' , side_effect = mock_preprocess
1598- ):
1599- with mock .patch .object (
1600- Gemini , '_api_backend' , new_callable = mock .PropertyMock
1601- ) as mock_backend :
1602- mock_backend .return_value = GoogleLLMVariant .VERTEX_AI
1603- with mock .patch (
1604- 'google.adk.models.google_llm.Gemini.connect'
1605- ) as mock_connect :
1606- mock_connect .return_value .__aenter__ .return_value = mock_connection
1607-
1608- try :
1609- async for _ in flow .run_live (invocation_context ):
1610- pass
1611- except StopTestError :
1612- pass
1613-
1614- assert mock_connect .call_count == 1
1615- called_req = mock_connect .call_args [0 ][0 ]
1616- # history_config must NOT be auto-injected on Vertex.
1617- assert (
1618- called_req .live_connect_config is None
1619- or called_req .live_connect_config .history_config is None
1620- )
1621- # History is still seeded via send_history (send_client_content).
1622- mock_connection .send_history .assert_awaited_once ()
1623-
1624-
16251563@pytest .mark .asyncio
16261564async def test_run_live_respects_explicit_initial_history_in_client_content_false ():
16271565 """Test that run_live respects explicit initial_history_in_client_content=False in RunConfig."""
0 commit comments