Skip to content

feat(llm): add native Groq provider and fix cache_breakpoint for non-Anthropic models#6314

Open
AHMEDDEV2004 wants to merge 2 commits into
crewAIInc:mainfrom
AHMEDDEV2004:feat/add-groq-native-provider
Open

feat(llm): add native Groq provider and fix cache_breakpoint for non-Anthropic models#6314
AHMEDDEV2004 wants to merge 2 commits into
crewAIInc:mainfrom
AHMEDDEV2004:feat/add-groq-native-provider

Conversation

@AHMEDDEV2004

@AHMEDDEV2004 AHMEDDEV2004 commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Closes #6286
Fixes #5886

This PR adds native Groq provider support and fixes the cache_breakpoint bug that causes BadRequestError on non-Anthropic providers.

1. Native Groq Provider

  • Added "groq" to SUPPORTED_NATIVE_PROVIDERS and provider_mapping
  • Added ProviderConfig for Groq in OPENAI_COMPATIBLE_PROVIDERS pointing to https://api.groq.com/openai/v1
  • Added pattern matching for common Groq model prefixes: llama, gemma, mixtral, whisper, deepseek
  • Models route via OpenAICompatibleCompletion — no new dependencies

Usage:

from crewai import LLM
llm = LLM(model="groq/llama-3.3-70b-versatile")

2. Cache Breakpoint Fix

The cache_breakpoint key (Anthropic-specific prompt caching marker) was being sent to all providers in the LiteLLM path via _format_messages_for_provider(). Non-Anthropic APIs reject this unknown field:

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

Fix: Strip cache_breakpoint from all messages in _format_messages_for_provider when self.is_anthropic is False. This is the minimal, correct fix — it handles the LiteLLM fallback path that base_llm._format_messages() (native path) already covers.

Verification

  • Unit tests verify:
    • Groq appears in SUPPORTED_NATIVE_PROVIDERS
    • Groq config points to correct API endpoint
    • Model patterns match Groq model families
    • _get_native_provider("groq") returns OpenAICompatibleCompletion
    • cache_breakpoint is stripped for non-Anthropic providers
    • cache_breakpoint is preserved for Anthropic providers
  • Manually tested with GROQ_API_KEY set and groq/llama-3.3-70b-versatile model

Test plan

  • Syntax validation passes on all modified files
  • Unit tests for routing and cache_breakpoint stripping
  • CI will validate against full test suite

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for a new model provider, expanding available routing options.
    • Tool execution errors are now shown in a more structured, consistent format.
  • Bug Fixes

    • Improved handling of tool failures so error details are clearer and more actionable.
    • Prevented unsupported message fields from being sent to providers that don’t accept them.

ahmed-sobrus and others added 2 commits June 24, 2026 13:52
Replace generic "Error executing tool: {e}" strings with structured
JSON containing exception type, message, and retryability hint.
This gives agents the information needed to decide whether to retry,
fix their input, or skip the tool entirely.

Closes crewAIInc#6262

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…for non-Anthropic

Adds Groq as a natively supported OpenAI-compatible provider, routing
groq/* models directly to https://api.groq.com/openai/v1 without
requiring the heavier LiteLLM fallback.

Also fixes the cache_breakpoint bug (crewAIInc#5886) where the Anthropic-specific
cache_breakpoint key was sent to non-Anthropic providers, causing
BadRequestError on Groq, OpenAI-compatible, and other providers.

Closes crewAIInc#6286
Fixes crewAIInc#5886

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@corridor-security corridor-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: This PR adds native Groq provider routing, strips Anthropic-only cache metadata for non-Anthropic providers, and standardizes tool error formatting; no exploitable security vulnerabilities were identified.

Risk: Low risk. The changes do not introduce new public endpoints, authentication or authorization logic, file/network access paths, or unsafe execution surfaces beyond existing LLM provider integration behavior.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces a format_tool_error utility that serializes tool exceptions into a structured JSON-prefixed string, adopted across all agent executor and LLM tool-call error paths. Separately adds native Groq provider routing via the OpenAI-compatible completion layer and strips the CACHE_BREAKPOINT_KEY field from outbound messages for non-Anthropic providers.

Changes

Structured tool error formatting

Layer / File(s) Summary
format_tool_error utility module
lib/crewai/src/crewai/utilities/tool_errors.py
New module defines RETRYABLE_EXCEPTIONS and format_tool_error, which returns a backward-compatible "Error executing tool: " prefix followed by JSON containing exception type, message, retryable flag, and optional truncated traceback.
Adopt format_tool_error across executor and LLM error paths
lib/crewai/src/crewai/agents/crew_agent_executor.py, lib/crewai/src/crewai/experimental/agent_executor.py, lib/crewai/src/crewai/utilities/agent_utils.py, lib/crewai/src/crewai/llm.py
Imports format_tool_error and replaces all hardcoded f"Error executing tool: {e}" strings with format_tool_error(e) in _execute_single_native_tool_call, execute_tool_action, execute_native_tool parallel path, and _handle_tool_call event emission.
Tests for format_tool_error and RETRYABLE_EXCEPTIONS
lib/crewai/tests/test_tool_errors.py
Validates JSON prefix format, error/type/message fields, retryable flag per exception class, traceback inclusion toggle, edge cases (empty message, special characters, subclasses), and membership of TimeoutError/ConnectionError/OSError in RETRYABLE_EXCEPTIONS.

Groq native provider and cache_breakpoint stripping

Layer / File(s) Summary
Groq provider registration and routing
lib/crewai/src/crewai/llm.py, lib/crewai/src/crewai/llms/providers/openai_compatible/completion.py
Adds groq to SUPPORTED_NATIVE_PROVIDERS, maps the groq model-name prefix in LLM.__new__, extends _matches_provider_pattern for Groq model name prefixes, includes groq in openai_compatible_providers for _get_native_provider, and inserts a ProviderConfig entry with base_url=https://api.groq.com/openai/v1, GROQ_API_KEY/GROQ_BASE_URL env vars, and api_key_required=True.
Strip CACHE_BREAKPOINT_KEY for non-Anthropic providers
lib/crewai/src/crewai/llm.py
In _format_messages_for_provider, removes CACHE_BREAKPOINT_KEY from each outbound message dict when the target model is not Anthropic, preventing unknown-field rejections (e.g., GroqException: property 'cache_breakpoint' is unsupported).
Tests for Groq routing and cache_breakpoint stripping
lib/crewai/tests/llms/test_groq_provider.py
Verifies Groq is in SUPPORTED_NATIVE_PROVIDERS, configured in OPENAI_COMPATIBLE_PROVIDERS with the expected base URL and API key requirements, matches Groq-specific model name patterns, routes to OpenAICompatibleCompletion, and that _format_messages_for_provider strips cache_breakpoint only for non-Anthropic providers while preserving role and content.

Suggested Reviewers

  • greysonlalonde
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several changes add standardized tool-error formatting and new error utilities/tests, which are unrelated to the Groq and cache_breakpoint objectives. Move the tool-error formatting work into a separate PR, or add a linked issue that explicitly calls for those changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: native Groq support and the cache_breakpoint fix for non-Anthropic models.
Linked Issues check ✅ Passed The PR implements both linked requirements: Groq native/OpenAI-compatible support and stripping cache_breakpoint for non-Anthropic providers. [6286, 5886]

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

Warning

⚠️ This pull request shows signs of AI-generated slop (trivial_assertion). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/crewai/src/crewai/utilities/tool_errors.py`:
- Around line 27-28: The traceback handling in the error formatting helper
should use the traceback attached to the provided exception object instead of
the ambient exception state. Update the logic in the tool error utility that
builds error_data so that, when include_traceback is enabled, it formats
exception.__traceback__ directly rather than calling traceback.format_exc();
keep the change localized to the same helper and preserve the existing error
payload structure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: be16a89f-5f08-46fc-bbaa-1ac8ff487ae3

📥 Commits

Reviewing files that changed from the base of the PR and between a046e6a and 37fc0a6.

📒 Files selected for processing (8)
  • lib/crewai/src/crewai/agents/crew_agent_executor.py
  • lib/crewai/src/crewai/experimental/agent_executor.py
  • lib/crewai/src/crewai/llm.py
  • lib/crewai/src/crewai/llms/providers/openai_compatible/completion.py
  • lib/crewai/src/crewai/utilities/agent_utils.py
  • lib/crewai/src/crewai/utilities/tool_errors.py
  • lib/crewai/tests/llms/test_groq_provider.py
  • lib/crewai/tests/test_tool_errors.py

Comment on lines +27 to +28
if include_traceback:
error_data["traceback"] = traceback.format_exc(limit=3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Format the traceback from exception.__traceback__, not ambient exception state.

traceback.format_exc() only works for the currently handled exception. If this helper is reused on a captured/re-raised exception, include_traceback=True can return NoneType: None or the wrong stack.

Proposed fix
     if include_traceback:
-        error_data["traceback"] = traceback.format_exc(limit=3)
+        error_data["traceback"] = "".join(
+            traceback.format_exception(
+                type(exception),
+                exception,
+                exception.__traceback__,
+                limit=3,
+            )
+        )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if include_traceback:
error_data["traceback"] = traceback.format_exc(limit=3)
if include_traceback:
error_data["traceback"] = "".join(
traceback.format_exception(
type(exception),
exception,
exception.__traceback__,
limit=3,
)
)
🧰 Tools
🪛 ast-grep (0.44.0)

[info] 28-28: use jsonify instead of json.dumps for JSON output
Context: json.dumps(error_data)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai/src/crewai/utilities/tool_errors.py` around lines 27 - 28, The
traceback handling in the error formatting helper should use the traceback
attached to the provided exception object instead of the ambient exception
state. Update the logic in the tool error utility that builds error_data so
that, when include_traceback is enabled, it formats exception.__traceback__
directly rather than calling traceback.format_exc(); keep the change localized
to the same helper and preserve the existing error payload structure.

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

Labels

None yet

Projects

None yet

2 participants