crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[Feature Request & Bug]: Add native Groq provider support and strip cache_breakpoint for non-Anthropic models

Open Mahajan-Sachin opened this issue 5 months ago • 7 comments

Feature Area

Core functionality

Is your feature request related to a an existing bug? Please link it here.

Yes, it is related to this open bug: https://github.com/crewAIInc/crewAI/issues/5886

Describe the solution you'd like

  1. Add groq natively to SUPPORTED_NATIVE_PROVIDERS and map it as an OpenAI-compatible provider.
  2. In llm.py, strip the cache_breakpoint key from the message dictionary for all non-Anthropic models during message formatting (fixing issue #5886).

Describe alternatives you've considered

Using the LiteLLM fallback is an option, but native integration is cleaner, avoids dependency overhead, and natively manages the Groq endpoints. For the cache_breakpoint issue, there are no clean alternatives other than sanitizing the messages before sending them.

Additional context

I have already implemented and verified these changes locally. I've also written automated unit tests verifying the routing and fallback behavior, and they pass successfully. I'm ready to submit the PR!

llm-generated

Willingness to Contribute

Yes, I'd be happy to submit a pull request

Mahajan-Sachin avatar Jun 22 '26 18:06 Mahajan-Sachin

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jul 23 '26 12:07 github-actions[bot]

Reliability note (architecture only)

On: [Feature Request & Bug]: Add native Groq provider support and strip cache_breakpoint for non-Anthropic models

Production pattern that usually fixes this class of failure:

  1. Durable artifact id before success (run id / checkpoint version / tool receipt)
  2. Fail closed when the external write is missing — never silent green
  3. Idempotency on the business object for timeout+retry
  4. Policy before tool — refuse hops that would double-fire
  5. Progress + cancel on multi-minute agent work

A model is not an agent; a harness is. Architecture only — not selling anything.

IgorGanapolsky avatar Jul 23 '26 21:07 IgorGanapolsky

Hi! Commenting to keep this issue active.

I have submitted Pull Request #6287 which fully resolves this issue by adding native Groq support and stripping cache_breakpoint for non-Anthropic models. The PR is completely up-to-date with the latest main branch, verified with robust unit tests (including regression tests), and has been marked as "ready to merge" by CodeRabbit.

Would love to get a maintainer's review on #6287!

Mahajan-Sachin avatar Jul 24 '26 02:07 Mahajan-Sachin

Hi @IgorGanapolsky! Thanks for sharing these valuable reliability patterns.

@coderabbitai, what are your thoughts on these 5 production patterns for agentic reliability (durable artifact IDs, failing closed, idempotency keys, policy-before-tool, and cancellation) in the context of the current CrewAI framework architecture? How does the crew/agent executor currently address these, or where is there room for improvement?

Mahajan-Sachin avatar Jul 24 '26 02:07 Mahajan-Sachin

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Candidate execution/reliability modules =='
fd -t f -e py . | rg -i '(crew|agent|executor|task|tool|process|event|callback|cancel|checkpoint|memory|kickoff)'

printf '%s\n' '== Structural outline of likely runtime modules =='
for f in $(fd -t f -e py . | rg -i '(^|/)(crew|agent|executor|task|tool).*\.py$' | head -80); do
  ast-grep outline "$f" --items all --type class,function 2>/dev/null || true
done

printf '%s\n' '== Targeted reliability vocabulary in Python source =='
rg -n -i -C 3 \
  '(idempotenc|checkpoint|cancel(lation|led)?|interrupt|abort|timeout|retry|callback|task_id|run_id|execution_id|tool_result|cache|fail.*(closed|open)|exception)' \
  -g '*.py' \
  -g '!**/tests/**' \
  . | head -800

Length of output: 176720


🏁 Script executed:

#!/bin/bash
set -euo pipefail

files=(
  lib/crewai/src/crewai/crew.py
  lib/crewai/src/crewai/task.py
  lib/crewai/src/crewai/agents/crew_agent_executor.py
  lib/crewai/src/crewai/agents/step_executor.py
  lib/crewai/src/crewai/tools/tool_usage.py
  lib/crewai/src/crewai/tools/base_tool.py
  lib/crewai/src/crewai/state/runtime.py
  lib/crewai/src/crewai/state/checkpoint_listener.py
  lib/crewai/src/crewai/state/event_record.py
  lib/crewai/src/crewai/state/checkpoint_config.py
  lib/crewai/src/crewai/flow/persistence/base.py
  lib/crewai/src/crewai/flow/persistence/sqlite.py
  lib/crewai/src/crewai/hooks/tool_hooks.py
  lib/crewai/src/crewai/hooks/llm_hooks.py
  lib/crewai/src/crewai/events/types/tool_usage_events.py
  lib/crewai/src/crewai/events/types/task_events.py
  lib/crewai/src/crewai/events/types/crew_events.py
)

for f in "${files[@]}"; do
  if [[ -f "$f" ]]; then
    printf '\n== OUTLINE: %s ==\n' "$f"
    ast-grep outline "$f" --items all || true
  fi
done

printf '\n== EXECUTION AND DURABILITY IMPLEMENTATIONS ==\n'
for f in "${files[@]}"; do
  if [[ -f "$f" ]]; then
    printf '\n----- %s -----\n' "$f"
    rg -n -C 5 -i \
      '(def (kickoff|execute|execute_sync|execute_async|_execute|_run|resume|replay|cancel)|\
class .*(Runtime|Checkpoint|Persistence|ToolUsage)|\
(uuid|task_id|run_id|execution_id|checkpoint|persist|idempot|retry|timeout|\
cancel|interrupt|exception|raise|hook|before|after|cache))' "$f" || true
  fi
done

printf '\n== TARGETED TEST NAMES AND ASSERTIONS ==\n'
rg -n -C 3 -i \
  '(checkpoint|resum|cancel|interrupt|idempot|tool.*(hook|error|retry)|task.*(fail|error)|crew.*(fail|error))' \
  lib/crewai/tests/test_checkpoint.py \
  lib/crewai/tests/test_flow_persistence.py \
  lib/crewai/tests/test_flow_resumability_regression.py \
  lib/crewai/tests/hooks \
  lib/crewai/tests/tools/test_tool_usage.py \
  lib/crewai/tests/agents/test_agent_executor.py 2>/dev/null || true

Length of output: 183866


🏁 Script executed:

#!/bin/bash
set -euo pipefail

show() {
  local file="$1" start="$2" end="$3"
  printf '\n===== %s (lines %s-%s) =====\n' "$file" "$start" "$end"
  sed -n "${start},${end}p" "$file"
}

# Core execution and failure behavior
show lib/crewai/src/crewai/task.py 250 470
show lib/crewai/src/crewai/crew.py 640 900
show lib/crewai/src/crewai/crew.py 1100 1400
show lib/crewai/src/crewai/agents/crew_agent_executor.py 200 620

# Tool policy, error, and cache behavior
show lib/crewai/src/crewai/hooks/tool_hooks.py 130 205
show lib/crewai/src/crewai/tools/tool_usage.py 230 530
show lib/crewai/src/crewai/tools/base_tool.py 230 390
show lib/crewai/src/crewai/agents/cache/cache_handler.py 1 180

# Checkpoint triggers and error behavior
show lib/crewai/src/crewai/state/checkpoint_listener.py 105 270
show lib/crewai/src/crewai/state/checkpoint_config.py 130 230
show lib/crewai/src/crewai/state/runtime.py 290 460

printf '\n===== Cancellation / idempotency / receipt API search in core runtime =====\n'
rg -n -i -C 3 \
  '\b(cancel|cancelled|canceled|cancellation|abort|interrupt|idempotency|idempotent|receipt|transactional|compensat(e|ion)|outbox)\b' \
  lib/crewai/src/crewai \
  -g '*.py' \
  -g '!**/tests/**'

printf '\n===== Task and tool identity generation =====\n'
rg -n -C 4 \
  '(id: .*uuid|default_factory=uuid|uuid\.uuid4|set_current_task_id|_kickoff_event_id)' \
  lib/crewai/src/crewai/task.py \
  lib/crewai/src/crewai/crew.py \
  lib/crewai/src/crewai/context.py \
  lib/crewai/src/crewai/events/base_events.py

Length of output: 135694


@Mahajan-Sachin, these are excellent production patterns. The current framework has meaningful primitives for several of them, but they are not yet a single end-to-end reliability contract—especially around externally side-effecting tools.

Pattern Current CrewAI coverage Main gap / opportunity
1. Durable artifact IDs Crew, Task, and events have UUIDs. Tool events carry task/agent IDs, arguments, attempt count, timing, and cache status. Opt-in checkpoints support JSON/SQLite persistence, restore, lineage, and forks. Checkpointing captures CrewAI runtime state, not a transactional receipt for an external write. A tool that creates a payment, ticket, or deployment should persist the provider’s receipt/operation ID before the task is considered complete.
2. Fail closed Task failures emit TaskFailedEvent and re-raise; crew failures emit CrewKickoffFailedEvent and re-raise. Tool errors emit error events rather than a successful-finish event. Automatic checkpoint failures are currently logged and swallowed, so a configured checkpoint is not a completion gate. Also, hook exceptions are intentionally fail-open unless the hook explicitly returns False or raises HookAborted. For high-risk operations, users should make policy/persistence failures fail closed.
3. Idempotency There is an in-memory tool-result cache keyed by tool name and input, plus retry handling for tool execution/parsing and task guardrails. Cache ≠ idempotency: it is local, ephemeral, and does not protect against timeout-after-side-effect or process restart. A robust tool contract needs an idempotency key derived from a stable business operation ID, propagated to providers that support it, with durable lookup of prior receipts.
4. Policy before tool This is the strongest direct fit. Before-tool hooks receive tool name, input, task, agent, and crew context; they can mutate input or block execution via False/HookAborted. Human approval can also be implemented there. The policy layer is programmable rather than declarative, and a hook crash is fail-open by design. A future policy abstraction could offer tool risk classes, allow/deny rules, required approval, idempotency requirements, and fail-closed behavior for protected tools.
5. Progress + cancellation Lifecycle events provide progress signals for crew/task/tool start, finish, and failure. Streaming has cleanup/cancellation behavior. A2A tasks have explicit cancellation monitoring and status transitions. There does not appear to be a general Crew.cancel() / Task.cancel() contract with a cancellation token propagated through the executor and arbitrary tool calls. Canceling a coroutine also cannot reliably undo an external request already sent; tools need provider-specific cancel/compensation support.

A particularly important distinction is checkpoint/resume versus exactly-once effects. Crew checkpoints can resume task execution based on restored task outputs, which is valuable for workflow continuity. But if the process fails between “external system accepted the write” and “CrewAI checkpoint records completion,” replay may invoke the side-effecting tool again. The durable receipt + idempotency-key pattern closes that ambiguity.

A pragmatic direction would be:

  1. Introduce a per-tool-invocation operation ID correlated with crew/task/event IDs.
  2. Let tools return a structured result such as status, receipt_id, idempotency_key, is_reversible, and provider_operation_id.
  3. Add a durable side-effect ledger to checkpoint state.
  4. Require a successful persisted receipt before marking configured side-effecting tasks complete.
  5. Add executor-level cancellation tokens, with tools opting into cancellation and compensation semantics.

So: the framework is already well-positioned for observability, checkpointing, hooks, and A2A cancellation. The largest reliability improvement would be elevating those primitives into an explicit side-effect execution contract for tools.

coderabbitai[bot] avatar Jul 24 '26 02:07 coderabbitai[bot]

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 24 '26 12:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Aug 29 '26 12:08 github-actions[bot]