Skip to content

Commit 0d8e22d

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: Removing deprecated methods in Runner
PiperOrigin-RevId: 881637295
1 parent b857f01 commit 0d8e22d

4 files changed

Lines changed: 56 additions & 26 deletions

File tree

contrib/langchain4j/src/test/java/com/google/adk/models/langchain4j/RunLoop.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public static List<Event> runLoop(BaseAgent agent, boolean streaming, Object...
5353
allEvents.addAll(
5454
runner
5555
.runAsync(
56-
session.userId(),
57-
session.id(),
56+
session,
5857
messageContent,
5958
RunConfig.builder()
6059
.setStreamingMode(

contrib/spring-ai/src/test/java/com/google/adk/models/springai/SpringAIIntegrationTest.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static org.junit.jupiter.api.Assertions.*;
1919

2020
import com.google.adk.agents.LlmAgent;
21-
import com.google.adk.agents.RunConfig;
2221
import com.google.adk.events.Event;
2322
import com.google.adk.models.springai.integrations.tools.WeatherTool;
2423
import com.google.adk.runner.InMemoryRunner;
@@ -74,15 +73,14 @@ public ChatResponse call(Prompt prompt) {
7473

7574
// when
7675
Runner runner = new InMemoryRunner(agent);
77-
Session session =
78-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
76+
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();
7977

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

8381
List<Event> events =
8482
runner
85-
.runAsync(session.userId(), session.id(), userMessage, RunConfig.builder().build())
83+
.runAsync(session, userMessage, com.google.adk.agents.RunConfig.builder().build())
8684
.toList()
8785
.blockingGet();
8886

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

152150
// when
153151
Runner runner = new InMemoryRunner(agent);
154-
Session session =
155-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
152+
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();
156153

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

163160
List<Event> events =
164161
runner
165-
.runAsync(session.userId(), session.id(), userMessage, RunConfig.builder().build())
162+
.runAsync(session, userMessage, com.google.adk.agents.RunConfig.builder().build())
166163
.toList()
167164
.blockingGet();
168165

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

221218
// when
222219
Runner runner = new InMemoryRunner(agent);
223-
Session session =
224-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
220+
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();
225221

226222
Content userMessage =
227223
Content.builder()
@@ -232,10 +228,11 @@ public Flux<ChatResponse> stream(Prompt prompt) {
232228
List<Event> events =
233229
runner
234230
.runAsync(
235-
session.userId(),
236-
session.id(),
231+
session,
237232
userMessage,
238-
RunConfig.builder().setStreamingMode(RunConfig.StreamingMode.SSE).build())
233+
com.google.adk.agents.RunConfig.builder()
234+
.setStreamingMode(com.google.adk.agents.RunConfig.StreamingMode.SSE)
235+
.build())
239236
.toList()
240237
.blockingGet();
241238

contrib/spring-ai/src/test/java/com/google/adk/models/springai/TestUtils.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public static List<Event> askAgent(BaseAgent agent, boolean streaming, Object...
4646
allEvents.addAll(
4747
runner
4848
.runAsync(
49-
session.userId(),
50-
session.id(),
49+
session,
5150
messageContent,
5251
RunConfig.builder()
5352
.setStreamingMode(
@@ -68,17 +67,13 @@ public static List<Event> askBlockingAgent(BaseAgent agent, Object... messages)
6867
}
6968

7069
Runner runner = new InMemoryRunner(agent);
71-
Session session =
72-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
70+
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();
7371

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

7674
for (Content content : contents) {
7775
List<Event> batchEvents =
78-
runner
79-
.runAsync(session.userId(), session.id(), content, RunConfig.builder().build())
80-
.toList()
81-
.blockingGet();
76+
runner.runAsync(session, content, RunConfig.builder().build()).toList().blockingGet();
8277
events.addAll(batchEvents);
8378
}
8479

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

9590
Runner runner = new InMemoryRunner(agent);
96-
Session session =
97-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
91+
Session session = runner.sessionService().createSession("test-app", "test-user").blockingGet();
9892

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

10195
for (Content content : contents) {
10296
List<Event> batchEvents =
10397
runner
10498
.runAsync(
105-
session.userId(),
106-
session.id(),
99+
session,
107100
content,
108101
RunConfig.builder().setStreamingMode(RunConfig.StreamingMode.SSE).build())
109102
.toList()

core/src/main/java/com/google/adk/runner/Runner.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,35 @@ public Flowable<Event> runAsync(String userId, String sessionId, Content newMess
415415
return runAsync(userId, sessionId, newMessage, RunConfig.builder().build());
416416
}
417417

418+
/**
419+
* See {@link #runAsync(Session, Content, RunConfig, Map)}.
420+
*
421+
* @deprecated Use runAsync with sessionId.
422+
*/
423+
@Deprecated(since = "0.4.0", forRemoval = true)
424+
public Flowable<Event> runAsync(Session session, Content newMessage, RunConfig runConfig) {
425+
return runAsync(session, newMessage, runConfig, /* stateDelta= */ null);
426+
}
427+
428+
/**
429+
* Runs the agent asynchronously using a provided Session object.
430+
*
431+
* @param session The session to run the agent in.
432+
* @param newMessage The new message from the user to process.
433+
* @param runConfig Configuration for the agent run.
434+
* @param stateDelta Optional map of state updates to merge into the session for this run.
435+
* @return A Flowable stream of {@link Event} objects generated by the agent during execution.
436+
* @deprecated Use runAsync with sessionId.
437+
*/
438+
@Deprecated(since = "0.4.0", forRemoval = true)
439+
public Flowable<Event> runAsync(
440+
Session session,
441+
Content newMessage,
442+
RunConfig runConfig,
443+
@Nullable Map<String, Object> stateDelta) {
444+
return runAsyncImpl(session, newMessage, runConfig, stateDelta);
445+
}
446+
418447
/**
419448
* Runs the agent asynchronously using a provided Session object.
420449
*
@@ -681,6 +710,18 @@ public Flowable<Event> runLive(
681710
return runLive(sessionKey.userId(), sessionKey.id(), liveRequestQueue, runConfig);
682711
}
683712

713+
/**
714+
* Runs the agent asynchronously with a default user ID.
715+
*
716+
* @return stream of generated events.
717+
*/
718+
@Deprecated(since = "0.5.0", forRemoval = true)
719+
public Flowable<Event> runWithSessionId(
720+
String sessionId, Content newMessage, RunConfig runConfig) {
721+
// TODO(b/410859954): Add user_id to getter or method signature. Assuming "tmp-user" for now.
722+
return this.runAsync("tmp-user", sessionId, newMessage, runConfig);
723+
}
724+
684725
/**
685726
* Checks if the agent and its parent chain allow transfer up the tree.
686727
*

0 commit comments

Comments
 (0)