@@ -572,8 +572,70 @@ 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+ from google .adk .agents .run_config import RunConfig
585+
586+ if "labels" not in RunConfig .model_fields :
587+ pytest .skip ("Installed google-adk RunConfig does not support labels." )
588+
589+ app = agent_engines .AdkApp (agent = _TEST_AGENT )
590+ app .set_up ()
591+
592+ # Pre-create a session in the real in-memory session service.
593+ await app .async_create_session (
594+ user_id = _TEST_USER_ID , session_id = "test_session_id"
595+ )
596+
597+ runner_mock = mock .Mock ()
598+
599+ async def mock_run_async (* args , ** kwargs ):
600+ from google .adk .events import event
601+
602+ yield event .Event (
603+ ** {
604+ "author" : "currency_exchange_agent" ,
605+ "content" : {"parts" : [{"text" : "Sweden" }], "role" : "model" },
606+ "id" : "9aaItGK9" ,
607+ "invocation_id" : "e-6543c213-6417-484b-9551-b67915d1d5f7" ,
608+ }
609+ )
610+
611+ spy = mock .MagicMock (side_effect = mock_run_async )
612+ runner_mock .run_async = spy
613+ app ._tmpl_attrs ["runner" ] = runner_mock
614+
615+ labels = {"goog-originating-logical-product-id" : "prod1" }
616+ request_json = json .dumps (
617+ {
618+ "user_id" : _TEST_USER_ID ,
619+ "session_id" : "test_session_id" ,
620+ "message" : {
621+ "parts" : [{"text" : "What is the exchange rate from USD to SEK?" }],
622+ "role" : "user" ,
623+ },
624+ "labels" : labels ,
625+ }
626+ )
627+
628+ async for _ in app .streaming_agent_run_with_events (
629+ request_json = request_json ,
630+ ):
631+ pass
632+
633+ # The labels are surfaced to run_async via a RunConfig.
634+ spy .assert_called_once ()
635+ run_config = spy .call_args .kwargs ["run_config" ]
636+ assert run_config is not None
637+ assert run_config .labels == labels
638+
577639 @pytest .mark .asyncio
578640 @mock .patch .dict (
579641 os .environ ,
0 commit comments