Repository navigation
feat(interactions): add automaticContinuation to Interactions.CreateAsync in the .NET SDK - #1360
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
…sync 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: 995657094
copybara-service
Bot
force-pushed
the
copybara_995657094
branch
from
October 28, 2026 05:16
641fb43 to
1470cc7
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withstatus="requires_continuation"plus acontinuation_token.IInteractions.CreateAsyncandInteractions.CreateAsyncnow acceptbool? automaticContinuation = null(defaulttrue) andTimeSpan? timeout = nulland chain continuation hops client-side so a plainCreateAsync()returns the full decode.Request chaining:
continuation_tokenfrom the previous hop. WithStoreenabled (default) it setsPreviousInteractionIdto the hop that issued the token and omitsInput; withStore = falseit resends the originalInput.GenerationConfig.MaxOutputTokensto 65536 when unset without mutating caller request objects (streaming uses the server's 64k default). Explicit values are never overridden.completed,incomplete(token preserved for manual resumption),requires_action,failed,cancelled, a missing token, or a repeated token. Skipped for agent requests andBackground = true;Background = truewithautomaticContinuation: falsethrowsArgumentException.Unary (
Stream = false) merging:Interaction:Stepsconcatenated in hop order (leadinguser_inputsteps dropped on later hops),Usagecounts and per-modality breakdowns summed across hops withUsage.InitialInputTokenstaken from hop 1,Id/Status/ContinuationToken/Updatedfrom the final hop, andPreviousInteractionId/Created/Inputfrom hop 1.ContinuationIdslists 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):EventStream<InteractionSseEvent>(await foreachandNext()). Consumers should treatinteraction.completedwithstatus="requires_continuation"as intermediate.interaction.status_updatecheckpoint token when no content was yielded since that checkpoint (up to 3 no-progress reconnects). SSEerrorevents are terminal; HTTP status retries stay withRetryConfig.Timeouts and errors:
TimeSpan? timeoutbounds the wholeCreateAsync()call across hops viaCallDeadline, whileHttpClient.Timeout,RetryConfig, andCancellationTokenapply per hop / immediate cancellation.ContinuationInterruptedException(InnerExceptionset to the underlying error, orContinuationTimeoutExceptionon deadline expiry) carryingPartialInteraction,ContinuationToken,InteractionId, andContinuationIdsso billed work is preserved for manual resumption. First-hop failures propagate unchanged.Opt-out:
automaticContinuation: falsereturns the single server response untouched (no budget injection, no merging) and emits a one-timeTrace.TraceWarningif it stops atrequires_continuationwithout a caller-suppliedcontinuation_token.Tests:
Google.GenAI.Tests/InteractionsContinuationConformanceTest.cs(52 conformance cases) andGoogle.GenAI.Tests/InteractionsContinuationTest.cs(whole-call timeout with fake clock, non-mutation, warning, andEventStream.Next()tests).