Change thinking effort mid-conversation via OpenAI `configuration_update` and Anthropic per-message `output_config`, recorded as `ModelSettingsDeltaPart`

Merged
DO
1mo ago
+4897-88

Changing the unified thinking effort between runs or steps used to change the request-level effort, which is part of the provider's prompt cache key. On OpenAI that throws the cached prefix away. Now the framework records each change in history as a ModelSettingsDeltaPart: the changed settings by their unified ModelSettings keys (for example {'thinking': 'high'}), plus whether the request sent them at request level, which opens a window. Each model adapter decides which keys it can deliver mid-conversation and keeps sending the window's opening values at request level; every other key goes out at request level as before. Today effort is the only such key:

  • OpenAI Responses (GPT-6 family): a configuration_update input item.
  • Anthropic (Fable 5.1, Mythos 5.1, Opus 5.5, Opus 5, Sonnet 5.5, Haiku 5.5 on the Claude API and Google Cloud; Fable 5.1 and Opus 5.5 on the legacy Bedrock InvokeModel client): an effort-only {'role': 'system', 'content': [], 'output_config': {...}} entry, under the mid-conversation-output-config-2026-07-01 beta.

Adding a setting a provider can change mid-conversation later (verbosity, say) is an adapter change, not a new part.

[!WARNING]
Compatibility impact. ModelRequestPart gains ModelSettingsDeltaPart, and HandleResponseEvent (and with it AgentStreamEvent) gains ModelSettingsDeltaEvent:

  • all_messages() gains a ModelSettingsDeltaPart at the end of the first request that sets thinking to an effort level ('low', 'high', ...), and on each request where that level changes. Nothing is recorded while thinking is unset or a bool.
  • The event stream gains a ModelSettingsDeltaEvent for each recorded part, and the Vercel AI and AG-UI adapters dump and stream it as a data-model-settings-delta data part and a pydantic_ai_model_settings_delta activity.
  • On the models above, a request after an effort change keeps the request-level effort the conversation started with and sends the change in place, so its bytes differ from before.

This relies on the version policy's allowance for adding new message parts. Migration: update snapshot tests of messages or events for agents that set an effort level; handle the new ModelRequestPart and event members in code that matches the unions exhaustively (custom serializers or renderers using assert_never), skipping ModelSettingsDeltaPart or rendering it through Model.prepare_messages. The API compatibility check is waived for the two union changes in .github/api-compatibility-allowlist.json.

Everything else sends the change at request level, as before. That covers other APIs and models, an explicit openai_reasoning_effort / anthropic_effort (the request then records no unified level), OpenAI truncation or server compaction, non-adaptive Anthropic thinking (between_tools on Sonnet 5.5 and disabled on Haiku 5.5 return a 400 for a differing per-message effort), and changes to or from True/False.

Measured (live, 2026-10-23)

Cache read on the second request after an effort change, with a fresh prefix per scenario:

ModelNo changeRequest-level changeNative marker
gpt-6.1-sol8,591 / 8,6290 / 8,6308,593 / 8,631
claude-opus-5-512,425 (full)12,425 (full)12,419 (full)

The recorded cassettes here show the same: 8,025 of 8,058 cached on OpenAI and 10,831 read on Anthropic. A request-level change didn't cost Anthropic any cache reads in our probes, contrary to its docs. Its docs prefer the marker anyway, for the cache and because a request-level change steers Fable 5.1 less reliably.

Design

  • History: ModelSettingsDeltaPart(settings, top_level) goes at the end of the request it applies to. settings is a RecordedModelSettings: the JSON-native subset of ModelSettings keys that shape what the model produces, never transport settings such as extra_headers, timeout or extra_body. The framework records only thinking today, as an effort level or None for a request that names none.
    • The first request that names an effort level records one with top_level=True, as does any change that no marker can express (to or from True/False) and the first request after a compaction.
    • A change between two levels is recorded with top_level=False.
    • A part on the current request that no response has answered yet is replaced rather than followed by a second one, since OpenAI rejects two adjacent updates.
  • Projection:
    • Model.prepare_messages keeps the parts from the last top_level=True part onward on models whose adapter renders them (supports_mid_conversation_effort profile flag, set per provider and narrowed per Anthropic client). A change from before that point would override the request-level value on both providers; live probes showed an earlier marker wins over a later request-level change.
    • Parts with no response between them collapse into the last one.
    • Every other model drops the parts.
  • Fallback and direct calls: the effort recorded is the one the serving model sends, with its own settings merged in; a FallbackModel records one only when every candidate would send the same, and otherwise opens a request-level window that claims no effort. direct.model_request drops recorded deltas (it sends its own model_settings) and prepares any history holding a part an adapter can't send.
  • UI: the parts ride through Vercel AI and AG-UI, both when dumped and when streamed as ModelSettingsDeltaEvent. That's like ToolAvailabilityDeltaPart: dropping them on a round trip would move the prefix. Loaded settings are validated against RecordedModelSettings, with unknown keys dropped; a forged change is superseded by the change the next request records.

Limitation

Anthropic applies a per-message change from the next user turn with new input. A change on a step that only returns tool results waits for the next user prompt (probed: no effect on that step). Changing effort per step inside one run (#9009) is therefore out of scope here on Anthropic; it works on OpenAI Responses, where the item takes effect after a function_call_output. The docs say so.

Tests

  • Cassettes (live-recorded on gpt-6.1-sol and claude-opus-5-5): the second run reads the first run's prefix from cache.
  • Mocked request bodies for each rendering and each fallback, the per-client profile gate, recording and projection rules, previous_response_id='auto' continuation, and UI dump/load and client-rebuilt-stream round trips.
  • A new append-only checker case (agent:effort_change) that changes effort at a tool-result step and between runs. It keeps the prefix on Anthropic and OpenAI Responses and is an allowed request-level move on Chat Completions. The checker now also counts Anthropic's output_config as part of the cache key.
  • SDK minimums bumped to openai>=3.31.0 and anthropic>=1.15.0 for the new types. The lock diff touches only those two packages.

Follow-ups (not in this PR)

  • Have WarnOnCacheBusts attribute a request-level cache bust to the effort change that caused it, on APIs without a mid-conversation channel (Gemini, Chat Completions).
  • Render OpenRouter's mid-conversation effort forms.
  • Add a settings-delta scenario to the real-reducer UI round-trip harness (tests/ui_roundtrip, #10560) once it lands; the client-rebuilt tests here use the Python reducer stand-ins.

Release note: "Changing the thinking effort level mid-conversation keeps the prompt cache on OpenAI Responses (GPT-6) and Anthropic: the change is recorded as a new ModelSettingsDeltaPart and sent as a configuration_update item or per-message output_config, so histories that set an effort level gain one part on their first request."

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code