Skip to content

fix: guard cache_breakpoint marking behind is_anthropic check#5971

Open
fedyaahmed135-star wants to merge 1 commit into
crewAIInc:mainfrom
fedyaahmed135-star:fix/cache-breakpoint-non-anthropic-providers
Open

fix: guard cache_breakpoint marking behind is_anthropic check#5971
fedyaahmed135-star wants to merge 1 commit into
crewAIInc:mainfrom
fedyaahmed135-star:fix/cache-breakpoint-non-anthropic-providers

Conversation

@fedyaahmed135-star
Copy link
Copy Markdown

@fedyaahmed135-star fedyaahmed135-star commented May 29, 2026

Fixes #5886

Problem

mark_cache_breakpoint() is called unconditionally in crew_agent_executor.py for every LLM provider. The cache_breakpoint flag is a CrewAI-internal marker that only the Anthropic provider adapter knows how to translate and strip before the API call.

Every other provider — Groq, OpenAI-compatible endpoints, Bedrock, Gemini, LiteLLM — receives cache_breakpoint: True in the raw message dict and rejects the request with 400 Bad Request.

Root cause

mark_cache_breakpoint() was imported and called unconditionally. Only llms/providers/anthropic/completion.py strips this flag — no other provider does.

Fix

Added use_cache_breakpoint guard that checks self.llm.is_anthropic before calling mark_cache_breakpoint(). When False, a no-op _maybe_mark() is used instead.

Applied to both:

  • agents/crew_agent_executor.py
  • experimental/agent_executor.py

Result

  • Anthropic: behaviour unchanged, prompt caching still works
  • Groq, OpenAI-compatible, Bedrock, Gemini: no longer receive unknown cache_breakpoint field, requests succeed

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced LLM compatibility by optimizing cache handling logic to properly support multiple LLM providers, improving performance with non-Anthropic implementations.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 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: 25553302-054e-4717-90e3-7048d1e077c2

📥 Commits

Reviewing files that changed from the base of the PR and between fca21b1 and cb6b748.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/agents/crew_agent_executor.py
  • lib/crewai/src/crewai/experimental/agent_executor.py

📝 Walkthrough

Walkthrough

Two agent executor implementations now conditionally apply Anthropic-specific cache breakpoint markers only when the LLM provider is Anthropic, preventing non-Anthropic providers (Groq, OpenAI-compatible) from receiving unsupported cache_breakpoint fields in message dictionaries.

Changes

Anthropic-conditional cache breakpoint wrapping

Layer / File(s) Summary
CrewAgentExecutor conditional cache breakpoint
lib/crewai/src/crewai/agents/crew_agent_executor.py
_setup_messages introduces an is_anthropic check and defines a local _maybe_mark wrapper that either applies mark_cache_breakpoint or returns messages unchanged, then uses this wrapper for both system and user prompt messages.
AgentExecutor conditional cache breakpoint in sync and async paths
lib/crewai/src/crewai/experimental/agent_executor.py
invoke() and invoke_async() both introduce the same conditional _maybe_mark wrapper pattern for system/user message formatting, applying mark_cache_breakpoint only when self.llm.is_anthropic is true, mirroring the CrewAgentExecutor pattern across dual invocation paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • crewAIInc/crewAI#5774: This PR removed unconditional mark_cache_breakpoint calls and added the initial placement of cache breakpoint wrapping that this PR now conditions on Anthropic LLMs.

Suggested labels

size/L

Poem

🐰 With whiskers twitching in the morning light,
Cache breakpoints now check if Anthropic's right,
Groq and OpenAI skip the flag with glee,
Messages flow clean and happy and free!

🚥 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 'fix: guard cache_breakpoint marking behind is_anthropic check' clearly and concisely describes the main change: adding conditional logic to only apply cache breakpoints for Anthropic LLMs.
Linked Issues check ✅ Passed The PR fully addresses issue #5886 by preventing mark_cache_breakpoint() from being called unconditionally on all LLM providers, restricting it to Anthropic only via the is_anthropic check.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the cache_breakpoint issue: modifications to crew_agent_executor.py and experimental/agent_executor.py to conditionally apply mark_cache_breakpoint based on LLM provider type.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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

Development

Successfully merging this pull request may close these issues.

[BUG] cache_breakpoint injected into messages for non-Anthropic providers (Groq, OpenAI-compatible)

1 participant