diff --git a/contrib/spring-ai/src/test/java/com/google/adk/models/springai/SpringAIIntegrationTest.java b/contrib/spring-ai/src/test/java/com/google/adk/models/springai/SpringAIIntegrationTest.java index 328df0415..d64e3a549 100644 --- a/contrib/spring-ai/src/test/java/com/google/adk/models/springai/SpringAIIntegrationTest.java +++ b/contrib/spring-ai/src/test/java/com/google/adk/models/springai/SpringAIIntegrationTest.java @@ -75,7 +75,7 @@ public ChatResponse call(Prompt prompt) { // when Runner runner = new InMemoryRunner(agent); Session session = - runner.sessionService().createSession(agent.name(), "test-user").blockingGet(); + runner.sessionService().createSession(runner.appName(), "test-user").blockingGet(); Content userMessage = Content.builder().role("user").parts(List.of(Part.fromText("What is a qubit?"))).build(); @@ -152,7 +152,7 @@ public ChatResponse call(Prompt prompt) { // when Runner runner = new InMemoryRunner(agent); Session session = - runner.sessionService().createSession(agent.name(), "test-user").blockingGet(); + runner.sessionService().createSession(runner.appName(), "test-user").blockingGet(); Content userMessage = Content.builder() @@ -221,7 +221,7 @@ public Flux stream(Prompt prompt) { // when Runner runner = new InMemoryRunner(agent); Session session = - runner.sessionService().createSession(agent.name(), "test-user").blockingGet(); + runner.sessionService().createSession(runner.appName(), "test-user").blockingGet(); Content userMessage = Content.builder() diff --git a/contrib/spring-ai/src/test/java/com/google/adk/models/springai/TestUtils.java b/contrib/spring-ai/src/test/java/com/google/adk/models/springai/TestUtils.java index c23e68eae..738cace9b 100644 --- a/contrib/spring-ai/src/test/java/com/google/adk/models/springai/TestUtils.java +++ b/contrib/spring-ai/src/test/java/com/google/adk/models/springai/TestUtils.java @@ -32,7 +32,8 @@ public static List askAgent(BaseAgent agent, boolean streaming, Object... ArrayList allEvents = new ArrayList<>(); Runner runner = new InMemoryRunner(agent, agent.name()); - Session session = runner.sessionService().createSession(agent.name(), "user132").blockingGet(); + Session session = + runner.sessionService().createSession(runner.appName(), "user132").blockingGet(); for (Object message : messages) { Content messageContent = null; @@ -68,7 +69,7 @@ public static List askBlockingAgent(BaseAgent agent, Object... messages) Runner runner = new InMemoryRunner(agent); Session session = - runner.sessionService().createSession(agent.name(), "test-user").blockingGet(); + runner.sessionService().createSession(runner.appName(), "test-user").blockingGet(); List events = new ArrayList<>(); @@ -93,7 +94,7 @@ public static List askAgentStreaming(BaseAgent agent, Object... messages) Runner runner = new InMemoryRunner(agent); Session session = - runner.sessionService().createSession(agent.name(), "test-user").blockingGet(); + runner.sessionService().createSession(runner.appName(), "test-user").blockingGet(); List events = new ArrayList<>(); diff --git a/core/src/main/java/com/google/adk/runner/InMemoryRunner.java b/core/src/main/java/com/google/adk/runner/InMemoryRunner.java index 58741003c..afd38dc1e 100644 --- a/core/src/main/java/com/google/adk/runner/InMemoryRunner.java +++ b/core/src/main/java/com/google/adk/runner/InMemoryRunner.java @@ -26,11 +26,10 @@ /** The class for the in-memory GenAi runner, using in-memory artifact and session services. */ public class InMemoryRunner extends Runner { + private static final String DEFAULT_APP_NAME = "InMemoryRunner"; public InMemoryRunner(BaseAgent agent) { - // TODO: Change the default appName to InMemoryRunner to align with adk python. - // Check the dev UI in case we break something there. - this(agent, /* appName= */ agent.name(), ImmutableList.of()); + this(agent, DEFAULT_APP_NAME, ImmutableList.of()); } public InMemoryRunner(BaseAgent agent, String appName) { diff --git a/core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java b/core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java index 361c5eb6b..4039a15b6 100644 --- a/core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java +++ b/core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java @@ -87,7 +87,8 @@ public void agentRemembersUserNameWithMemoryTool() throws Exception { .build(); InMemoryRunner runner = new InMemoryRunner(agent); - String sessionId = runner.sessionService().createSession(agentName, userId).blockingGet().id(); + String sessionId = + runner.sessionService().createSession(runner.appName(), userId).blockingGet().id(); Content firstMessage = Content.fromParts(Part.fromText("My name is James")); @@ -101,7 +102,7 @@ public void agentRemembersUserNameWithMemoryTool() throws Exception { Session updatedSession = runner .sessionService() - .getSession("test_agent", userId, sessionId, Optional.empty()) + .getSession(runner.appName(), userId, sessionId, Optional.empty()) .blockingGet(); // Save the updated session to memory so we can bring it up on the next request. diff --git a/core/src/test/java/com/google/adk/runner/InMemoryRunnerTest.java b/core/src/test/java/com/google/adk/runner/InMemoryRunnerTest.java new file mode 100644 index 000000000..da9eb149b --- /dev/null +++ b/core/src/test/java/com/google/adk/runner/InMemoryRunnerTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.adk.runner; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.adk.agents.LlmAgent; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class InMemoryRunnerTest { + + @Test + public void defaultAppName_isInMemoryRunner() { + LlmAgent agent = LlmAgent.builder().name("my_agent").model("gemini-2.0-flash").build(); + InMemoryRunner runner = new InMemoryRunner(agent); + assertThat(runner.appName()).isEqualTo("InMemoryRunner"); + } + + @Test + public void explicitAppName_isPreserved() { + LlmAgent agent = LlmAgent.builder().name("my_agent").model("gemini-2.0-flash").build(); + InMemoryRunner runner = new InMemoryRunner(agent, "custom-app"); + assertThat(runner.appName()).isEqualTo("custom-app"); + } +}