diff --git a/core/src/main/java/com/google/adk/runner/Runner.java b/core/src/main/java/com/google/adk/runner/Runner.java index b96a5605c..ae0dd6b87 100644 --- a/core/src/main/java/com/google/adk/runner/Runner.java +++ b/core/src/main/java/com/google/adk/runner/Runner.java @@ -225,7 +225,12 @@ public Flowable runAsync(String userId, String sessionId, Content newMess return runAsync(userId, sessionId, newMessage, RunConfig.builder().build()); } - /** See {@link #runAsync(Session, Content, RunConfig, Map)}. */ + /** + * See {@link #runAsync(Session, Content, RunConfig, Map)}. + * + * @deprecated Use runAsync with sessionId. + */ + @Deprecated(since = "0.4.0", forRemoval = true) public Flowable runAsync(Session session, Content newMessage, RunConfig runConfig) { return runAsync(session, newMessage, runConfig, /* stateDelta= */ null); } @@ -238,7 +243,9 @@ public Flowable runAsync(Session session, Content newMessage, RunConfig r * @param runConfig Configuration for the agent run. * @param stateDelta Optional map of state updates to merge into the session for this run. * @return A Flowable stream of {@link Event} objects generated by the agent during execution. + * @deprecated Use runAsync with sessionId. */ + @Deprecated(since = "0.4.0", forRemoval = true) public Flowable runAsync( Session session, Content newMessage, @@ -321,14 +328,20 @@ public Flowable runAsync( this.sessionService .appendEvent(updatedSession, agentEvent) .flatMap( - registeredEvent -> - contextWithUpdatedSession - .pluginManager() - .runOnEventCallback( - contextWithUpdatedSession, - registeredEvent) - .defaultIfEmpty( - registeredEvent)) + registeredEvent -> { + // TODO: remove this hack after + // deprecating runAsync with + // Session. + copySessionStates( + updatedSession, session); + return contextWithUpdatedSession + .pluginManager() + .runOnEventCallback( + contextWithUpdatedSession, + registeredEvent) + .defaultIfEmpty( + registeredEvent); + }) .toFlowable()); // If beforeRunCallback returns content, emit it and skip @@ -359,6 +372,13 @@ public Flowable runAsync( } } + private void copySessionStates(Session source, Session target) { + // TODO: remove this hack when deprecating all runAsync with Session. + for (var entry : source.state().entrySet()) { + target.state().put(entry.getKey(), entry.getValue()); + } + } + /** * Creates an {@link InvocationContext} for a live (streaming) run. *