feat: preserve prompt cache across effort switches - #48513
Open
nexxeln wants to merge 2 commits into
Open
Conversation
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.
Issue for this PR
Closes #
Type of change
What does this PR do?
Switching a model variant (effort) mid-session currently changes the top-level
output_config.effort/reasoning.effort, which providers render into the prompt, so the whole prompt cache (tools, system and messages) is invalidated on every switch. Anthropic (Opus 5, Fable/Mythos 5.1) and OpenAI (gpt-6-astra) both expose a per-message alternative that keeps the prefix intact.model-switchedhistory entry toMessage.effort({ effort, previous })instead of dropping it (to-llm-message.ts).applyEffortUpdatesruns inprepareRequestnext toapplyCachePolicyand strips the markers unless the route's protocol declaressupportsEffortUpdates, so every other route behaves exactly as today.output_config.effortat the first marker'sprevious, lowers each marker to{ role: "system", content: [], output_config: { effort } }, and adds themid-conversation-output-config-2026-07-01beta. OpenAI Responses does the same withconfiguration_updateitems (coalescing consecutive ones, off whencontextManagementis set).Gates: Anthropic Opus ≥ 5 / Fable, Mythos ≥ 5.1 and OpenAI
gpt-6-astra, with acompatibility.supportsEffortUpdatesoverride. Anthropic applies the change from the next user turn; OpenAI from the next response. Zen stripsanthropic-betatoday, so the Opus 5 marker 400s through it until Zen forwards the header — that needs to land first or Zen should advertisesupportsEffortUpdates: falsefor Claude models. Vertex Anthropic is deliberately not forwarded (beta acceptance unverified).How did you verify your code works?
Live against the APIs before implementing (Opus 5, Opus 4.8, Sonnet 4.6/5, gpt-5.5, gpt-6-astra incl. the ChatGPT/Codex backend, Gemini 3.5 Flash): top-level effort changes read 0 cached tokens; markers /
configuration_updateread the full prior prefix across multiple switches; unsupported models return the documented 400s. Thenbun typecheckin ai/core/server/sdk, the fullpackages/aisuite, and the core runner tests (new:effort-updates.test.ts,to-llm-messagecases, a runner scenario asserting the compiled Anthropic body after a switch).Screenshots / recordings
n/a
Checklist