Skip to content

Commit d4cafa4

Browse files
committed
fix(runner): default InMemoryRunner appName to match Python SDK
Default the single-arg InMemoryRunner constructor to "InMemoryRunner" instead of agent.name(), aligning with adk-python.
1 parent 9bcfffd commit d4cafa4

5 files changed

Lines changed: 54 additions & 11 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public ChatResponse call(Prompt prompt) {
7575
// when
7676
Runner runner = new InMemoryRunner(agent);
7777
Session session =
78-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
78+
runner.sessionService().createSession(runner.appName(), "test-user").blockingGet();
7979

8080
Content userMessage =
8181
Content.builder().role("user").parts(List.of(Part.fromText("What is a qubit?"))).build();
@@ -152,7 +152,7 @@ public ChatResponse call(Prompt prompt) {
152152
// when
153153
Runner runner = new InMemoryRunner(agent);
154154
Session session =
155-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
155+
runner.sessionService().createSession(runner.appName(), "test-user").blockingGet();
156156

157157
Content userMessage =
158158
Content.builder()
@@ -221,7 +221,7 @@ public Flux<ChatResponse> stream(Prompt prompt) {
221221
// when
222222
Runner runner = new InMemoryRunner(agent);
223223
Session session =
224-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
224+
runner.sessionService().createSession(runner.appName(), "test-user").blockingGet();
225225

226226
Content userMessage =
227227
Content.builder()

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public static List<Event> askAgent(BaseAgent agent, boolean streaming, Object...
3232
ArrayList<Event> allEvents = new ArrayList<>();
3333

3434
Runner runner = new InMemoryRunner(agent, agent.name());
35-
Session session = runner.sessionService().createSession(agent.name(), "user132").blockingGet();
35+
Session session =
36+
runner.sessionService().createSession(runner.appName(), "user132").blockingGet();
3637

3738
for (Object message : messages) {
3839
Content messageContent = null;
@@ -68,7 +69,7 @@ public static List<Event> askBlockingAgent(BaseAgent agent, Object... messages)
6869

6970
Runner runner = new InMemoryRunner(agent);
7071
Session session =
71-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
72+
runner.sessionService().createSession(runner.appName(), "test-user").blockingGet();
7273

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

@@ -93,7 +94,7 @@ public static List<Event> askAgentStreaming(BaseAgent agent, Object... messages)
9394

9495
Runner runner = new InMemoryRunner(agent);
9596
Session session =
96-
runner.sessionService().createSession(agent.name(), "test-user").blockingGet();
97+
runner.sessionService().createSession(runner.appName(), "test-user").blockingGet();
9798

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

‎core/src/main/java/com/google/adk/runner/InMemoryRunner.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626

2727
/** The class for the in-memory GenAi runner, using in-memory artifact and session services. */
2828
public class InMemoryRunner extends Runner {
29+
private static final String DEFAULT_APP_NAME = "InMemoryRunner";
2930

3031
public InMemoryRunner(BaseAgent agent) {
31-
// TODO: Change the default appName to InMemoryRunner to align with adk python.
32-
// Check the dev UI in case we break something there.
33-
this(agent, /* appName= */ agent.name(), ImmutableList.of());
32+
this(agent, DEFAULT_APP_NAME, ImmutableList.of());
3433
}
3534

3635
public InMemoryRunner(BaseAgent agent, String appName) {

‎core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public void agentRemembersUserNameWithMemoryTool() throws Exception {
8787
.build();
8888

8989
InMemoryRunner runner = new InMemoryRunner(agent);
90-
String sessionId = runner.sessionService().createSession(agentName, userId).blockingGet().id();
90+
String sessionId =
91+
runner.sessionService().createSession(runner.appName(), userId).blockingGet().id();
9192

9293
Content firstMessage = Content.fromParts(Part.fromText("My name is James"));
9394

@@ -101,7 +102,7 @@ public void agentRemembersUserNameWithMemoryTool() throws Exception {
101102
Session updatedSession =
102103
runner
103104
.sessionService()
104-
.getSession("test_agent", userId, sessionId, Optional.empty())
105+
.getSession(runner.appName(), userId, sessionId, Optional.empty())
105106
.blockingGet();
106107

107108
// Save the updated session to memory so we can bring it up on the next request.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.runner;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import com.google.adk.agents.LlmAgent;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.junit.runners.JUnit4;
25+
26+
@RunWith(JUnit4.class)
27+
public final class InMemoryRunnerTest {
28+
29+
@Test
30+
public void defaultAppName_isInMemoryRunner() {
31+
LlmAgent agent = LlmAgent.builder().name("my_agent").model("gemini-2.0-flash").build();
32+
InMemoryRunner runner = new InMemoryRunner(agent);
33+
assertThat(runner.appName()).isEqualTo("InMemoryRunner");
34+
}
35+
36+
@Test
37+
public void explicitAppName_isPreserved() {
38+
LlmAgent agent = LlmAgent.builder().name("my_agent").model("gemini-2.0-flash").build();
39+
InMemoryRunner runner = new InMemoryRunner(agent, "custom-app");
40+
assertThat(runner.appName()).isEqualTo("custom-app");
41+
}
42+
}

0 commit comments

Comments
 (0)