Add `framing_announcement` setting and only announce the `<system>` voice tag once a conversation needs it

Merged
DO
23d ago
+1068-470

On models without mid-conversation system messages (Gemini, Claude before 5.x and on Bedrock/Vertex, Grok, DeepSeek and most open models), every request with a system prompt or instructions has had a sentence added to its system prompt explaining the <system> tag, even for agents that never send anything mid-conversation.

This adds a framing_announcement model setting:

  • 'when_needed' (default): the sentence is added from the first request whose history has a <system> block, and on every request after it. It now goes ahead of the leading system prompts rather than after them, so the operator's own text keeps the last word (as in #11813, where Gemini acted more often on requests quoted in a tool result when the announcement came after the operator's prompt). That's a mid-conversation SystemPromptPart (enqueued, request-scoped, or from a stored history) or an instruction change appended by a dynamic instruction with on_change='append'. A change to an instruction with the default on_change='rewrite' rewrites the instructions at the start and adds nothing. Agents that never send one keep their system prompt as written; agents that do change their cached prompt prefix once, at that request. The condition is derived from the messages alone, so replays and later runs render identically.
  • 'always': the sentence on every request from the first, as in v2.63 (now ahead of the leading system prompts).
  • 'never': turns it off.

Escaping <system> in user prompt and tool return text is unchanged in all three modes.

Model.prepare_messages keeps its signature: the agent passes the setting on a private, unserialized ModelRequestParameters field, and a model's own settings apply when it's absent (direct prepare_messages calls, Temporal activities restore it from the request's settings).

[!WARNING]
Compatibility impact: On the models listed above, the system prompt of an agent that never sends anything mid-conversation no longer contains the <system> tag sentence, so its first request after upgrading misses an existing prompt cache once, and tests that snapshot the request see one fewer system block. Where the sentence is sent, it now comes before the leading system prompts instead of after them, which changes the cached prefix of an agent with a system_prompt once. An agent using on_change='append' instructions gets the sentence from the first appended change instead of the first request, which changes its cached prefix once at that point.

Why this can ship in a minor release: The sentence is framework-authored prompt text, not public API, and v2.63 added it recently; the default restores the prompt users wrote.

Migration: Set model_settings={'framing_announcement': 'always'} to send the sentence on every request, as before.

Checklist

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

🤖 Generated with Claude Code