@@ -14,23 +14,23 @@ To integrate this Firestore session service into your ADK project, add the follo
1414 <dependency >
1515 <groupId >com.google.adk</groupId >
1616 <artifactId >google-adk</artifactId >
17- <version >0.4.0-SNAPSHOT </version >
17+ <version >1.0.0 </version >
1818 </dependency >
1919 <!-- Firestore Session Service -->
2020 <dependency >
21- <groupId >com.google.adk.contrib </groupId >
22- <artifactId >firestore-session-service</artifactId >
23- <version >0.4.0-SNAPSHOT </version >
21+ <groupId >com.google.adk</groupId >
22+ <artifactId >google-adk- firestore-session-service</artifactId >
23+ <version >1.0.0 </version >
2424 </dependency >
2525</dependencies >
2626```
2727
2828``` gradle
2929dependencies {
3030 // ADK Core
31- implementation 'com.google.adk:google-adk:0.4.0-SNAPSHOT '
31+ implementation 'com.google.adk:google-adk:1.0.0 '
3232 // Firestore Session Service
33- implementation 'com.google.adk.contrib: firestore-session-service:0.4.0-SNAPSHOT '
33+ implementation 'com.google.adk:google-adk- firestore-session-service:1.0.0 '
3434}
3535```
3636
@@ -42,49 +42,110 @@ Sample Property Settings:
4242
4343``` properties
4444# Firestore collection name for storing session data
45- adk.firestore .collection.name =adk-session
45+ firebase.root .collection.name =adk-session
4646# Google Cloud Storage bucket name for artifact storage
47- adk. gcs.bucket.name =your-gcs-bucket-name
47+ gcs.adk .bucket.name =your-gcs-bucket-name
4848# 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
49+ keyword.extraction.stopwords =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
5050```
5151
5252Then, you can use the `FirestoreDatabaseRunner` to start your ADK application with Firestore session management:
5353
5454```java
55- import com.google.adk.agents.YourAgent; // Replace with your actual agent class
56- import com.google.adk.plugins.BasePlugin;
55+ import com.google.adk.agents.BaseAgent;
56+ import com.google.adk.agents.LlmAgent;
57+ import com.google.adk.agents.RunConfig;
5758import com.google.adk.runner.FirestoreDatabaseRunner;
5859import com.google.cloud.firestore.Firestore;
5960import 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;
61+ import io.reactivex.rxjava3.core.Flowable;
62+ import java.util.Map;
63+ import com.google.adk.sessions.FirestoreSessionService;
64+ import com.google.adk.sessions.Session;
65+ import com.google.adk.tools.Annotations.Schema;
66+ import com.google.adk.tools.FunctionTool;
67+ import com.google.genai.types.Content;
68+ import com.google.genai.types.Part;
69+ import com.google.adk.events.Event;
70+ import java.util.Scanner;
71+ import static java.nio.charset.StandardCharsets.UTF_8;
72+
73+ /***
74+ *
75+ */
76+ public class YourAgentApplication {
6477
78+ public static void main(String[] args) {
79+ System.out.println("Starting YourAgentApplication...");
6580
6681
82+ RunConfig runConfig = RunConfig.builder().build();
83+ String appName = "hello-time-agent";
6784
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
85+ BaseAgent timeAgent = initAgent();
86+ // Initialize Firestore
87+ FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance();
88+ Firestore firestore = firestoreOptions.getService();
7389
7490
75- FirestoreDatabaseRunner firestoreRunner = new FirestoreDatabaseRunner(
76- new YourAgent(), // Replace with your actual agent instance
77- "YourAppName" ,
78- plugins ,
79- firestore
91+ // Use FirestoreDatabaseRunner to persist session state
92+ FirestoreDatabaseRunner runner = new FirestoreDatabaseRunner(
93+ timeAgent ,
94+ appName ,
95+ firestore
8096 );
8197
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));
8598
99+
100+ Session session = new FirestoreSessionService(firestore)
101+ .createSession(appName,"user1234",null,"12345")
102+ .blockingGet();
103+
104+
105+ try (Scanner scanner = new Scanner(System.in, UTF_8)) {
106+ while (true) {
107+ System.out.print("\n You > ");
108+ String userInput = scanner.nextLine();
109+ if ("quit".equalsIgnoreCase(userInput)) {
110+ break;
111+ }
112+
113+ Content userMsg = Content.fromParts(Part.fromText(userInput));
114+ Flowable<Event> events = runner.runAsync(session.userId(), session.id(), userMsg, runConfig);
115+
116+ System.out.print("\n Agent > ");
117+ events.blockingForEach(event -> {
118+ if (event.finalResponse()) {
119+ System.out.println(event.stringifyContent());
120+ }
121+ });
122+ }
123+ }
124+
125+
126+ }
127+
128+ /** Mock tool implementation */
129+ @Schema(description = "Get the current time for a given city")
130+ public static Map<String, String> getCurrentTime(
131+ @Schema(name = "city", description = "Name of the city to get the time for") String city) {
132+ return Map.of(
133+ "city", city,
134+ "forecast", "The time is 10:30am."
135+ );
136+ }
137+ private static BaseAgent initAgent() {
138+ return LlmAgent.builder()
139+ .name("hello-time-agent")
140+ .description("Tells the current time in a specified city")
141+ .instruction("""
142+ You are a helpful assistant that tells the current time in a city.
143+ Use the ' getCurrentTime' tool for this purpose.
144+ """)
145+ .model("gemini-3.1-pro-preview")
146+ .tools(FunctionTool.create(YourAgentApplication.class, "getCurrentTime"))
147+ .build();
86148 }
149+
87150}
88151```
89-
90- Make sure to replace `YourAgent` and `"YourAppName"` with your actual agent class and application name.
0 commit comments