Fix #5886: Strip cache_breakpoint from LiteLLM path for non-Anthropic providers#5887
Fix #5886: Strip cache_breakpoint from LiteLLM path for non-Anthropic providers#5887devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…ders The LiteLLM-based LLM.call() (used by Groq, OpenAI-compatible, etc.) does not go through BaseLLM._format_messages() which strips the cache_breakpoint flag. This causes providers like Groq to reject messages with 'cache_breakpoint' as an unsupported property. Strip the flag in _prepare_completion_params() so it is removed from the wire payload for all providers using the LiteLLM code path. Fixes #5886 Co-Authored-By: João <joao@crewai.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
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 (2)
📝 WalkthroughWalkthroughLLM._prepare_completion_params now strips the CACHE_BREAKPOINT_KEY marker from formatted messages before sending to LiteLLM, preventing API rejections from non-Anthropic providers that don't support cache_breakpoint fields. Regression tests verify marker removal, caller-side immutability, and correct message pass-through. ChangesCache breakpoint marker handling for LiteLLM
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
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 docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
Fixes #5886 —
cache_breakpointwas leaking into the wire payload for non-Anthropic providers (Groq, OpenAI-compatible, etc.) causing API errors like:Root cause: The LiteLLM-based
LLM.call()code path (used by Groq and other non-native providers) does not go throughBaseLLM._format_messages()which stripscache_breakpoint. Instead it uses_format_messages_for_provider()→_prepare_completion_params(), neither of which stripped the flag.Native providers (OpenAI, Anthropic, Gemini, Azure, Bedrock) all call
BaseLLM._format_messages()and are unaffected.Fix: Strip
cache_breakpointinLLM._prepare_completion_params()before the messages are placed into the API request params. This creates copies (not in-place mutation) so the executor's reusable messages list retains markers across ReAct loop iterations.Review & Testing Checklist for Human
LLM(model="groq/llama-3.3-70b-versatile")with a basic crewsuper()._format_messages()strips them, so this change doesn't affect that path)tests/llms/test_prompt_cache.py::TestLiteLLMPathStripsMarkerpassNotes
lib/crewai/src/crewai/llm.py— the_prepare_completion_paramsmethodlib/crewai/tests/llms/test_prompt_cache.pyLink to Devin session: https://app.devin.ai/sessions/86df9bef10ca4e7ebfbf3c97c946f2fd
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests