Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions core/src/main/java/com/google/adk/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ public Flowable<Event> 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<Event> runAsync(Session session, Content newMessage, RunConfig runConfig) {
return runAsync(session, newMessage, runConfig, /* stateDelta= */ null);
}
Expand All @@ -238,7 +243,9 @@ public Flowable<Event> 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<Event> runAsync(
Session session,
Content newMessage,
Expand Down Expand Up @@ -321,14 +328,20 @@ public Flowable<Event> 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
Expand Down Expand Up @@ -359,6 +372,13 @@ public Flowable<Event> 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.
*
Expand Down