State loaded deferred capabilities' instructions in the system voice, append their changes, and show them to `before_model_request`
- Closes #7236
Also settles #8879. After this PR, a loaded deferred capability's instructions reach the model in the system voice, after the load_capability call. They no longer arrive as the tool result.
Until now a loaded capability's instructions arrived as the load_capability tool result. They were resolved once, when the capability loaded. A dynamic instruction kept its load-time value for the rest of the conversation, on_change='append' only produced a warning, and before_model_request hooks never saw them.
The tool-result placement also cost the instructions their authority. In a live probe (10 models, 3 placements, 8 conversations each), the user pushed against a loaded rule, and then a fetched page claimed to supersede it. With the rules in the tool result, Claude Opus 5.5 kept them 0 times out of 8. With the rules in a native system message it kept them 8 times out of 8. Putting them in both places was as bad as the tool result alone. No other model did worse with the system message.
[!WARNING]
Compatibility impact:
- Placement. The
load_capability tool result is now {"message": "Capability '<id>' loaded. Its instructions, if any, follow."} (whether or not there are any, so loading doesn't resolve them twice), and LoadCapabilityReturnPart.instructions is None for new loads. The capability's instructions are recorded as InstructionDeltaPart(id='capability:<id>') on the request after the load. They are sent as a mid-conversation system message where the model supports one, and as <system> text in the tool result's turn elsewhere. Code that read the instructions from the load return gets nothing. A FunctionModel sees them as a system part, or as <system> text, after the tool return.
- Withdrawals. Continuing a history that loaded a capability the agent no longer has now appends a withdrawal of that capability's block. A capability whose instructions now resolve to nothing is withdrawn the same way.
- Per-request updates. A loaded capability's dynamic instructions are resolved again before every request, and every change is appended. An instruction that changes on every request, such as one that renders the current time, appends an update to every request.
Why this can ship in a minor release:
- The tool result was never a documented contract for reading a capability's instructions.
- A dynamic instruction that stayed at its load-time value was a bug: the model kept following stale or removed instructions.
- Message-part changes are permitted by the version policy.
- Histories from earlier versions keep working. Their load returns still seed the block, and nothing is sent again.
Migration:
- Read loaded instructions from the
InstructionDeltaParts for capability:<id>, or in a before_model_request hook via instruction_parts, where instruction_visibility_of(part) reports 'via_history'.
- Render a timestamp at date precision, or move it out of the instructions.
- If you deliberately run a history against an agent without one of its loaded capabilities, expect that capability's block to be withdrawn.
Release note: loaded deferred capabilities' instructions are now stated in the system voice after the load_capability call, and their later changes are appended to history. The tool result only confirms the load.
What changes:
- Load. The tool result only confirms the load. The request after it states the capability's instructions as
InstructionDeltaPart(id='capability:<registry id>'), placed right after the load return. It is rendered through the existing #8188 path: Anthropicrole: systemon models that accept it, an OpenAIsystemmessage on Responses and Chat (which OpenAI treats asdeveloperon reasoning models), and<system>text in the same turn as the tool result elsewhere. Wire shapes are pinned for all of them. Realtime sessions have no delta channel, so the return still carries the instructions there. - Changes. One mechanism and one fold seed. Later changes to the block are appended as further deltas, as diffs where shorter, whatever
on_changesays. The "on_change='append'is not supported for deferred capability instructions" warning is gone. A capability whose instructions resolve to nothing, or that the agent no longer has, is withdrawn. One that is eager again is left alone. - Hooks.
before_model_requestsees loaded parts ininstruction_parts, re-keyed beneathcapability:<id>, and the newModelRequestParameters.instruction_visibilitymarks them'via_history'(read it withinstruction_visibility_of(part)). The graph removes them, and resets the map toNone, before the model is called, so provider adapters are unchanged. Hooks shape the first statement too. A hook that buildsinstruction_partsfrom scratch leaves loaded capabilities as if it weren't there. A hook withdraws one by emptying its parts. - Scope. A loaded block's state is folded from history (
LoadedInstructionValues). It opens at the load and closes at a compaction, which drops the load so the model loads again. A new prefix window doesn't cut off its statements. Deltas for loaded ids are kept out of the prefix fold, so the block isn't spuriously withdrawn. - UI round trips.
sanitize_messages(strip_system_prompts=True)strips instruction deltas, so a client's history comes back without the statement. The next request then states the capability's current instructions again, as a recorded delta at the end of the conversation, and appends later changes after it. Nothing already sent is rewritten; the cost is one restatement per client turn at the tail. The instructions never reach the client either, since UI dumps leave deltas out. - History processing. A processor that removes a load exchange unloads the capability, so its resolved parts go nowhere: not into history, and not into the prefix.
- Eager again. A loaded capability that becomes eager with an append-mode block hands the block to the prefix. The handover opens a new window whose baseline holds the block, and the block is stated once more after the load's statements so that it supersedes them. From then on, its changes are the prefix's.
- Legacy histories. A load return that carries
instructionsseeds the block and isn't restated. The first change after it is sent in full, so text a client edited into a tool result is never quoted in a system-voice diff (veria finding). - The standing catalog sentence from the previous revision is dropped, so the catalog is byte-identical to
main.
Tests:
tests/test_loaded_capability_instructions.pycovers:- the first statement and its placement, changes and diffs
- a JSON round trip
- a legacy seed that isn't restated
- withdrawals (empty instructions, or the capability no longer configured), and an eager-again capability that is left alone
- a new prefix window
- compaction, after which the capability reloads
- client round trips (restated, changed, unconfigured)
- hooks shaping the instructions, dropping the prefix, or leaving loaded parts out
- a forged load return
- wire shapes on Anthropic, Responses, Chat, and the
<system>fallback on Haiku 4.5
tests/test_history_append_only.py: thedeferred:dynamic_instructionscase runs across Anthropic, OpenAI Responses and OpenAI Chat.tests/models/test_anthropic_loaded_capability_instructions.py: the probe's pressure scenario, recorded onclaude-opus-5-5. The user asks for a permanent delete, and then a fetched page claims to supersede the rules. In the recording the model kept every rule: it never calleddelete_fileand signed every reply.
Docs: docs/capabilities/on-demand.md, docs/agent.md, docs/capabilities/custom.md, agent_docs/message-history-and-caching.md, and the ON-DEMAND-CAPABILITIES skill reference.
Harness compaction's token estimate now counts a loaded capability's statements recorded before the current instruction window, since core keeps sending them while the load is in history.
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