Repository navigation
Commit 1470cc7
feat(interactions): add automaticContinuation to Interactions.CreateAsync in the .NET SDK
Foreground `Interactions.CreateAsync()` calls are capped per request by the server (32k output tokens unary, 64k streaming) and stop with `status="requires_continuation"` plus a `continuation_token`. `IInteractions.CreateAsync` and `Interactions.CreateAsync` now accept `bool? automaticContinuation = null` (default `true`) and `TimeSpan? timeout = null` and chain continuation hops client-side so a plain `CreateAsync()` 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 `PreviousInteractionId` to the hop that issued the token and omits `Input`; with `Store = false` it resends the original `Input`.
- Unary foreground model calls default `GenerationConfig.MaxOutputTokens` 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 agent requests and `Background = true`; `Background = true` with `automaticContinuation: false` throws `ArgumentException`.
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. Convenience output properties (`OutputText`, etc.) are recomputed across hop boundaries.
Streaming (`Stream = true`):
- Events from all hops are yielded verbatim on `EventStream<InteractionSseEvent>` (`await foreach` and `Next()`). Consumers should treat `interaction.completed` with `status="requires_continuation"` as intermediate.
- Mid-hop transport drops 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 `TimeSpan? timeout` bounds the whole `CreateAsync()` call across hops via `CallDeadline`, while `HttpClient.Timeout`, `RetryConfig`, and `CancellationToken` apply per hop / immediate cancellation.
- A failure or timeout after progress throws `ContinuationInterruptedException` (`InnerException` set to the underlying error, or `ContinuationTimeoutException` on deadline expiry) 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 emits a one-time `Trace.TraceWarning` if it stops at `requires_continuation` without a caller-supplied `continuation_token`.
Tests: `Google.GenAI.Tests/InteractionsContinuationConformanceTest.cs` (52 conformance cases) and `Google.GenAI.Tests/InteractionsContinuationTest.cs` (whole-call timeout with fake clock, non-mutation, warning, and `EventStream.Next()` tests).
PiperOrigin-RevId: 9956570941 parent cb44af3 commit 1470cc7
12 files changed
Lines changed: 2531 additions & 70 deletions
File tree
- src
- main/java/com/google/genai/gaos
- models
- errors
- interactions
- operations
- async
- utils
- test/java/com/google/genai/gaos
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | | - | |
41 | 39 | | |
42 | 40 | | |
43 | 41 | | |
| |||
91 | 89 | | |
92 | 90 | | |
93 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
94 | 106 | | |
95 | 107 | | |
96 | 108 | | |
| |||
103 | 115 | | |
104 | 116 | | |
105 | 117 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
119 | 154 | | |
120 | 155 | | |
121 | 156 | | |
| |||
0 commit comments