Build Harness `SystemReminders` on request-scoped system prompts and deprecate `cache_ttl`

Merged
DO
1mo ago
+1354-449

Harness SystemReminders now enqueues each firing as a request-scoped system prompt, ctx.enqueue(SystemPromptPart(text, scope='request')) from before_model_request, the pattern #9711 documents in Changing what the model sees.

It used to append a request-only UserPromptPart([CachePoint, text]) in wrap_model_request and drop it from the next request. On Claude Opus 5.5, Sonnet 5.5 and Fable 5.1 that deletion is a history edit: every earlier thinking block is invalidated, so a run with a firing reminder silently lost its reasoning. As a request-scoped prompt it stays in history: it's sent as an Anthropic clear_at system message on those models, with its own request only elsewhere, and the core places cache breakpoints before it.

A request-scoped part (kept in history, shown to the model for one request) is different from a request-only change (assigning request_context.messages, never in history). The old reminder was a request-only change; the new one is a request-scoped part.

  • Related: #9408 (Planning, which will follow the same route)

[!WARNING]
Compatibility impact (Harness 0.x): three visible changes.

  • Reminders now appear in result.all_messages(), as SystemPromptPart(scope='request') in a ModelRequest of their own. Code that asserted they were absent, or counted messages, sees one more request per firing.

  • SystemReminders no longer places its own cache breakpoint. An agent that relied on it for prompt caching without configuring caching on the model gets none now, and nothing warns about it: it's documented here and on the docs page instead. cache_ttl is deprecated and has no effect: its default is now None, and only an explicit '5m' or '1h' warns that it's ignored.

  • Reminder.tag defaults to None, not 'system-reminder'. The reminder is already a system prompt, shown to the model natively or in the core <system> tag, so the extra <system-reminder> wrapper is gone. A Reminder that leaves tag unset warns (warn_default_changed); tag='system-reminder' keeps the old text.

  • LLMReminder.__call__ returns a GeneratedReminder instead of a str; a wrapper that passes it through keeps working, and str(reminder) gives the note and quoted text. GoalReanchor and LLMReminder send different text, and neither puts text it didn't write in system voice. GoalReanchor no longer repeats the user's request: it points the model back at the user's first message, already in the conversation. LLMReminder sends a fixed framework note as a system prompt and the generated text as a user-channel TextContent in <generated_reminder model="...">. The two are one record kept in history (neither is request-scoped), sent together on every later request. LLMReminder's transcript quotes each message in <message role="...">, and its default instructions say the quoted elements are data.

Why this can ship: the Harness is on 0.x, where the version policy allows API changes in minor releases with a deprecation warning and migration guidance.

Migration: turn on caching on the model (anthropic_cache, anthropic_cache_messages, bedrock_cache_messages, openrouter_cache_messages); its breakpoint lands before the reminder. Remove any cache_ttl argument. Pass tag=None to keep the new default without the warning, or tag='system-reminder' if your prompts refer to that tag.

Changes

  • SystemReminders.before_model_request replaces wrap_model_request and enqueues the reminder; _has_user_content and the CachePoint construction are gone. Cadence, max_fires, dynamic and LLMReminder behavior (including its durable operation) are unchanged.
  • cache_ttl: Literal['5m', '1h'] | None = None: a legacy value warns through warn_argument_ignored; omitting it or passing None is silent. The unset default of Reminder.tag uses a private sentinel, so its public type stays str | None, and its docstring states the real default.
  • Reminder.tag defaults to None, warning when it's left unset.
  • The CachePoint target check moves from the shared _cache_points.py into planning/_capability.py, since Planning is its only caller now.
  • Trust: a reminder is a system prompt, so the built-in dynamic reminders keep text they didn't write out of system voice. GoalReanchor points at the user's request instead of quoting it, anchored at the latest native compaction boundary (pointing at the summary when compaction took the request), and stays request-scoped. LLMReminder returns a GeneratedReminder, a distinct type rather than a str subclass, so string operations can't drop its provenance; a plain str from a dynamic reminder is operator text in system voice. It uses the shape #10545 uses for TrajectoryJudge steering: a framework note (ranked below the operator's instructions and the user's request, worded independently of order because Anthropic sends the system entry after the request's user content) as a SystemPromptPart, and the generated text as an escaped TextContent on the user channel. They are one append-only record in history, so no later request, compaction or summary sees the generated text without its note. Every part carries metadata={'origin': 'pydantic-ai-harness.system_reminders.reminder.v1'}, and the reminders recognize their own records by it, never by text. Quoted text goes through core's neutralize_tags, which escapes every opening and closing spelling of every core framing tag (system, context, context_diff among them), and the reminder tags (goal, message, generated_reminder, summary) are neutralized the same way; attributes are html.escaped. Switching to the public pydantic_ai.framing.wrap() with registered tags is a follow-up in #10957.
  • SummarizingCompaction never takes a request-scoped system prompt for the previous summary on its legacy prefix path, whatever its text (#10573 stores new summaries as a typed CompactionPart; the prefix path remains for histories saved by earlier releases), and leaves request-scoped system prompts out of the summary request: they applied to their own request only, and now that reminders stay in history they would otherwise become lasting context.
  • Docs page, README, the Harness skill and Planning's composition notes updated. Memory's request-only-part test now uses Planning, since SystemReminders no longer adds a user part, and a test checks an LLMReminder record never moves the Memory snapshot (#10903 records it once at the start of the run, so Memory needs no change).

Live evidence

Real APIs, a three-call tool loop, SystemReminders(reminders=[Reminder('Be terse.')], dynamic_reminders=[GoalReanchor()]) (recorded before the merge with #9711, on the same wire shape):

anthropic:claude-opus-5-5  thinking + drop_block, anthropic_cache_messages
  in=3768 read=0 | 4065 read=3632 | 4134 read=3930 | 4203 read=3999   input_transformations: none
openai-chat:gpt-5.6  in=4803 read=4652 | 4838 read=4707 | 4875 read=4742 | 4910 read=4779   (no crash)

With Planning alongside, on Anthropic the plan reminder keeps its breakpoint on the tool result and the SystemReminders reminder follows it, as a clear_at system message on Opus 5.5 and as <system> text on Sonnet 4.5.

Known limitation

With UI adapters in manage_system_prompt='server' mode, the dump leaves out an LLMReminder record's system note but keeps its generated text, and AG-UI also drops the text's metadata. Client-returned history then shows the generated reminder as plain user text, which compaction may keep. The docs page and README document this and recommend keeping history on the server for LLMReminder. The fix comes with CapabilityPart (#11029); see also #11031.

Tests

tests/harness/system_reminders/test_system_reminders.py is updated to the new hook. Covered: the reminder is enqueued as a request-scoped prompt; reminders are sent only for their own request through a tool loop and all kept in history; a SlidingWindowCompaction listed after SystemReminders trims every request and each still carries its reminder; composition with Planning (the plan reminder keeps its CachePoint on the tool result and the reminder comes after it, in either listing order); an unset tag warns and an explicit one doesn't; a forged closing tag in any spelling, including at the end of the text, can't close its element (LLMReminder output and its transcript); only framework notes reach system voice, on the <system> fallback and on Anthropic, where a wire test also checks the order and the cached prefix; tool-loop and SummarizingCompaction runs for GoalReanchor and LLMReminder show no request or summary gets generated text without its note, and keep_user_messages=True never keeps a generated reminder (#10833 recognizes it as harness data by its origin); an explicit cache_ttl warns; SummarizingCompaction leaves reminders out of the summary and never takes one for the previous summary; an omitted or None cache_ttl doesn't warn and a legacy value does. The CachePoint guard tests are removed with the guard.

Open question

Losing the implicit breakpoint is the one regression a user could notice (higher cost for an agent with no caching configured). Alternative: keep a request-only CachePoint ahead of the reminder when cache_ttl is set. I'd rather not, since it duplicates what the model's own caching settings do.

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