@@ -572,8 +572,65 @@ async def mock_run_async(*args, **kwargs):
572572 session_id = "test_session_id" ,
573573 new_message = mock .ANY ,
574574 state_delta = {"test_user_id1" : "test_access_token" },
575+ run_config = None ,
575576 )
576577
578+ @pytest .mark .asyncio
579+ async def test_streaming_agent_run_with_events_propagates_labels (
580+ self ,
581+ default_instrumentor_builder_mock : mock .Mock ,
582+ get_project_id_mock : mock .Mock ,
583+ ):
584+ app = agent_engines .AdkApp (agent = _TEST_AGENT )
585+ app .set_up ()
586+
587+ # Pre-create a session in the real in-memory session service.
588+ await app .async_create_session (
589+ user_id = _TEST_USER_ID , session_id = "test_session_id"
590+ )
591+
592+ runner_mock = mock .Mock ()
593+
594+ async def mock_run_async (* args , ** kwargs ):
595+ from google .adk .events import event
596+
597+ yield event .Event (
598+ ** {
599+ "author" : "currency_exchange_agent" ,
600+ "content" : {"parts" : [{"text" : "Sweden" }], "role" : "model" },
601+ "id" : "9aaItGK9" ,
602+ "invocation_id" : "e-6543c213-6417-484b-9551-b67915d1d5f7" ,
603+ }
604+ )
605+
606+ spy = mock .MagicMock (side_effect = mock_run_async )
607+ runner_mock .run_async = spy
608+ app ._tmpl_attrs ["runner" ] = runner_mock
609+
610+ labels = {"goog-originating-logical-product-id" : "prod1" }
611+ request_json = json .dumps (
612+ {
613+ "user_id" : _TEST_USER_ID ,
614+ "session_id" : "test_session_id" ,
615+ "message" : {
616+ "parts" : [{"text" : "What is the exchange rate from USD to SEK?" }],
617+ "role" : "user" ,
618+ },
619+ "labels" : labels ,
620+ }
621+ )
622+
623+ async for _ in app .streaming_agent_run_with_events (
624+ request_json = request_json ,
625+ ):
626+ pass
627+
628+ # The labels are surfaced to run_async via a RunConfig.
629+ spy .assert_called_once ()
630+ run_config = spy .call_args .kwargs ["run_config" ]
631+ assert run_config is not None
632+ assert run_config .labels == labels
633+
577634 @pytest .mark .asyncio
578635 @mock .patch .dict (
579636 os .environ ,
0 commit comments