@@ -1620,6 +1620,44 @@ public void runLive_success() throws Exception {
16201620 assertThat (simplifyEvents (testSubscriber .values ())).containsExactly ("test agent: from llm" );
16211621 }
16221622
1623+ @ Test
1624+ public void runLive_asyncSessionService_persistsEvents () throws Exception {
1625+ BaseSessionService asyncSessionService =
1626+ new AppendDelayingSessionService (new InMemorySessionService (), 10 );
1627+ Runner runnerWithAsyncSession =
1628+ Runner .builder ()
1629+ .app (App .builder ().name ("test" ).rootAgent (agent ).build ())
1630+ .sessionService (asyncSessionService )
1631+ .build ();
1632+ Session asyncSession =
1633+ runnerWithAsyncSession .sessionService ().createSession ("test" , "user" ).blockingGet ();
1634+
1635+ LiveRequestQueue liveRequestQueue = new LiveRequestQueue ();
1636+ TestSubscriber <Event > testSubscriber =
1637+ runnerWithAsyncSession
1638+ .runLive (asyncSession , liveRequestQueue , RunConfig .builder ().build ())
1639+ .test ();
1640+
1641+ liveRequestQueue .content (createContent ("from user" ));
1642+ liveRequestQueue .close ();
1643+
1644+ testSubscriber .await ();
1645+ testSubscriber .assertComplete ();
1646+ assertThat (simplifyEvents (testSubscriber .values ())).containsExactly ("test agent: from llm" );
1647+
1648+ // Verify that the events are successfully persisted to session history.
1649+ ImmutableList <Event > history =
1650+ runnerWithAsyncSession
1651+ .sessionService ()
1652+ .listEvents ("test" , "user" , asyncSession .id ())
1653+ .blockingGet ()
1654+ .events ();
1655+ // The history should contain only the agent response event (user messages in liveQueue are not
1656+ // persisted).
1657+ assertThat (history ).hasSize (1 );
1658+ assertThat (history .get (0 ).author ()).isEqualTo ("test agent" );
1659+ }
1660+
16231661 @ Test
16241662 public void runLive_withSessionKey_success () throws Exception {
16251663 LiveRequestQueue liveRequestQueue = new LiveRequestQueue ();
0 commit comments