Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public static List<Event> runLoop(BaseAgent agent, boolean streaming, Object...
allEvents.addAll(
runner
.runAsync(
session.userId(),
session.id(),
session,
messageContent,
RunConfig.builder()
.setStreamingMode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.junit.jupiter.api.Assertions.*;

import com.google.adk.agents.LlmAgent;
import com.google.adk.agents.RunConfig;
import com.google.adk.events.Event;
import com.google.adk.models.springai.integrations.tools.WeatherTool;
import com.google.adk.runner.InMemoryRunner;
Expand Down Expand Up @@ -74,15 +73,14 @@ public ChatResponse call(Prompt prompt) {

// when
Runner runner = new InMemoryRunner(agent);
Session session =
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();

Content userMessage =
Content.builder().role("user").parts(List.of(Part.fromText("What is a qubit?"))).build();

List<Event> events =
runner
.runAsync(session.userId(), session.id(), userMessage, RunConfig.builder().build())
.runAsync(session, userMessage, com.google.adk.agents.RunConfig.builder().build())
.toList()
.blockingGet();

Expand Down Expand Up @@ -151,8 +149,7 @@ public ChatResponse call(Prompt prompt) {

// when
Runner runner = new InMemoryRunner(agent);
Session session =
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();

Content userMessage =
Content.builder()
Expand All @@ -162,7 +159,7 @@ public ChatResponse call(Prompt prompt) {

List<Event> events =
runner
.runAsync(session.userId(), session.id(), userMessage, RunConfig.builder().build())
.runAsync(session, userMessage, com.google.adk.agents.RunConfig.builder().build())
.toList()
.blockingGet();

Expand Down Expand Up @@ -220,8 +217,7 @@ public Flux<ChatResponse> stream(Prompt prompt) {

// when
Runner runner = new InMemoryRunner(agent);
Session session =
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();

Content userMessage =
Content.builder()
Expand All @@ -232,10 +228,11 @@ public Flux<ChatResponse> stream(Prompt prompt) {
List<Event> events =
runner
.runAsync(
session.userId(),
session.id(),
session,
userMessage,
RunConfig.builder().setStreamingMode(RunConfig.StreamingMode.SSE).build())
com.google.adk.agents.RunConfig.builder()
.setStreamingMode(com.google.adk.agents.RunConfig.StreamingMode.SSE)
.build())
.toList()
.blockingGet();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public static List<Event> askAgent(BaseAgent agent, boolean streaming, Object...
allEvents.addAll(
runner
.runAsync(
session.userId(),
session.id(),
session,
messageContent,
RunConfig.builder()
.setStreamingMode(
Expand All @@ -68,17 +67,13 @@ public static List<Event> askBlockingAgent(BaseAgent agent, Object... messages)
}

Runner runner = new InMemoryRunner(agent);
Session session =
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();

List<Event> events = new ArrayList<>();

for (Content content : contents) {
List<Event> batchEvents =
runner
.runAsync(session.userId(), session.id(), content, RunConfig.builder().build())
.toList()
.blockingGet();
runner.runAsync(session, content, RunConfig.builder().build()).toList().blockingGet();
events.addAll(batchEvents);
}

Expand All @@ -93,17 +88,15 @@ public static List<Event> askAgentStreaming(BaseAgent agent, Object... messages)
}

Runner runner = new InMemoryRunner(agent);
Session session =
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();

List<Event> events = new ArrayList<>();

for (Content content : contents) {
List<Event> batchEvents =
runner
.runAsync(
session.userId(),
session.id(),
session,
content,
RunConfig.builder().setStreamingMode(RunConfig.StreamingMode.SSE).build())
.toList()
Expand Down
41 changes: 41 additions & 0 deletions core/src/main/java/com/google/adk/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,35 @@ 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)}.
*
* @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);
}

/**
* Runs the agent asynchronously using a provided Session object.
*
* @param session The session to run the agent in.
* @param newMessage The new message from the user to process.
* @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,
RunConfig runConfig,
@Nullable Map<String, Object> stateDelta) {
return runAsyncImpl(session, newMessage, runConfig, stateDelta);
}

/**
* Runs the agent asynchronously using a provided Session object.
*
Expand Down Expand Up @@ -681,6 +710,18 @@ public Flowable<Event> runLive(
return runLive(sessionKey.userId(), sessionKey.id(), liveRequestQueue, runConfig);
}

/**
* Runs the agent asynchronously with a default user ID.
*
* @return stream of generated events.
*/
@Deprecated(since = "0.5.0", forRemoval = true)
public Flowable<Event> runWithSessionId(
String sessionId, Content newMessage, RunConfig runConfig) {
// TODO(b/410859954): Add user_id to getter or method signature. Assuming "tmp-user" for now.
return this.runAsync("tmp-user", sessionId, newMessage, runConfig);
}

/**
* Checks if the agent and its parent chain allow transfer up the tree.
*
Expand Down