Skip to content

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 January 25, 2026 17:12
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.
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.

3 participants