Repository navigation
feat(interactions): add automatic_continuation to interactions.create in the TypeScript SDK - #137
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/995657093
branch
from
October 28, 2026 05:17
1b8e1a9 to
767a70f
Compare
… in the TypeScript 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`. `GeminiNextGenInteractions.create` now accepts `automatic_continuation` (default `true`) on `params` and chains 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 !== false` (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 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` / `agent_config` requests and `background: true`; `background: true` with `automatic_continuation: false` throws an error upfront. 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.initial_input_tokens` taken from hop 1, `id` / `status` / `continuation_token` / `updated` from the final hop, and `previous_interaction_id` / `created` / `input` from hop 1. - `continuation_ids` lists every hop id in order, de-duplicated with any server-provided ids. `output_text` skips intervening thought steps across hop boundaries. Streaming (`stream: true`): - Events from all hops are yielded verbatim on a pull-on-demand `Stream<InteractionSSEEvent>`. 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 `options.retries`. Timeouts and errors: - Numeric per-call `options.timeout_ms` (and alias `options.timeout`) bounds the whole `create()` call across hops via `CallDeadline`. Client-level `httpOptions.timeout`, `options.retries`, and `AbortSignal` apply per hop. - A failure or timeout after progress throws `ContinuationInterruptedError` (`cause` chained) carrying `partialInteraction` (unary), `continuationToken`, `interactionId`, and `continuationIds` so billed work is preserved for manual resumption. First-hop failures propagate unchanged. Opt-out: - `automatic_continuation: false` returns the single server response untouched (no budget injection, no merging) and emits a one-time `console.warn` if it stops at `requires_continuation` without a caller-supplied `continuation_token`. Tests: `test/unit/interactions_continuation_conformance_test.ts` (52 conformance cases) and `test/unit/interactions_continuation_test.ts` (whole-call timeout, wire hygiene, stream cancellation, and exports). PiperOrigin-RevId: 995657093
copybara-service
Bot
force-pushed
the
copybara/995657093
branch
from
October 28, 2026 05:27
767a70f to
e2b435d
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 automatic_continuation to interactions.create in the TypeScript 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.GeminiNextGenInteractions.createnow acceptsautomatic_continuation(defaulttrue) onparamsand chains continuation hops client-side so a plaincreate()returns the full decode.Request chaining:
continuation_tokenfrom the previous hop. Withstore !== false(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 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 foragent/agent_configrequests andbackground: true;background: truewithautomatic_continuation: falsethrows an error upfront.Unary (
stream: false) merging:Interaction:stepsconcatenated in hop order (leadinguser_inputsteps dropped on later hops),usagecounts and per-modality breakdowns summed across hops withusage.initial_input_tokenstaken from hop 1,id/status/continuation_token/updatedfrom the final hop, andprevious_interaction_id/created/inputfrom hop 1.continuation_idslists every hop id in order, de-duplicated with any server-provided ids.output_textskips intervening thought steps across hop boundaries.Streaming (
stream: true):Stream<InteractionSSEEvent>. 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 withoptions.retries.Timeouts and errors:
options.timeout_ms(and aliasoptions.timeout) bounds the wholecreate()call across hops viaCallDeadline. Client-levelhttpOptions.timeout,options.retries, andAbortSignalapply per hop.ContinuationInterruptedError(causechained) carryingpartialInteraction(unary),continuationToken,interactionId, andcontinuationIdsso billed work is preserved for manual resumption. First-hop failures propagate unchanged.Opt-out:
automatic_continuation: falsereturns the single server response untouched (no budget injection, no merging) and emits a one-timeconsole.warnif it stops atrequires_continuationwithout a caller-suppliedcontinuation_token.Tests:
test/unit/interactions_continuation_conformance_test.ts(52 conformance cases) andtest/unit/interactions_continuation_test.ts(whole-call timeout, wire hygiene, stream cancellation, and exports).