fix(llm): detect Anthropic models with custom deployment naming#6190
fix(llm): detect Anthropic models with custom deployment naming#6190HumphreySun98 wants to merge 2 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 (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesProvider Pattern Matching Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 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/llm.py`:
- Around line 510-516: The provider detection logic at the diff location has
been expanded to check for `model_lower.startswith("anthropic")`, but the
`_is_anthropic_model` method does not include this same pattern matching logic.
Update the `_is_anthropic_model` method to mirror the expanded Anthropic
matching rule by adding a check for `model_lower.startswith("anthropic")`
alongside the existing pattern checks. This will ensure that both the provider
inference and the `is_anthropic` attribute remain consistent, allowing
Anthropic-specific message formatting in `_format_messages_for_provider` to be
properly applied.
🪄 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: d9473017-151b-42bc-97ed-06b1a168b440
📒 Files selected for processing (2)
lib/crewai/src/crewai/llm.pylib/crewai/tests/test_llm.py
Provider detection only recognized the canonical "claude-" / "anthropic." prefixes, so self-deployed Anthropic models named e.g. "anthropic--claude-..." were silently routed to the OpenAI adapter (and unprefixed ids defaulted to OpenAI outright), losing all Anthropic-specific request handling. Broaden the Anthropic pattern in _matches_provider_pattern to match "claude" anywhere or an "anthropic" prefix, and let _infer_provider_from_model fall back to the Anthropic/Gemini patterns before defaulting to OpenAI. "anthropic" is matched via startswith so lookalikes like "anthropomorphic" are unaffected; broad patterns such as bedrock's bare "." match are intentionally excluded. Fixes crewAIInc#5893 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…atcher Keep Anthropic detection consistent between the litellm `is_anthropic` flag and native-provider routing by having `_is_anthropic_model` delegate to `_matches_provider_pattern(model, "anthropic")`, so custom deployment names like `anthropic--claude-...` are recognized on both paths. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bac3e20 to
1c1d854
Compare
Problem
Provider detection only recognized the canonical
claude-/anthropic.prefixes. A self-deployed Anthropic model named e.g.anthropic--claude-3-5-sonnetwas therefore:_infer_provider_from_model, which defaulted unknown unprefixed ids to OpenAI, and_matches_provider_pattern,so it was routed to the OpenAI adapter, losing all Anthropic-specific request handling (stop-sequence normalization, thinking blocks, prompt caching, etc.).
Fix
_matches_provider_patternto matchclaudeanywhere or ananthropicprefix._infer_provider_from_modelfall back to the Anthropic/Gemini patterns before defaulting to OpenAI.anthropicis matched viastartswith, so lookalikes likeanthropomorphicare unaffected; broad patterns such as bedrock's bare.match are intentionally excluded to avoid false positives.Tests
Extended
test_validate_model_in_constantsand addedtest_infer_provider_from_model_custom_namingintest_llm.py, including no-regression and no-false-positive cases. Verified failing-without/passing-with the fix; the 20 existing model-routing tests still pass;ruffandmypyclean.Fixes #5893
This PR was authored with Claude Code. Per
CONTRIBUTING.md, AI-generated contributions require thellm-generatedlabel — I don't have triage permission to set it, so could a maintainer please add it? 🤖 Generated with Claude CodeSummary by CodeRabbit
Release Notes
Bug Fixes
Tests