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
21 changes: 13 additions & 8 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<!--
Copyright 2025 Google LLC

Expand All @@ -16,19 +16,15 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.google.adk</groupId>
<artifactId>google-adk-parent</artifactId>
<version>0.4.1-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
<version>0.4.1-SNAPSHOT</version>
<!-- {x-version-update:google-adk:current} -->
</parent>

<artifactId>google-adk</artifactId>
<name>Agent Development Kit</name>
<description>Agent Development Kit: an open-source, code-first toolkit designed to simplify building, evaluating, and deploying advanced AI agents anywhere.</description>



<dependencies>
<dependency>
<groupId>com.anthropic</groupId>
Expand Down Expand Up @@ -201,6 +197,15 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<!--Plugin added by RoostGPT-->
</plugin>
</plugins>
<pluginManagement>
<plugins/>
</pluginManagement>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* 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.
*/
// ********RoostGPT********
/*
Test generated by RoostGPT for test unit-java-adk using AI Type Azure Open AI and AI Model gpt-5

ROOST_METHOD_HASH=addSessionToMemory_8a630adf5c
ROOST_METHOD_SIG_HASH=addSessionToMemory_3e3003d0a0

Scenario 1: Successfully stores a session with events that have non-empty parts

Details:
TestName: storesSessionWithEventsHavingNonEmptyParts
Description: Verifies that addSessionToMemory stores a session whose events include content with present, non-empty parts. Confirms that the returned Completable completes without errors and that the stored events are discoverable via searchMemory.

Execution:
Arrange: Create a Session with appName "appA", userId "user1", session id "s1", and events where at least one event has content().isPresent() and parts().isPresent() with a non-empty list containing a Part with non-empty text like "hello world".
Act: Invoke addSessionToMemory(session) and await the Completable to complete. Then call searchMemory("appA", "user1", "hello") to retrieve memories.
Assert: Assert the Completable completes successfully. Assert that searchMemory returns at least one MemoryEntry with content containing the word "hello".

Validation:
Confirms that events meeting the filter (content present, parts present and non-empty) are retained and can be retrieved through searchMemory. Ensures the Completable signals completion, indicating the write to memory occurred.

*/

// ********RoostGPT********

package com.google.adk.memory;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;

import com.google.adk.events.Event;
import com.google.adk.sessions.Session;
import com.google.common.collect.ImmutableList;
import com.google.genai.types.Part;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Single;
import java.time.Instant;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

public class InMemoryMemoryServiceAddSessionToMemoryTest {

private InMemoryMemoryService service;

@BeforeEach
public void setup() {
service = new InMemoryMemoryService();
}

@Test
@Tag("valid")
public void testStoresSessionWithEventsHavingNonEmptyParts() {
// Arrange
String appName = "appA"; // TODO: adjust appName if needed
String userId = "user1"; // TODO: adjust userId if needed
String sessionId = "s1"; // TODO: adjust session id if needed
// Create a Part with non-empty text "hello world"
Part partWithHello = Mockito.mock(Part.class);
Mockito.when(partWithHello.text()).thenReturn(Optional.of("hello world"));
// Content containing a non-empty list of parts
com.google.genai.types.Content contentWithPart =
Mockito.mock(com.google.genai.types.Content.class);
Mockito.when(contentWithPart.parts()).thenReturn(Optional.of(ImmutableList.of(partWithHello)));
// Event with content present and non-empty parts
Event eventWithContent = Mockito.mock(Event.class);
Mockito.when(eventWithContent.content()).thenReturn(Optional.of(contentWithPart));
Mockito.when(eventWithContent.author()).thenReturn("author");
Mockito.when(eventWithContent.timestamp()).thenReturn(Instant.now().getEpochSecond());
// Event with empty parts to ensure filtering works
com.google.genai.types.Content contentEmptyParts =
Mockito.mock(com.google.genai.types.Content.class);
Mockito.when(contentEmptyParts.parts()).thenReturn(Optional.of(ImmutableList.of()));
Event eventEmptyParts = Mockito.mock(Event.class);
Mockito.when(eventEmptyParts.content()).thenReturn(Optional.of(contentEmptyParts));
Mockito.when(eventEmptyParts.author()).thenReturn("author");
Mockito.when(eventEmptyParts.timestamp()).thenReturn(Instant.now().getEpochSecond());
// Event with no content to ensure filtering works
Event eventNoContent = Mockito.mock(Event.class);
Mockito.when(eventNoContent.content()).thenReturn(Optional.empty());
Mockito.when(eventNoContent.author()).thenReturn("author");
Mockito.when(eventNoContent.timestamp()).thenReturn(Instant.now().getEpochSecond());
// Session with a mix of events
Session session = Mockito.mock(Session.class);
Mockito.when(session.appName()).thenReturn(appName);
Mockito.when(session.userId()).thenReturn(userId);
Mockito.when(session.id()).thenReturn(sessionId);
Mockito.when(session.events())
.thenReturn(ImmutableList.of(eventWithContent, eventEmptyParts, eventNoContent));
// Act
Completable completable = service.addSessionToMemory(session);
// Assert - Completable completes successfully
assertDoesNotThrow(() -> completable.blockingAwait());
// And the stored events are discoverable via searchMemory
Single<SearchMemoryResponse> responseSingle = service.searchMemory(appName, userId, "hello");
SearchMemoryResponse response = responseSingle.blockingGet();
// Assert at least one MemoryEntry with content containing the word "hello"
List<MemoryEntry> memories = response.memories();
boolean foundHello = false;
for (MemoryEntry memory : memories) {
Optional<List<Part>> maybeParts = memory.content().parts();
if (maybeParts.isPresent()) {
for (Part p : maybeParts.get()) {
Optional<String> text = p.text();
if (text.isPresent() && text.get().toLowerCase(Locale.ROOT).contains("hello")) {
foundHello = true;
break;
}
}
}
if (foundHello) {
break;
}
}
assertFalse(
(boolean) Boolean.valueOf(!foundHello),
"Expected to find at least one memory containing the word 'hello'");
}

@Test
@Tag("invalid")
public void testIgnoresEventsWithEmptyOrMissingParts() {
// Arrange
String appName = "appB"; // TODO: adjust appName if needed
String userId = "user2"; // TODO: adjust userId if needed
String sessionId = "s2"; // TODO: adjust session id if needed
// Event with empty parts
com.google.genai.types.Content contentEmptyParts =
Mockito.mock(com.google.genai.types.Content.class);
Mockito.when(contentEmptyParts.parts()).thenReturn(Optional.of(ImmutableList.of()));
Event eventEmptyParts = Mockito.mock(Event.class);
Mockito.when(eventEmptyParts.content()).thenReturn(Optional.of(contentEmptyParts));
Mockito.when(eventEmptyParts.author()).thenReturn("author");
Mockito.when(eventEmptyParts.timestamp()).thenReturn(Instant.now().getEpochSecond());
// Event with no content
Event eventNoContent = Mockito.mock(Event.class);
Mockito.when(eventNoContent.content()).thenReturn(Optional.empty());
Mockito.when(eventNoContent.author()).thenReturn("author");
Mockito.when(eventNoContent.timestamp()).thenReturn(Instant.now().getEpochSecond());
// Session containing only events that should be filtered out
Session session = Mockito.mock(Session.class);
Mockito.when(session.appName()).thenReturn(appName);
Mockito.when(session.userId()).thenReturn(userId);
Mockito.when(session.id()).thenReturn(sessionId);
Mockito.when(session.events()).thenReturn(ImmutableList.of(eventEmptyParts, eventNoContent));
// Act
Completable completable = service.addSessionToMemory(session);
// Assert - Completable completes successfully
assertDoesNotThrow(() -> completable.blockingAwait());
// Then search should not return any memories for any queried word
SearchMemoryResponse r1 = service.searchMemory(appName, userId, "anything").blockingGet();
List<MemoryEntry> memories1 = r1.memories();
assertFalse(
(boolean) Boolean.valueOf(!memories1.isEmpty()),
"Expected no memories to be returned for sessions with only empty/missing parts");
}
}
79 changes: 63 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<!-- Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,20 +12,16 @@
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. -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.google.adk</groupId>
<artifactId>google-adk-parent</artifactId>
<version>0.4.1-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
<version>0.4.1-SNAPSHOT</version>
<!-- {x-version-update:google-adk:current} -->
<packaging>pom</packaging>

<name>Google Agent Development Kit Maven Parent POM</name>
<url>https://github.com/google/adk-java</url>
<description>Google Agent Development Kit (ADK) for Java</description>

<modules>
<module>core</module>
<module>dev</module>
Expand All @@ -39,12 +35,10 @@
<module>a2a</module>
<module>a2a/webservice</module>
</modules>

<properties>
<java.version>17</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<auto-value.version>1.11.0</auto-value.version>
<spring-boot.version>3.4.1</spring-boot.version>
<otel.version>1.49.0</otel.version>
Expand Down Expand Up @@ -73,7 +67,6 @@
<maven-plugin-tools.version>3.9.0</maven-plugin-tools.version>
<httpclient5.version>5.4.3</httpclient5.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- BOMs for dependency management -->
Expand Down Expand Up @@ -112,7 +105,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- Direct dependencies -->
<dependency>
<groupId>com.anthropic</groupId>
Expand Down Expand Up @@ -274,9 +266,21 @@
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.4</version>
<scope>test</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter</artifactId>
<version>0.0.40</version>
<!--Dependency added by RoostGPT-->
</dependency>
</dependencies>
</dependencyManagement>

<build>
<extensions>
<extension>
Expand Down Expand Up @@ -324,8 +328,7 @@
</dependencies>
<configuration>
<reportFormat>plain</reportFormat>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter" />
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter"/>
<includes>
<include>**/*Test.java</include>
</includes>
Expand Down Expand Up @@ -469,6 +472,36 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<outputDirectory>testReport</outputDirectory>
</configuration>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.1</version>
<configuration>
<outputDirectory>testReport</outputDirectory>
</configuration>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<!--Plugin added by RoostGPT-->
</plugin>
</plugins>
</build>
<profiles>
Expand Down Expand Up @@ -528,7 +561,6 @@
</build>
</profile>
</profiles>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
Expand Down Expand Up @@ -558,4 +590,19 @@
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.4</version>
<scope>test</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter</artifactId>
<version>0.0.40</version>
<!--Dependency added by RoostGPT-->
</dependency>
</dependencies>
</project>