Repository navigation
Commit 2af7fae
feat(interactions): add automaticContinuation to Interactions.create in the Java SDK
Foreground `Interactions.create()` calls are capped per request by the server (32k output tokens unary, 64k streaming) and stop with `status="requires_continuation"` plus a `continuation_token`. `Interactions.create`, `AsyncInteractions.create`, `CreateInteractionRequest`, and `CreateInteractionRequestBuilder` now support `automaticContinuation` (default `true`) and chain continuation hops client-side so a plain `create()` returns the full decode.
Request chaining:
- Each hop after the first sends the `continuation_token` from the previous hop. With `store` enabled (default) it sets `previous_interaction_id` to the hop that issued the token and omits `input`; with `store=false` it resends the original `input`.
- Unary foreground model calls default `generation_config.max_output_tokens` to 65536 when unset without mutating caller request objects (streaming uses the server's 64k default). Explicit values are never overridden.
- Stops on `completed`, `incomplete` (token preserved for manual resumption), `requires_action`, `failed`, `cancelled`, a missing token, or a repeated token. Skipped for `CreateAgentInteraction` requests and `background=true`; `background=true` with `automaticContinuation=false` throws `IllegalArgumentException`.
Unary (`stream=false`) merging:
- Hops are merged into one `Interaction`: `steps` concatenated in hop order (leading `user_input` steps dropped on later hops), `usage` counts and per-modality breakdowns summed across hops with `usage.initialInputTokens` taken from hop 1, `id` / `status` / `continuationToken` / `updated` from the final hop, and `previousInteractionId` / `created` / `input` from hop 1.
- `continuationIds` lists every hop id in order, de-duplicated with any server-provided ids. Output convenience helpers (`outputText`, etc.) are recomputed across hop boundaries.
Streaming (`stream=true`):
- Events from all hops are yielded verbatim via `ContinuationEventStream` (sync and async). Consumers should treat `interaction.completed` with `status="requires_continuation"` as intermediate.
- Mid-hop transport drops (`IOException` / `UncheckedIOException`) or premature EOF resume from the latest `interaction.status_update` checkpoint token when no content was yielded since that checkpoint (up to 3 no-progress reconnects). SSE `error` events are terminal; HTTP status retries stay with `RetryConfig`.
Timeouts and errors:
- Per-call `timeout(Duration)` on `CreateInteractionRequest` / builders bounds the whole `create()` call across hops via `CallDeadline`, while client-level `HttpOptions.timeout` and `RetryConfig` apply per hop.
- A failure or timeout after progress throws `ContinuationInterruptedException` (`getCause()` chained) carrying `partialInteraction()`, `continuationToken()`, `interactionId()`, and `continuationIds()` so billed work is preserved for manual resumption. First-hop failures propagate unchanged.
Opt-out:
- `automaticContinuation=false` returns the single server response untouched (no budget injection, no merging) and logs a one-time `WARNING` if it stops at `requires_continuation` without a caller-supplied `continuation_token`.
Tests: `InteractionContinuationConformanceTest` (52 sync + 28 async streaming conformance cases) and `InteractionContinuationTest` (whole-call timeout, builder immutability, and warning tests).
PiperOrigin-RevId: 9956570951 parent 6e80d42 commit 2af7fae
6 files changed
Lines changed: 4031 additions & 97 deletions
File tree
- google/genai
- _gaos
- types/interactions
- tests/interactions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| |||
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
| 159 | + | |
157 | 160 | | |
158 | 161 | | |
159 | 162 | | |
| |||
220 | 223 | | |
221 | 224 | | |
222 | 225 | | |
| 226 | + | |
223 | 227 | | |
224 | 228 | | |
225 | 229 | | |
| |||
285 | 289 | | |
286 | 290 | | |
287 | 291 | | |
| 292 | + | |
288 | 293 | | |
289 | 294 | | |
290 | 295 | | |
| |||
335 | 340 | | |
336 | 341 | | |
337 | 342 | | |
| 343 | + | |
338 | 344 | | |
339 | 345 | | |
340 | 346 | | |
| |||
1317 | 1323 | | |
1318 | 1324 | | |
1319 | 1325 | | |
| 1326 | + | |
1320 | 1327 | | |
1321 | 1328 | | |
1322 | 1329 | | |
| |||
1356 | 1363 | | |
1357 | 1364 | | |
1358 | 1365 | | |
| 1366 | + | |
1359 | 1367 | | |
1360 | 1368 | | |
1361 | 1369 | | |
| |||
1423 | 1431 | | |
1424 | 1432 | | |
1425 | 1433 | | |
| 1434 | + | |
1426 | 1435 | | |
1427 | 1436 | | |
1428 | 1437 | | |
| |||
1489 | 1498 | | |
1490 | 1499 | | |
1491 | 1500 | | |
| 1501 | + | |
1492 | 1502 | | |
1493 | 1503 | | |
1494 | 1504 | | |
| |||
1554 | 1564 | | |
1555 | 1565 | | |
1556 | 1566 | | |
| 1567 | + | |
1557 | 1568 | | |
1558 | 1569 | | |
1559 | 1570 | | |
| |||
1604 | 1615 | | |
1605 | 1616 | | |
1606 | 1617 | | |
| 1618 | + | |
1607 | 1619 | | |
1608 | 1620 | | |
1609 | 1621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
170 | 175 | | |
171 | 176 | | |
172 | 177 | | |
| |||
263 | 268 | | |
264 | 269 | | |
265 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
266 | 277 | | |
267 | 278 | | |
268 | 279 | | |
| |||
380 | 391 | | |
381 | 392 | | |
382 | 393 | | |
| 394 | + | |
383 | 395 | | |
384 | 396 | | |
385 | 397 | | |
| |||
0 commit comments