Repository navigation
feat(interactions): add automaticContinuation to Interactions.create in the Java SDK - #138
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
copybara-service
Bot
force-pushed
the
copybara/995657095
branch
from
October 28, 2026 05:16
1a25aaf to
52a217c
Compare
…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: 995657095
copybara-service
Bot
force-pushed
the
copybara/995657095
branch
from
October 28, 2026 05:44
52a217c to
70561f1
Compare
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.create in the Java SDK
Foreground
Interactions.create()calls are capped per request by the server (32k output tokens unary, 64k streaming) and stop withstatus="requires_continuation"plus acontinuation_token.Interactions.create,AsyncInteractions.create,CreateInteractionRequest, andCreateInteractionRequestBuildernow supportautomaticContinuation(defaulttrue) and chain continuation hops client-side so a plaincreate()returns the full decode.Request chaining:
continuation_tokenfrom the previous hop. Withstoreenabled (default) it setsprevious_interaction_idto the hop that issued the token and omitsinput; withstore=falseit resends the originalinput.generation_config.max_output_tokensto 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 forCreateAgentInteractionrequests andbackground=true;background=truewithautomaticContinuation=falsethrowsIllegalArgumentException.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. Output convenience helpers (outputText, etc.) are recomputed across hop boundaries.Streaming (
stream=true):ContinuationEventStream(sync and async). Consumers should treatinteraction.completedwithstatus="requires_continuation"as intermediate.IOException/UncheckedIOException) or premature EOF resume from the latestinteraction.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:
timeout(Duration)onCreateInteractionRequest/ builders bounds the wholecreate()call across hops viaCallDeadline, while client-levelHttpOptions.timeoutandRetryConfigapply per hop.ContinuationInterruptedException(getCause()chained) carryingpartialInteraction(),continuationToken(),interactionId(), andcontinuationIds()so 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 logs a one-timeWARNINGif it stops atrequires_continuationwithout a caller-suppliedcontinuation_token.Tests:
InteractionContinuationConformanceTest(52 sync + 28 async streaming conformance cases) andInteractionContinuationTest(whole-call timeout, builder immutability, and warning tests).