Skip to content

Commit 27a44a9

Browse files
Merge pull request #601 from mohan-ganesh:feat/firestore-session-service
PiperOrigin-RevId: 836776506
2 parents 154a7d6 + b75608f commit 27a44a9

File tree

21 files changed

+3298
-10
lines changed

21 files changed

+3298
-10
lines changed

a2a/webservice/pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

77
<parent>
88
<groupId>com.google.adk</groupId>
99
<artifactId>google-adk-parent</artifactId>
1010
<version>0.4.0-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
11+
<relativePath>../../pom.xml</relativePath>
1112
</parent>
1213

1314
<artifactId>google-adk-a2a-webservice</artifactId>
@@ -63,4 +64,4 @@
6364
</plugin>
6465
</plugins>
6566
</build>
66-
</project>
67+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/target
2+
*.prefs
3+
*.iml
4+
.idea/
5+
.vscode/
6+
.DS_Store
7+
logs/
8+
*.log
9+
*.project
10+
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## Firestore Session Service for ADK
2+
3+
This sub-module contains an implementation of a session service for the ADK (Agent Development Kit) that uses Google Firestore as the backend for storing session data. This allows developers to manage user sessions in a scalable and reliable manner using Firestore's NoSQL database capabilities.
4+
5+
## Getting Started
6+
7+
To integrate this Firestore session service into your ADK project, add the following dependencies to your project's build configuration: pom.xml for Maven or build.gradle for Gradle.
8+
9+
## Basic Setup
10+
11+
```xml
12+
<dependencies>
13+
<!-- ADK Core -->
14+
<dependency>
15+
<groupId>com.google.adk</groupId>
16+
<artifactId>google-adk</artifactId>
17+
<version>0.4.0-SNAPSHOT</version>
18+
</dependency>
19+
<!-- Firestore Session Service -->
20+
<dependency>
21+
<groupId>com.google.adk.contrib</groupId>
22+
<artifactId>firestore-session-service</artifactId>
23+
<version>0.4.0-SNAPSHOT</version>
24+
</dependency>
25+
</dependencies>
26+
```
27+
28+
```gradle
29+
dependencies {
30+
// ADK Core
31+
implementation 'com.google.adk:google-adk:0.4.0-SNAPSHOT'
32+
// Firestore Session Service
33+
implementation 'com.google.adk.contrib:firestore-session-service:0.4.0-SNAPSHOT'
34+
}
35+
```
36+
37+
## Running the Service
38+
39+
You can customize your ADK application to use the Firestore session service by providing your own Firestore property settings, otherwise library will use the default settings.
40+
41+
Sample Property Settings:
42+
43+
```properties
44+
# Firestore collection name for storing session data
45+
adk.firestore.collection.name=adk-session
46+
# Google Cloud Storage bucket name for artifact storage
47+
adk.gcs.bucket.name=your-gcs-bucket-name
48+
#stop words for keyword extraction
49+
adk.stop.words=a,about,above,after,again,against,all,am,an,and,any,are,aren't,as,at,be,because,been,before,being,below,between,both,but,by,can't,cannot,could,couldn't,did,didn't,do,does,doesn't,doing,don't,down,during,each,few,for,from,further,had,hadn't,has,hasn't,have,haven't,having,he,he'd,he'll,he's,her,here,here's,hers,herself,him,himself,his,how,i,i'd,i'll,i'm,i've,if,in,into,is
50+
```
51+
52+
Then, you can use the `FirestoreDatabaseRunner` to start your ADK application with Firestore session management:
53+
54+
```java
55+
import com.google.adk.agents.YourAgent; // Replace with your actual agent class
56+
import com.google.adk.plugins.BasePlugin;
57+
import com.google.adk.runner.FirestoreDatabaseRunner;
58+
import com.google.cloud.firestore.Firestore;
59+
import com.google.cloud.firestore.FirestoreOptions;
60+
import java.util.ArrayList;
61+
import java.util.List;
62+
import com.google.adk.sessions.GetSessionConfig;
63+
import java.util.Optional;
64+
65+
66+
67+
68+
public class YourApp {
69+
public static void main(String[] args) {
70+
Firestore firestore = FirestoreOptions.getDefaultInstance().getService();
71+
List<BasePlugin> plugins = new ArrayList<>();
72+
// Add any plugins you want to use
73+
74+
75+
FirestoreDatabaseRunner firestoreRunner = new FirestoreDatabaseRunner(
76+
new YourAgent(), // Replace with your actual agent instance
77+
"YourAppName",
78+
plugins,
79+
firestore
80+
);
81+
82+
GetSessionConfig config = GetSessionConfig.builder().build();
83+
// Example usage of session service
84+
firestoreRunner.sessionService().getSession("APP_NAME","USER_ID","SESSION_ID", Optional.of(config));
85+
86+
}
87+
}
88+
```
89+
90+
Make sure to replace `YourAgent` and `"YourAppName"` with your actual agent class and application name.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2025 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<parent>
23+
<groupId>com.google.adk</groupId>
24+
<artifactId>google-adk-parent</artifactId>
25+
<version>0.4.0-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
26+
<relativePath>../../pom.xml</relativePath>
27+
</parent>
28+
29+
<artifactId>google-adk-firestore-session-service</artifactId>
30+
<name>Agent Development Kit - Firestore Session Management</name>
31+
<description>Firestore integration with Agent Development Kit for User Session Management</description>
32+
33+
34+
<dependencies>
35+
36+
<dependency>
37+
<groupId>com.google.adk</groupId>
38+
<artifactId>google-adk</artifactId>
39+
<version>${project.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.google.adk</groupId>
43+
<artifactId>google-adk-dev</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.google.genai</groupId>
48+
<artifactId>google-genai</artifactId>
49+
<version>${google.genai.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.google.cloud</groupId>
53+
<artifactId>google-cloud-firestore</artifactId>
54+
<version>3.30.3</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>com.google.truth</groupId>
58+
<artifactId>truth</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.mockito</groupId>
63+
<artifactId>mockito-core</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.junit.jupiter</groupId>
69+
<artifactId>junit-jupiter-api</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter-engine</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.mockito</groupId>
79+
<artifactId>mockito-junit-jupiter</artifactId>
80+
<scope>test</scope>
81+
</dependency>
82+
83+
</dependencies>
84+
85+
<build>
86+
<plugins>
87+
<plugin>
88+
<groupId>org.jacoco</groupId>
89+
<artifactId>jacoco-maven-plugin</artifactId>
90+
</plugin>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-surefire-plugin</artifactId>
94+
<configuration>
95+
<argLine>
96+
${jacoco.agent.argLine}
97+
--add-opens java.base/java.util=ALL-UNNAMED
98+
--add-opens java.base/java.lang=ALL-UNNAMED
99+
</argLine>
100+
</configuration>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
</project>

0 commit comments

Comments
 (0)