Skip to content

fix(anthropic): tool result caching#867

Merged
sixlive merged 2 commits intomainfrom
fix/tool-result-caching-accumulation
Mar 1, 2026
Merged

fix(anthropic): tool result caching#867
sixlive merged 2 commits intomainfrom
fix/tool-result-caching-accumulation

Conversation

@sixlive
Copy link
Contributor

@sixlive sixlive commented Jan 25, 2026

Description

Refactor of #485.

Problem

When using tool_result_cache_type in multi-step tool calling scenarios, cache_control was being applied to every ToolResultMessage instead of just the last one. This could exceed Anthropic's 4 cache breakpoint limit and is unnecessary since the system uses "longest matching prefix" caching.

Solution

Move cache control application from Text.php (per-message during handleToolCalls()) to MessageMap::map() where it applies cache_control only to the last ToolResultMessage across all messages.

Changes

  • Text.php: Remove automatic cacheType application to each ToolResultMessage
  • MessageMap.php: Apply cache_control only to the last tool result message
  • ToolResultCachingTest.php: Unit and integration tests for the fix
  • Fixtures: Real API response fixtures for integration testing

elliottlawson and others added 2 commits March 1, 2026 15:23
Apply tool_result_cache_type only to the last tool result message across all messages instead of applying it to each tool result during creation. This prevents cache accumulation when there are multiple tool call rounds.
@sixlive sixlive force-pushed the fix/tool-result-caching-accumulation branch from a34ce71 to 32c781c Compare March 1, 2026 20:23
@kinsta
Copy link

kinsta bot commented Mar 1, 2026

Preview deployments for prism ⚡️

Status Branch preview Commit preview
✅ Ready Visit preview Visit preview

Commit: 32c781c8b01d61325307a770cbbc37f952030000

Deployment ID: 0c544dc5-eb10-4c74-ae56-2bcbdbedae49

Static site name: prism-97nz9

@sixlive sixlive merged commit 83d4f6e into main Mar 1, 2026
14 checks passed
@sixlive sixlive deleted the fix/tool-result-caching-accumulation branch March 1, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants