|
32 | 32 | import com.google.adk.plugins.PluginManager; |
33 | 33 | import com.google.adk.sessions.InMemorySessionService; |
34 | 34 | import com.google.adk.sessions.Session; |
| 35 | +import com.google.adk.summarizer.LlmEventSummarizer; |
35 | 36 | import com.google.adk.testing.TestLlm; |
36 | 37 | import com.google.adk.testing.TestUtils.EchoTool; |
37 | 38 | import com.google.common.collect.ImmutableList; |
@@ -208,6 +209,101 @@ public void runAsync_noEvents_empty() { |
208 | 209 | .isEmpty(); |
209 | 210 | } |
210 | 211 |
|
| 212 | + @Test |
| 213 | + public void runAsync_compactionAfterApproval_doesNotCallOriginalFunction() { |
| 214 | + LlmAgent agent = createAgentWithEchoTool(); |
| 215 | + // The summarizer's event is user-authored, so it ends the scan as in ADK Python. |
| 216 | + Event compactionEvent = |
| 217 | + new LlmEventSummarizer( |
| 218 | + createTestLlm(createLlmResponse(Content.fromParts(Part.fromText("summary"))))) |
| 219 | + .summarizeEvents(CONFIRMED_CALL_EVENTS) |
| 220 | + .blockingGet(); |
| 221 | + assertThat(compactionEvent).isNotNull(); |
| 222 | + assertThat(compactionEvent.author()).isEqualTo("user"); |
| 223 | + Session session = |
| 224 | + Session.builder("session_id") |
| 225 | + .events( |
| 226 | + ImmutableList.<Event>builder() |
| 227 | + .addAll(CONFIRMED_CALL_EVENTS) |
| 228 | + .add(compactionEvent) |
| 229 | + .build()) |
| 230 | + .build(); |
| 231 | + |
| 232 | + assertThat(resumedEvents(agent, session)).isEmpty(); |
| 233 | + } |
| 234 | + |
| 235 | + @Test |
| 236 | + public void runAsync_stateDeltaOnlyEventAfterApproval_doesNotCallOriginalFunction() { |
| 237 | + LlmAgent agent = createAgentWithEchoTool(); |
| 238 | + // A state-only user event, such as a resume without a message, ends the scan too. |
| 239 | + Event stateDeltaEvent = |
| 240 | + Event.builder() |
| 241 | + .author("user") |
| 242 | + .actions(EventActions.builder().stateDelta(ImmutableMap.of("resume_count", 1)).build()) |
| 243 | + .build(); |
| 244 | + Session session = |
| 245 | + Session.builder("session_id") |
| 246 | + .events( |
| 247 | + ImmutableList.<Event>builder() |
| 248 | + .addAll(CONFIRMED_CALL_EVENTS) |
| 249 | + .add(stateDeltaEvent) |
| 250 | + .build()) |
| 251 | + .build(); |
| 252 | + |
| 253 | + assertThat(resumedEvents(agent, session)).isEmpty(); |
| 254 | + } |
| 255 | + |
| 256 | + @Test |
| 257 | + public void runAsync_userTextTurnAfterApproval_doesNotCallOriginalFunction() { |
| 258 | + LlmAgent agent = createAgentWithEchoTool(); |
| 259 | + // The approved call never recorded a response; a later text turn must not re-run it. |
| 260 | + Event laterUserTextEvent = |
| 261 | + Event.builder() |
| 262 | + .author("user") |
| 263 | + .content(Content.fromParts(Part.fromText("unrelated follow-up question"))) |
| 264 | + .build(); |
| 265 | + Session session = |
| 266 | + Session.builder("session_id") |
| 267 | + .events( |
| 268 | + ImmutableList.<Event>builder() |
| 269 | + .addAll(CONFIRMED_CALL_EVENTS) |
| 270 | + .add(laterUserTextEvent) |
| 271 | + .build()) |
| 272 | + .build(); |
| 273 | + |
| 274 | + assertThat(resumedEvents(agent, session)).isEmpty(); |
| 275 | + } |
| 276 | + |
| 277 | + @Test |
| 278 | + public void runAsync_laterUserTurnAnswersOtherFunctionCall_doesNotCallOriginalFunction() { |
| 279 | + LlmAgent agent = createAgentWithEchoTool(); |
| 280 | + // The latest user event answers another function call, so the earlier approval stays unused. |
| 281 | + Event otherFunctionResponseEvent = |
| 282 | + Event.builder() |
| 283 | + .author("user") |
| 284 | + .content( |
| 285 | + Content.fromParts( |
| 286 | + Part.builder() |
| 287 | + .functionResponse( |
| 288 | + FunctionResponse.builder() |
| 289 | + .id("other_fc_id") |
| 290 | + .name("other_tool") |
| 291 | + .response(ImmutableMap.of("result", "done")) |
| 292 | + .build()) |
| 293 | + .build())) |
| 294 | + .build(); |
| 295 | + Session session = |
| 296 | + Session.builder("session_id") |
| 297 | + .events( |
| 298 | + ImmutableList.<Event>builder() |
| 299 | + .addAll(CONFIRMED_CALL_EVENTS) |
| 300 | + .add(otherFunctionResponseEvent) |
| 301 | + .build()) |
| 302 | + .build(); |
| 303 | + |
| 304 | + assertThat(resumedEvents(agent, session)).isEmpty(); |
| 305 | + } |
| 306 | + |
211 | 307 | @Test |
212 | 308 | public void runAsync_noUserConfirmationEvent_empty() { |
213 | 309 | LlmAgent agent = createAgentWithEchoTool(); |
|
0 commit comments