System-Reminders mitten im Chat: AI SDK-Fix hält sie an Ort und Stelle
Eine Änderung im AI SDK sorgt dafür, dass System-Reminders während eines laufenden Chats mit Claude an der vorgesehenen Position bleiben. Entwickler können das Verhalten ohne echte API-Aufrufe über einen Fake-Endpunkt nachvollziehen.

Vom Cuelark-Team. Quellen: AI SDK Release Notes, PR und Dokumentation sowie die API-Dokumentation von Anthropic, geprüft am 29. November 2026. Wir haben Claude nicht tatsächlich aufgerufen: Alles lief gegen einen gefälschten Anthropic-Endpunkt mit ai@7.0.184 und @ai-sdk/anthropic@4.0.111 (sowie 4.0.110 zum Vergleich), sodass sichtbar wird, welche Anfrage deine App sendet, nicht die Modellausgabe.
Claude kann eine Rolle übernehmen: eine "system"-Nachricht mitten im Nachrichtenverlauf. Prompt Caching bildet einen Hash über zuerst die Tools, dann das System und dann die Nachrichten; ein Treffer erfordert, dass dieses Präfix Byte für Byte übereinstimmt. Ändert man das top-level System mitten im Chat, geht der Cache für alles danach verloren. Hängt man dagegen eine Systemnachricht an der Stelle an, wo die neue Regel gelten soll, bleibt das gecachte Präfix unverändert.
Das AI SDK unterstützt das mit allowSystemInMessages: true, aber bis zu dieser Woche verhielt sich ein häufiger Fall fehlerhaft.
Der Patch (27. November UTC) behebt zwei Fälle, die einen Cache-Breakpoint lautlos verwerfen:
Der Fix fügt providerOptions.anthropic.midConversationSystemMessages hinzu (Standardwert false). Ist der Wert true, bleibt eine spätere Systemnachricht dort, wo man sie platziert hat. Eine Nachricht, die nur toolChanges enthält, setzt ihr cacheControl jetzt auf ihre letzte Tool-Änderung.
Anthropic listet Systemnachrichten mitten im Gespräch für Claude Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.1, Fable 5, Mythos 5, Opus 5.5, Opus 5, Opus 4.8, Sonnet 5.5 und Haiku 5.5. Claude Sonnet 5 unterstützt sie nicht. Aktiviere die Option nur für die gelisteten Modelle.
Der gleiche Verlauf durch beide Versionen: user, assistant, user, dann eine System-Erinnerung mit cacheControl.
const history = [ { role: 'user', content: 'Here is our style guide... (long)' }, { role: 'assistant', content: 'Got it.' }, { role: 'user', content: 'Rewrite the intro.' }, { role: 'system', content: 'Reply in US English. Keep it under 120 words.', providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } }, }, ]; await generateText ( { model: anthropic ( 'claude-opus-5-5' ), allowSystemInMessages: true, messages: history, providerOptions: { anthropic: { midConversationSystemMessages: true } }, } ); Enter fullscreen mode Exit fullscreen mode Was der Endpunkt empfangen hat:
Im Tool-Fall enthielt eine Systemnachricht nur toolChanges: [{ type: 'tool_addition', toolName: 'exportPdf' }] plus cacheControl. Auf 4.0.110 gab es dort keinen Breakpoint. Auf 4.0.111 wurde {"type":"tool_addition","tool":{"type":"tool_reference","name":"exportPdf"},"cache_control":{"type":"ephemeral"}} gesendet.
Eine Erinnerung muss bei jeder Anfrage an derselben Position stehen, sonst passt das Präfix nicht mehr. UI-Nachrichten von useChat enthalten keine Systemnachrichten, daher speichern wir die Erinnerung als Metadatum auf ihrer User-Nachricht und bauen sie auf dem Server in jeder Runde neu auf.
// app/api/chat/route.ts import { anthropic } from '@ai-sdk/anthropic'; import { streamText, convertToModelMessages, type UIMessage, type ModelMessage } from 'ai'; export type ChatMessage = UIMessage < { reminder?: string } >; const cache = { anthropic: { cacheControl: { type: 'ephemeral' as const } } }; export async function POST ( req: Request ) { const { messages }: { messages: ChatMessage [ ] } = await req. json ( ); const modelMessages: ModelMessage [ ] = [ ]; for ( const m of messages ) { modelMessages. push (... ( await convertToModelMessages ( [ m ] ) ) ); // Put the reminder back right after its user turn on every request. if ( m. role === 'user' && m. metadata?. reminder ) { modelMessages. push ( { role: 'system', content: m. metadata. reminder } ); } } // One breakpoint on the newest message covers the whole history. const last = modelMessages. at ( - 1 )!; last. providerOptions = {... last. providerOptions,... cache }; const result = streamText ( { model: anthropic ( 'claude-opus-5-5' ), allowSystemInMessages: true, messages: modelMessages, providerOptions: { anthropic: { midConversationSystemMessages: true } }, } ); return result. toUIMessageStreamResponse ( ); } Enter fullscreen mode Exit fullscreen mode Auf dem Client hängt eine Checkbox im Eingabefeld die Erinnerung an:
const { messages, sendMessage, status } = useChat < ChatMessage > ( ); sendMessage ( { text: input, metadata: usEnglish? { reminder: 'Reply in US English from here on.' }: undefined, } ); Enter fullscreen mode Exit fullscreen mode Wir haben diesen Handler zweimal gegen einen gefälschten Streaming-Endpunkt aufgerufen, wie zwei useChat-Runden. Auf 4.0.111 sendete Runde 1 user > system mit dem Breakpoint auf der Erinnerung; Runde 2 sendete user > system > assistant > user mit dem Breakpoint auf der neuesten User-Nachricht. Wenn man cache_control ignoriert, waren die Nachrichten von Runde 1 ein exaktes Präfix derer von Runde 2, und beide wurden durch toUIMessageStreamResponse zurückgestreamt.
Auf 4.0.110 wanderte die Erinnerung in das top-level System, was auch ihre Bedeutung ändert: Sie gilt nun für den gesamten Chat, einschließlich früherer Runden.
Um den Aufbau der Chat-UI zu überspringen, bietet Cuelark UI shadcn-artige Chat-Komponenten, die zu diesem Setup passen.
Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.
Original (Englisch) anzeigen
By the Cuelark Team. Sources: AI SDK release notes, PR and docs, and Anthropic's API docs, checked 29 November 2026. We didn't call Claude: everything ran against a fake Anthropic endpoint on ai@7.0.184 with @ai-sdk/anthropic@4.0.111 (and 4.0.110 for comparison), so it shows the request your app sends, not model output.
Claude can take a role: "system" message in the middle of messages. Prompt caching hashes tools, then system, then messages, and a hit needs that prefix to match byte for byte. Edit the top-level system mid-chat and you lose the cache for everything after it. Append a system message where the new rule applies and the cached prefix stays the same.
The AI SDK supports this with allowSystemInMessages: true, but until this week one common case misbehaved.
The patch (November 27 UTC) fixes two cases that silently drop a cache breakpoint:
The fix adds providerOptions.anthropic.midConversationSystemMessages (default false ). When true, a later system message stays where you put it. A tool-changes-only message now puts its cacheControl on its last tool change.
Anthropic lists mid-conversation system messages for Claude Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.1, Fable 5, Mythos 5, Opus 5.5, Opus 5, Opus 4.8, Sonnet 5.5 and Haiku 5.5. Claude Sonnet 5 doesn't. Only enable the option for listed models.
Same history through both versions: user, assistant, user, then a system reminder with cacheControl.
const history = [ { role: 'user', content: 'Here is our style guide... (long)' }, { role: 'assistant', content: 'Got it.' }, { role: 'user', content: 'Rewrite the intro.' }, { role: 'system', content: 'Reply in US English. Keep it under 120 words.', providerOptions: { anthropic: { cacheControl: { type: 'ephemeral' } } }, }, ]; await generateText ( { model: anthropic ( 'claude-opus-5-5' ), allowSystemInMessages: true, messages: history, providerOptions: { anthropic: { midConversationSystemMessages: true } }, } ); Enter fullscreen mode Exit fullscreen mode What the endpoint received:
For the tool case, a system message containing only toolChanges: [{ type: 'tool_addition', toolName: 'exportPdf' }] plus cacheControl. had no breakpoint on 4.0.110. On 4.0.111 it sent {"type":"tool_addition","tool":{"type":"tool_reference","name":"exportPdf"},"cache_control":{"type":"ephemeral"}}.
A reminder must sit in the same position on every request, or the prefix stops matching. useChat UI messages don't include system messages, so we store the reminder as metadata on its user message and rebuild it on the server each turn.
// app/api/chat/route.ts import { anthropic } from '@ai-sdk/anthropic'; import { streamText, convertToModelMessages, type UIMessage, type ModelMessage } from 'ai'; export type ChatMessage = UIMessage < { reminder?: string } >; const cache = { anthropic: { cacheControl: { type: 'ephemeral' as const } } }; export async function POST ( req: Request ) { const { messages }: { messages: ChatMessage [ ] } = await req. json ( ); const modelMessages: ModelMessage [ ] = [ ]; for ( const m of messages ) { modelMessages. push (... ( await convertToModelMessages ( [ m ] ) ) ); // Put the reminder back right after its user turn on every request. if ( m. role === 'user' && m. metadata?. reminder ) { modelMessages. push ( { role: 'system', content: m. metadata. reminder } ); } } // One breakpoint on the newest message covers the whole history. const last = modelMessages. at ( - 1 )!; last. providerOptions = {... last. providerOptions,... cache }; const result = streamText ( { model: anthropic ( 'claude-opus-5-5' ), allowSystemInMessages: true, messages: modelMessages, providerOptions: { anthropic: { midConversationSystemMessages: true } }, } ); return result. toUIMessageStreamResponse ( ); } Enter fullscreen mode Exit fullscreen mode On the client, a composer checkbox attaches the reminder:
const { messages, sendMessage, status } = useChat < ChatMessage > ( ); sendMessage ( { text: input, metadata: usEnglish? { reminder: 'Reply in US English from here on.' }: undefined, } ); Enter fullscreen mode Exit fullscreen mode We called this handler twice against a fake streaming endpoint, like two useChat turns. On 4.0.111, turn 1 sent user > system with the breakpoint on the reminder; turn 2 sent user > system > assistant > user with the breakpoint on the newest user message. Ignoring cache_control, turn 1's messages were an exact prefix of turn 2's, and both streamed back through toUIMessageStreamResponse. On 4.0.110 the reminder moved into top-level system, which also changes its meaning: it now applies to the whole chat, earlier turns included.
To skip building the chat UI, Cuelark UI has shadcn-style chat components that fit this setup.