fix(ai): advance Anthropic cache marker across tool results - #1927
Merged
Merged
Conversation
samsja
previously approved these changes
Aug 31, 2026
samsja
approved these changes
Sep 1, 2026
olety
pushed a commit
to oneiron-dev/prime-agent
that referenced
this pull request
Sep 1, 2026
…ellect-ai#1927) * fix(ai): cache Anthropic tool results * docs(ai): add cache fix changelog fragment * test(ai): trim Anthropic cache regression * test(ai): use Haiku cache fixture
PR9000
pushed a commit
to PR9000/prime-agent
that referenced
this pull request
Sep 1, 2026
…ellect-ai#1927) * fix(ai): cache Anthropic tool results * docs(ai): add cache fix changelog fragment * test(ai): trim Anthropic cache regression * test(ai): use Haiku cache fixture
5 tasks
ketema
added a commit
to ketema/prime-agent
that referenced
this pull request
Sep 1, 2026
- Direct session transport between TUI and worker (ENG-5817, PrimeIntellect-ai#1926) - Event-driven supervisor agent roster with push subscriptions (PrimeIntellect-ai#1897, PrimeIntellect-ai#1900, PrimeIntellect-ai#1895) - Hardened daemon startup, recovery ownership, and worker launch diagnostics (PrimeIntellect-ai#1929, PrimeIntellect-ai#1918) - Python REPL runtime single-dump snapshots and bash preview tool (PrimeIntellect-ai#1945, PrimeIntellect-ai#1911) - Non-blocking RLM subagent deletion and snapshot update suppression (PrimeIntellect-ai#1954, PrimeIntellect-ai#1944) - Saved catalog loading on Agents View open (PrimeIntellect-ai#1960) - Advanced Anthropic prompt caching marker across tool results (PrimeIntellect-ai#1927) - TUI process replacement on update and empty draft eviction (PrimeIntellect-ai#1631, PrimeIntellect-ai#1946, PrimeIntellect-ai#1920)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cache_controlLinear: ENG-5823
Why
Prime Agent's Python kernel loop often emits assistant messages with
content: nullafter the first turn, while each kernel result is sent as atoolmessage. The cache-marker scan skipped tool messages, so it walked back to an earlier assistant text block and left the rolling breakpoint frozen there. Every later tool call and result was then resent as uncached input.Test plan
npm test -w packages/ainpx biome check packages/ai/src/providers/openai-completions.ts packages/ai/test/openai-completions-cache-control-format.test.tsnpx tsgo --noEmitNote
Low Risk
Narrow change to where cache markers are attached on Anthropic-format completions; improves caching behavior without touching auth or data handling.
Overview
Fixes Anthropic-compatible rolling prompt cache placement so the ephemeral
cache_controlmarker can land on the latesttoolmessage, not only user or assistant turns.In
openai-completions.ts, the backward scan inaddCacheControlToLastConversationMessageand the helpersaddCacheControlToMessage/addCacheControlToTextContentnow treatrole: "tool"like other conversational messages. That matters when assistant turns are tool-call-only (e.g. empty text) and each kernel step ends with a tool result—the marker previously stuck on an earlier assistant block, so later tool traffic was treated as uncached input.Adds a regression test that asserts the last outbound message is a
toolpayload withcache_controlon its text part, plus a short changelog note.Reviewed by Cursor Bugbot for commit eb64556. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix Anthropic cache marker to advance across
toolresult messagesPreviously the rolling
cache_controlmarker could only land on user or assistant messages, so it never advanced past a tool result. ExpandsaddCacheControlToLastConversationMessage,addCacheControlToMessage, andaddCacheControlToTextContentin openai-completions.ts to also considerrole: 'tool'messages when placing the ephemeral cache marker. Adds a test confirming the marker lands on the final tool message in a conversation ending with a tool result.Changes since #1927 opened
Macroscope summarized be91ea9.