feat(providers): add ProviderCapabilities dataclass with unified capability detection#6233
feat(providers): add ProviderCapabilities dataclass with unified capability detection#6233tcconnally wants to merge 4 commits into
Conversation
|
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)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesProvider Capability Detection
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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/llm.py`:
- Line 2396: The early return that bails on missing LiteLLM introspection is
happening before the get_capabilities() method call on line 2396, which prevents
the fallback logic for response_format and reasoning_effort validation from
running. Move the early return statement to after the get_capabilities() call so
that the method's built-in fallback logic can execute before any conditional
exit occurs.
- Around line 2481-2485: The current logic unconditionally sets
supports_tool_calling to True when the provider is not in the
_PROVIDERS_WITHOUT_TOOL_CALLING blocklist, which discards valid False results
from supports_function_calling(). Replace the conditional logic that assigns
True on line 2485 with AND logic that checks both conditions: that the provider
is not in _PROVIDERS_WITHOUT_TOOL_CALLING AND that
self.supports_function_calling() returns True. This ensures the function's
negative results are respected instead of being overridden.
- Around line 2487-2488: The current code at line 2487-2488 uses only a
provider-level allowlist to determine reasoning support, which incorrectly
allows reasoning_effort for non-reasoning models under reasoning-capable
providers. Replace the static allowlist check for `supports_reasoning` with a
model-aware approach using `litellm.supports_reasoning(model,
custom_llm_provider=provider)` when available, and fall back to the static
`_PROVIDERS_WITH_REASONING` allowlist check only when that function is
unavailable or returns None. This ensures that reasoning_effort is only applied
to models that actually support reasoning, not just providers that support
reasoning for some of their models.
🪄 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: d127da02-d2a6-48dc-bd8a-73ba44d43884
📒 Files selected for processing (1)
lib/crewai/src/crewai/llm.py
…bility detection Adds a structured ProviderCapabilities dataclass that aggregates previously scattered capability checks (supports_response_schema, supports_function_calling, supports_stop_words) into a single object. - ProviderCapabilities: supports_response_format, supports_tool_calling, supports_reasoning, supports_streaming, supports_image_input, supports_stop_words - get_capabilities() method on LLM that uses litellm introspection with static-provider-allowlist fallbacks - Updated _validate_call_params() to use capabilities for clearer error messages including reasoning_effort validation - Static allowlists (_PROVIDERS_WITHOUT_RESPONSE_FORMAT, etc.) as fallback when litellm is unavailable Closes crewAIInc#6220
77cfb72 to
9ed6a84
Compare
Two CodeRabbit findings on get_capabilities()/_validate_call_params(): 1. _validate_call_params() bailed out whenever supports_response_schema was unavailable (`or supports_response_schema is None`), short-circuiting validation even when litellm itself is installed. get_capabilities() already carries a static-allowlist fallback for that case, so drop the extra guard and let it run (it gates introspection internally). 2. Reasoning detection was provider-level only (`provider in _PROVIDERS_WITH_REASONING`), which both false-positives non-reasoning models under reasoning-capable providers and false-negatives reasoning providers outside the static set. Make it model-aware via litellm.supports_reasoning(model, custom_llm_provider=provider), falling back to the static allowlist when introspection is unavailable or raises -- mirroring the existing response_format path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Marking this ready for review. Summary of the CodeRabbit review pass (commit 5398e54): Addressed (fixed):
Rebutted (kept as-is, with maintainer-visible rationale, CodeRabbit agreed and withdrew): Validated locally with |
Summary
Adds a structured
ProviderCapabilitiesdataclass that aggregates previously scattered capability checks into a single object, addressing #6220.Problem
CrewAI currently checks provider capabilities through separate methods (
supports_response_schema(),supports_function_calling(),supports_stop_words()) and hardcoded provider lists. This means:Solution
ProviderCapabilities dataclass
LLM.get_capabilities()
Uses litellm introspection when available, falling back to static provider allowlists:
Updated validation
_validate_call_params()now uses capabilities for bothresponse_formatandreasoning_effortvalidation with clearer error messages:Static fallback allowlists
When litellm is unavailable, three frozensets provide the fallback:
_PROVIDERS_WITHOUT_RESPONSE_FORMAT: deepseek, ollama, ollama_chat, hosted_vllm_PROVIDERS_WITHOUT_TOOL_CALLING: (empty — all modern providers support tools)_PROVIDERS_WITH_REASONING: openai, azure, anthropic, bedrock, cerebrasRelated
Summary by CodeRabbit
Bug Fixes
Chores