release: Anthropic prompt cache control (#599)

Merged
SW
5mo ago
+348-1

Summary

  • Ports open-agents' addCacheControl helper (split into isAnthropicModel, addCacheControlToTools, addCacheControlToMessages per SRP)
  • Wires into runAgentStep: tools wrapped once + prepareStep callback wraps messages per step
  • Anthropic now caches system prompt + tools across turns; subsequent turns re-read most of the prefix at ~10% cost

Test plan

  • 19 unit tests; full suite 3138/3138 pass
  • E2E on preview verified: turn 2 cost drops from baseline $0.005959 โ†’ $0.00167 (72% cheaper); cacheReadTokens=5020 on turn 2 (was 0)
  • Cache shape matches open-agents production (4.5ร— drop on Haiku vs 12ร— on Opus โ€” ratio reflects model, shape matches)

๐Ÿค– Generated with Claude Code


Summary by cubic

Adds Anthropic prompt caching to the chat workflow so the system prompt and tools are reused across turns. Marks the last tool and last message with cacheControl: { type: "ephemeral" }, cutting follow-up turn input cost (~72% in E2E).

  • New Features
    • Added isAnthropicModel, addCacheControlToTools, and addCacheControlToMessages.
    • runAgentStep: wraps tools once and uses prepareStep to tag the final message per step (Anthropic only).
    • No changes for non-Anthropic models; 19 unit tests cover helpers and wiring.