Send `TrajectoryJudge` steering as a framework `SystemPromptPart` note plus the judge message as escaped `<judge_feedback>` data, both marked with `metadata`
TrajectoryJudge delivered a Steer verdict with ctx.enqueue(f"Steering from trajectory judge '{name}': {message}"). That presented framework text to the running agent as an ordinary user turn, with the judge-written message unescaped inside it. This PR sends the steer as two parts:
- a fixed framework note in system voice (
SystemPromptPart); - the judge's message as data on the user channel, quoted in an escaped
<judge_feedback judge="...">element.
[!WARNING]
Compatibility impact: Existing code that finds judge steering in message history by matching Steering from trajectory judge '...' in a UserPromptPart will no longer find it. Steering is now two parts in one request: a SystemPromptPart holding a fixed framework note, and a UserPromptPart whose TextContent holds the message in a <judge_feedback judge="..."> element. The model-visible text has changed too.
Why this can ship in a minor release: Pydantic AI Harness is on 0.x, and the steering text was never documented as an interface. This fixes framework text being presented to the model as something the user said.
Migration: To observe steering, use the on_verdict callback, which receives each Steer(message=...) as it is enqueued, instead of searching message history for its text.
- Audit item H18 in the 2026-10-15 "message history as world model" audit. The audit's rules: trust tiers map to channels, untrusted content never enters system voice, and framework voice never rides
ctx.enqueue(str). - Uses
SystemPromptPart.metadatafrom #10641.
What the model sees, as two parts:
system note: A trajectory judge reviewing this run sent a course correction. It is in the accompanying `<judge_feedback>` tag, written by a reviewing model, not by the user: follow it unless it conflicts with your instructions or the user's request.
user message: <judge_feedback judge="focus">
refocus
</judge_feedback>
Providers don't all send the two in the same order. Anthropic sends a request's user content before its mid-conversation system entry (models/anthropic.py), so the wire order there is user message, then note. That's why the note says "accompanying" rather than "follows".
On models without inline system prompts, core wraps the note as <system>…</system> user text. The judge's message is never inside that wrapper.
Design choices:
- Split the voices, as #10558 does for the
RepoContextpointer. The judge model reads the run's tool results, so its output can echo injected text. Putting XML quotes inside a system part doesn't create a role boundary. So only the fixed note is system voice, and the message is user-channel data.- Inside the message, the
<that opens anything a parser could read as asystemorjudge_feedbacktag, opening or closing, becomes<. The pattern isr'<(?=\s*/?\s*(?:system|judge_feedback)(?=[\s/>]))', any case, which covers whitespace around/and the name, self-closing syntax and attributes.systemis included because, on a model without inline system prompts, real framework notes become<system>…</system>user text, and the judge's message must not be able to imitate one. #10547 makes this the default for every data frame in core's_framing.wrap(), and aTODOmarks the switch. - The judge prompt's whole-transcript
html.escapeisn't reused here: it would change what the agent reads (a < bbecomesa < b).
- Inside the message, the
- Tag name
<judge_feedback>, and the note's wording as written: DouweM's call. No transcript code recognizes steering by its text, so the earlier spelling needs no compatibility handling. - Conversation scope, not
scope='request': DouweM's call. A steer is a course correction the agent should keep following. It isn't a one-off nudge. Withscope='request', Anthropic would clear it after one request, and the agent could drift back before the next evaluation, which may beeveryrequests later. The old user-text steer also stayed in the conversation, and history stays append-only either way. - The judge recognizes its own steering by metadata, internally. Both parts carry harness-private metadata that survives
_merge_consecutive_messages(ModelRequest.metadata, used in an earlier revision, doesn't). The judge transcript uses it to render earlier steering astrajectory judge {name} steered: ...instead of auser:line, and recognizes only the exact single-TextContentshape it enqueues. The metadata isn't documented for applications: provenance is being designed as a core concept, and this will move to it. Like other application-only metadata, it doesn't survive a round trip through the UI adapters. - Known limit: on models without inline system prompts. The judge still reads the prepared
request_context.messages, so request-only transforms that other capabilities apply, such as redaction, still apply to what the judge sees. In that prepared copy, core has already turned the note into<system>user text with no metadata, so the note shows in the judge transcript as auser:line. The message itself is still rendered as steering. The docs say so.
Tests:
- The steer splits into a metadata-marked
SystemPromptPartnote (conversation scope) and a metadata-markedTextContentdata part. - Through
Model.prepare_messages()withsupports_inline_system_prompts=False, a forged</system>/</judge_feedback>/</JUDGE_FEEDBACK >in the judge message stays inside the data, the<system>wrapper holds only the note, and the attribute is escaped. - After
agent.run(message_history=first.all_messages())merges the steering request into its neighbour, the note is still found bySystemPromptPart.metadata['origin'], and the judge renders the earlier steer as steering. This test fails if the metadata lookup is disabled. - Each closing-tag variant is neutralized, and
</judge_feedbacks>and an opening<judge_feedback>are left alone. These cases are driven throughTrajectoryJudgeitself, by inspecting the enqueued parts. - On a model without inline system prompts, the second evaluation renders the first steer's message as steering, and shows the note as a
user:line (the documented limit). - On
AnthropicModel: the wire order is the user turn (tool_result, then the feedback text) followed by thesystementry holding only the note, and the first request's cached prefix is sent again byte for byte.
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