2828import com .google .adk .models .LlmRequest ;
2929import com .google .adk .models .LlmResponse ;
3030import com .google .common .collect .ImmutableList ;
31+ import com .google .common .collect .ImmutableMap ;
3132import com .google .genai .types .Content ;
3233import com .google .genai .types .FunctionCall ;
3334import com .google .genai .types .FunctionResponse ;
3435import com .google .genai .types .Part ;
3536import io .reactivex .rxjava3 .core .Flowable ;
36- import java .util .HashMap ;
37+ import java .util .Map ;
3738import org .junit .Before ;
3839import org .junit .Rule ;
3940import org .junit .Test ;
@@ -74,7 +75,7 @@ public void setUp() {
7475 public void summarizeEvents_success () {
7576 ImmutableList <Event > events =
7677 ImmutableList .of (createEvent (1L , "Hello" , "user" ), createEvent (2L , "Hi there!" , "model" ));
77- String expectedConversationHistory = "user: Hello\\ nmodel: Hi there!" ;
78+ String expectedConversationHistory = "user: Hello\n model: Hi there!" ;
7879 String expectedPrompt =
7980 DEFAULT_PROMPT_TEMPLATE .replace ("{conversation_history}" , expectedConversationHistory );
8081 LlmResponse mockLlmResponse =
@@ -148,47 +149,25 @@ public void summarizeEvents_formatsEventsForPromptCorrectly() {
148149 .invocationId ("id2" )
149150 .build (),
150151 // Event with function call
151- Event .builder ()
152- .timestamp (7L )
153- .author ("model" )
154- .content (
155- Content .builder ()
156- .parts (
157- ImmutableList .of (
158- Part .builder ()
159- .functionCall (
160- FunctionCall .builder ()
161- .name ("tool" )
162- .args (new HashMap <>())
163- .build ())
164- .build ()))
165- .build ())
166- .invocationId ("id3" )
167- .build (),
152+ createFunctionCallEvent (7L , "id3" , "tool" , ImmutableMap .of ("key" , "value" )),
168153 // Event with function response
169- Event .builder ()
170- .timestamp (8L )
171- .author ("model" )
172- .content (
173- Content .builder ()
174- .parts (
175- ImmutableList .of (
176- Part .builder ()
177- .functionResponse (
178- FunctionResponse .builder ()
179- .name ("tool" )
180- .response (new HashMap <>())
181- .build ())
182- .build ()))
183- .build ())
184- .invocationId ("id4" )
185- .build ());
154+ createFunctionResponseEvent (8L , "id4" , "tool" , ImmutableMap .of ("status" , "ok" )),
155+ // Event with function call (add)
156+ createFunctionCallEvent (9L , "id5" , "add" , ImmutableMap .of ("a" , 20 , "b" , 22 )),
157+ // Event with primitive function response
158+ createFunctionResponseEvent (10L , "id6" , "add" , ImmutableMap .of ("result" , 42 )));
186159
187160 String expectedFormattedHistory =
188- "user: User says...\\ n"
189- + "model: Model replies...\\ n"
190- + "user: Another user input\\ n"
191- + "model: More model text" ;
161+ """
162+ user: User says...
163+ model: Model replies...
164+ user: Another user input
165+ model: More model text
166+ model: [FUNCTION_CALL: tool({"key":"value"})]
167+ model: [FUNCTION_RESPONSE: tool -> {"status":"ok"}]
168+ model: [FUNCTION_CALL: add({"a":20,"b":22})]
169+ model: [FUNCTION_RESPONSE: add -> {"result":42}]\
170+ """ ;
192171 String expectedPrompt =
193172 DEFAULT_PROMPT_TEMPLATE .replace ("{conversation_history}" , expectedFormattedHistory );
194173
@@ -215,4 +194,39 @@ private Event createEvent(long timestamp, String text, String author) {
215194 .invocationId (Event .generateEventId ())
216195 .build ();
217196 }
197+
198+ private Event createFunctionCallEvent (
199+ long timestamp , String invocationId , String name , Map <String , Object > args ) {
200+ return Event .builder ()
201+ .timestamp (timestamp )
202+ .author ("model" )
203+ .content (
204+ Content .builder ()
205+ .parts (
206+ ImmutableList .of (
207+ Part .builder ()
208+ .functionCall (FunctionCall .builder ().name (name ).args (args ).build ())
209+ .build ()))
210+ .build ())
211+ .invocationId (invocationId )
212+ .build ();
213+ }
214+
215+ private Event createFunctionResponseEvent (
216+ long timestamp , String invocationId , String name , Map <String , Object > response ) {
217+ return Event .builder ()
218+ .timestamp (timestamp )
219+ .author ("model" )
220+ .content (
221+ Content .builder ()
222+ .parts (
223+ ImmutableList .of (
224+ Part .builder ()
225+ .functionResponse (
226+ FunctionResponse .builder ().name (name ).response (response ).build ())
227+ .build ()))
228+ .build ())
229+ .invocationId (invocationId )
230+ .build ();
231+ }
218232}
0 commit comments