Skip to content
Open
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 @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -221,7 +221,7 @@ public Flux<ChatResponse> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static List<Event> askAgent(BaseAgent agent, boolean streaming, Object...
ArrayList<Event> 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;
Expand Down Expand Up @@ -68,7 +69,7 @@ public static List<Event> 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<Event> events = new ArrayList<>();

Expand All @@ -93,7 +94,7 @@ public static List<Event> 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<Event> events = new ArrayList<>();

Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/com/google/adk/runner/InMemoryRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand All @@ -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.
Expand Down
42 changes: 42 additions & 0 deletions core/src/test/java/com/google/adk/runner/InMemoryRunnerTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}