@@ -1120,3 +1120,89 @@ async def consume_responses(session: testing_utils.Session):
11201120 assert (
11211121 function_response_found
11221122 ), 'Buffered function_response event was not yielded.'
1123+
1124+
1125+ def test_live_streaming_text_content_persisted_in_session ():
1126+ """Test that user text content sent via send_content is persisted in session."""
1127+ response1 = LlmResponse (
1128+ content = types .Content (
1129+ role = 'model' , parts = [types .Part (text = 'Hello! How can I help you?' )]
1130+ ),
1131+ turn_complete = True ,
1132+ )
1133+
1134+ mock_model = testing_utils .MockModel .create ([response1 ])
1135+
1136+ root_agent = Agent (
1137+ name = 'root_agent' ,
1138+ model = mock_model ,
1139+ tools = [],
1140+ )
1141+
1142+ class CustomTestRunner (testing_utils .InMemoryRunner ):
1143+
1144+ def run_live_and_get_session (
1145+ self ,
1146+ live_request_queue : LiveRequestQueue ,
1147+ run_config : testing_utils .RunConfig = None ,
1148+ ) -> tuple [list [testing_utils .Event ], testing_utils .Session ]:
1149+ collected_responses = []
1150+
1151+ async def consume_responses (session : testing_utils .Session ):
1152+ run_res = self .runner .run_live (
1153+ session = session ,
1154+ live_request_queue = live_request_queue ,
1155+ run_config = run_config or testing_utils .RunConfig (),
1156+ )
1157+ async for response in run_res :
1158+ collected_responses .append (response )
1159+ if len (collected_responses ) >= 1 :
1160+ return
1161+
1162+ try :
1163+ session = self .session
1164+ loop = asyncio .new_event_loop ()
1165+ asyncio .set_event_loop (loop )
1166+ try :
1167+ loop .run_until_complete (
1168+ asyncio .wait_for (consume_responses (session ), timeout = 5.0 )
1169+ )
1170+ finally :
1171+ loop .close ()
1172+ except (asyncio .TimeoutError , asyncio .CancelledError ):
1173+ pass
1174+
1175+ # Get the updated session
1176+ updated_session = self .runner .session_service .get_session_sync (
1177+ app_name = self .app_name ,
1178+ user_id = session .user_id ,
1179+ session_id = session .id ,
1180+ )
1181+ return collected_responses , updated_session
1182+
1183+ runner = CustomTestRunner (root_agent = root_agent )
1184+ live_request_queue = LiveRequestQueue ()
1185+
1186+ # Send text content (not audio blob)
1187+ user_text = 'Hello, this is a test message'
1188+ live_request_queue .send_content (
1189+ types .Content (role = 'user' , parts = [types .Part (text = user_text )])
1190+ )
1191+
1192+ res_events , session = runner .run_live_and_get_session (live_request_queue )
1193+
1194+ assert res_events is not None , 'Expected a list of events, got None.'
1195+
1196+ # Check that user text content was persisted in the session
1197+ user_content_found = False
1198+ for event in session .events :
1199+ if event .author == 'user' and event .content :
1200+ for part in event .content .parts :
1201+ if part .text and user_text in part .text :
1202+ user_content_found = True
1203+ break
1204+
1205+ assert user_content_found , (
1206+ f'Expected user text content "{ user_text } " to be persisted in session. '
1207+ f'Session events: { [e .content for e in session .events ]} '
1208+ )
0 commit comments