fix: strip cache_breakpoint in LiteLLM path and expand Anthropic prefixes#5914
fix: strip cache_breakpoint in LiteLLM path and expand Anthropic prefixes#5914superShen0916 wants to merge 1 commit into
Conversation
…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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR expands Anthropic model prefix validation to support ChangesLiteLLM Provider Compatibility
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Two small fixes to improve LLM provider routing robustness:
1. Strip cache_breakpoint in LiteLLM fallback path (Fixes #5886)
_format_messages_for_providerwas not strippingcache_breakpointflags before sending messages to providers through the LiteLLM path. This caused errors like:BaseLLM._format_messagesalready 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 likeanthropic--claude-sonnet-4to be recognized as Anthropic models and routed to the native provider.Changes
lib/crewai/src/crewai/llm.py: Stripcache_breakpointfrom message copies in_format_messages_for_provider(the LiteLLM fallback path) before provider-specific formattinglib/crewai/src/crewai/llm.py: Addanthropic--to Anthropic model prefix detectionTest plan
TestCacheMarkerHelpers,TestBaseFormatDoesNotMutate,TestNonAnthropicStripsMarkerBaseLLM._format_messagesRisk
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