Skip to content

fix(cache): cache all system messages and stabilize task tool descriptions#3091

Merged
tusharmath merged 4 commits intomainfrom
fix/cache-anthropic-on-user-message
Apr 20, 2026
Merged

fix(cache): cache all system messages and stabilize task tool descriptions#3091
tusharmath merged 4 commits intomainfrom
fix/cache-anthropic-on-user-message

Conversation

@amitksingh1490
Copy link
Copy Markdown
Contributor

The main changes in this PR:

  1. Anthropic cache strategy fix: Previously only the first system message was cached, now all system messages are cached. This ensures the static system prefix remains reusable. The logic also falls back to caching the first conversation message when there's no system prompt.

  2. Stabilize task tool descriptions: Added sorting of agents by ID before generating task tool descriptions to ensure deterministic output regardless of agent order.

  3. Stabilize skill loading: Added sorting of skills by name (and resources by path) to ensure deterministic skill loading order.

Key implementation details:

  • Modified SetCache transformer to cache all system messages instead of just the first
  • Added agents.sort_by(|left, right| left.id.as_str().cmp(right.id.as_str())) in tool_registry.rs
  • Added sort_skills() and sort_paths() functions in skill.rs with comprehensive tests
  • Updated tests to verify stable ordering behavior

Breaking changes: None

Testing:

  • Updated existing tests in set_cache.rs to reflect new caching behavior
  • Added test_task_tool_description_is_stable_across_agent_order test
  • Added test_sort_skills_orders_names_and_resources test
  • Updated snapshot tests for tool descriptions

…tions

The main changes in this PR:
1. **Anthropic cache strategy fix**: Previously only the first system message was cached, now all system messages are cached. This ensures the static system prefix remains reusable. The logic also falls back to caching the first conversation message when there's no system prompt.

2. **Stabilize task tool descriptions**: Added sorting of agents by ID before generating task tool descriptions to ensure deterministic output regardless of agent order.

3. **Stabilize skill loading**: Added sorting of skills by name (and resources by path) to ensure deterministic skill loading order.

Key implementation details:
- Modified `SetCache` transformer to cache all system messages instead of just the first
- Added `agents.sort_by(|left, right| left.id.as_str().cmp(right.id.as_str()))` in tool_registry.rs
- Added `sort_skills()` and `sort_paths()` functions in skill.rs with comprehensive tests
- Updated tests to verify stable ordering behavior

Breaking changes: None

Testing:
- Updated existing tests in set_cache.rs to reflect new caching behavior
- Added `test_task_tool_description_is_stable_across_agent_order` test
- Added `test_sort_skills_orders_names_and_resources` test
- Updated snapshot tests for tool descriptions
@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Apr 20, 2026
@tusharmath tusharmath merged commit acd9af5 into main Apr 20, 2026
8 checks passed
@tusharmath tusharmath deleted the fix/cache-anthropic-on-user-message branch April 20, 2026 11:48
@tusharmath
Copy link
Copy Markdown
Collaborator

Related to #3076

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants