Skip to content

fix: strip cache_breakpoint in LiteLLM path and expand Anthropic prefixes#5914

Open
superShen0916 wants to merge 1 commit into
crewAIInc:mainfrom
superShen0916:fix/llm-routing-improvements
Open

fix: strip cache_breakpoint in LiteLLM path and expand Anthropic prefixes#5914
superShen0916 wants to merge 1 commit into
crewAIInc:mainfrom
superShen0916:fix/llm-routing-improvements

Conversation

@superShen0916
Copy link
Copy Markdown

@superShen0916 superShen0916 commented May 23, 2026

Summary

Two small fixes to improve LLM provider routing robustness:

1. Strip cache_breakpoint in LiteLLM fallback path (Fixes #5886)

_format_messages_for_provider was not stripping cache_breakpoint flags before sending messages to providers through the LiteLLM path. This caused errors like:

GroqException - 'messages.0': property 'cache_breakpoint' is unsupported

BaseLLM._format_messages already handles this for native providers (OpenAI, Anthropic, etc.), but the LiteLLM fallback path uses its own method which missed this step. The fix strips the flag from message copies before they reach LiteLLM.

2. Expand Anthropic model prefix matching (Fixes #5893)

Added anthropic-- to the Anthropic model prefix list in _matches_provider_pattern. This allows custom deployments with names like anthropic--claude-sonnet-4 to be recognized as Anthropic models and routed to the native provider.

Changes

  • lib/crewai/src/crewai/llm.py: Strip cache_breakpoint from message copies in _format_messages_for_provider (the LiteLLM fallback path) before provider-specific formatting
  • lib/crewai/src/crewai/llm.py: Add anthropic-- to Anthropic model prefix detection

Test plan

  • Existing tests pass: TestCacheMarkerHelpers, TestBaseFormatDoesNotMutate, TestNonAnthropicStripsMarker
  • The message copy approach preserves caller message lists (no mutation) — consistent with the pattern used in BaseLLM._format_messages

Risk

Low. Changes are limited to stripping an internal-only flag from API-bound messages (already done in the native path) and expanding a prefix allowlist by one entry.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved Anthropic model compatibility with additional naming patterns.
    • Fixed cache marker handling in message preparation for improved provider request processing.

Review Change Stack

…ixes

- Strip cache_breakpoint flags in _format_messages_for_provider to fix
  errors with Groq and other LiteLLM-routed providers that reject
  unknown message fields (e.g., 'cache_breakpoint is unsupported').
  BaseLLM._format_messages already handles this for native providers.
- Add 'anthropic--' to the Anthropic model prefix list so custom
  deployments with names like 'anthropic--claude-...' are recognized.

Fixes crewAIInc#5886
Fixes crewAIInc#5893

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 55f2f543-aac8-4652-abfc-7e9d1641451a

📥 Commits

Reviewing files that changed from the base of the PR and between c3e2001 and 303d166.

📒 Files selected for processing (1)
  • lib/crewai/src/crewai/llm.py

📝 Walkthrough

Walkthrough

This PR expands Anthropic model prefix validation to support anthropic-- naming convention alongside existing claude- and anthropic. prefixes, and adds cache-breakpoint flag sanitization in LiteLLM message preparation to strip unsupported cache markers before sending requests to non-Anthropic providers.

Changes

LiteLLM Provider Compatibility

Layer / File(s) Summary
Expanded Anthropic model prefix validation
lib/crewai/src/crewai/llm.py
Anthropic/Claude provider matching logic now accepts an additional anthropic-- prefix alongside existing claude- and anthropic. prefixes.
Cache breakpoint sanitization for LiteLLM
lib/crewai/src/crewai/llm.py
_format_messages_for_provider imports strip_cache_breakpoint, shallow-copies each message dict, and applies strip_cache_breakpoint to remove cache-breakpoint flags prior to provider-specific message handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A prefix grows from claude to bright,
Anthropic flags now stripped from sight,
Cache breakpoints fade without a trace,
LiteLLM finds its proper place!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: stripping cache_breakpoint in the LiteLLM path and expanding Anthropic model name prefixes.
Linked Issues check ✅ Passed The PR addresses both linked issues: it strips cache_breakpoint before sending to LiteLLM providers (#5886) and adds 'anthropic--' prefix to Anthropic model detection (#5893).
Out of Scope Changes check ✅ Passed All changes in the PR are directly scoped to the two linked issues; no unrelated modifications were introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

None yet

1 participant