Skip to content

fix: preserve provider on LiteLLM-routed models - #6849

Merged
lucasgomide merged 5 commits into
mainfrom
luzk/fix-llm-provider
Aug 7, 2026
Merged

fix: preserve provider on LiteLLM-routed models#6849
lucasgomide merged 5 commits into
mainfrom
luzk/fix-llm-provider

Conversation

@lucasgomide

@lucasgomide lucasgomide commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

LiteLLM-routed models kept LLM.provider stuck on the openai default because construction never passed the computed provider into init. Downstream consumers, including the model-provider allowlist, therefore treated groq, cohere, mistral, and similar calls as openai. BaseLLM now infers the provider from a provider/model prefix when none is supplied.


Note

Medium Risk
Changes default provider inference and multimodal/instructor wiring for all LiteLLM-backed models; incorrect behavior could mis-route allowlists or break vision/file payloads, though scope is narrow and well covered by new tests.

Overview
LiteLLM-routed models (groq/…, cohere/…, etc.) no longer default provider to openai when it is omitted at construction. BaseLLM now sets provider from the model’s prefix/model string via _extract_provider, so allowlists and other consumers see the real vendor while routing still goes through LiteLLM.

Multimodal file handling is split from provider identity: sync/async message file processing uses _multimodal_formatter_name() instead of self.provider. On the LLM LiteLLM path, provider stays (e.g. anthropic) but formatting uses the openai content-block schema LiteLLM expects on the wire.

InternalInstructor builds the instructor model id without double-prefixing when the model string is already qualified (e.g. groq/llama-3.3-70b).

Tests cover prefix → provider on LiteLLM, multimodal formatter behavior, and instructor qualification.

Reviewed by Cursor Bugbot for commit 948b22b. Bugbot is set up for automated code reviews on this repo. Configure here.

LiteLLM construction computed the real provider in `__new__` but never
passed it into init, so `BaseLLM` silently defaulted every shared-path
model to `openai`. Infer the provider from a `provider/model` prefix
when none is supplied so groq, cohere, mistral, and the rest report
themselves correctly to callers like the policy engine.
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change extracts providers from prefixed model identifiers for LiteLLM routing and prevents duplicate prefixes when creating Instructor clients. Tests cover OpenAI, Anthropic, Groq, Together, and Groq-qualified models.

Changes

Provider routing

Layer / File(s) Summary
Provider extraction and fallback validation
lib/crewai/src/crewai/llms/base_llm.py, lib/crewai/tests/test_llm.py
BaseLLM extracts the provider from string model identifiers. Non-string models retain the "openai" fallback. Tests verify provider and model preservation across LiteLLM fallback cases.
Instructor qualified model handling
lib/crewai/src/crewai/utilities/internal_instructor.py, lib/crewai/tests/utilities/test_converter.py
InternalInstructor preserves an existing provider-qualified model and prepends the provider only when it is absent. Tests cover groq/llama-3.3-70b forwarding.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: preserving provider identity for LiteLLM-routed models.
Description check ✅ Passed The description directly explains provider inference, instructor qualification, multimodal handling, and related test coverage.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch luzk/fix-llm-provider

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.

@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/llms/base_llm.py`:
- Around line 277-280: Make provider qualification idempotent across BaseLLM and
the downstream object path: preserve the original qualified model while setting
provider, and ensure the internal instructor path does not prepend provider when
self.llm.model already starts with it. Update the LiteLLM routing flow
accordingly and add a regression test covering a model such as
groq/llama-3.3-70b to verify it is passed only once.
🪄 Autofix

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: 1d754196-b76d-4390-9e6d-c19b0d4457eb

📥 Commits

Reviewing files that changed from the base of the PR and between 18c52c4 and 5a2b3c2.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/llms/base_llm.py
  • lib/crewai/tests/test_llm.py

Comment thread lib/crewai/src/crewai/llms/base_llm.py
With LiteLLM models now carrying a real `provider` while `model` keeps
its `provider/name` form, `InternalInstructor` was building
`groq/groq/...` for `instructor.from_provider`. Skip the prefix when
the model string is already qualified.
@crewAIInc crewAIInc deleted a comment from linear Bot Aug 6, 2026
@github-actions github-actions Bot added the size/S label Aug 7, 2026
@lucasgomide
lucasgomide force-pushed the luzk/fix-llm-provider branch from 16d6353 to f9b51fe Compare August 7, 2026 13:32

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e655682. Configure here.

Comment thread lib/crewai/tests/llms/test_multimodal_integration.py Outdated
Preserving the real provider on the LiteLLM path made
`format_multimodal_content` emit Anthropic-native blocks for
`anthropic/...` models, which LiteLLM rejects. Keep `provider` as the
model identity for policies, but format multimodal blocks with the
OpenAI chat schema when `is_litellm` is set. Expose the formatter helper
on `BaseLLM` so native OpenAI/Azure completions share the same API.
@lucasgomide
lucasgomide force-pushed the luzk/fix-llm-provider branch from 43f14ab to 948b22b Compare August 7, 2026 14:31
@lucasgomide
lucasgomide merged commit e264e05 into main Aug 7, 2026
58 checks passed
@lucasgomide
lucasgomide deleted the luzk/fix-llm-provider branch August 7, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants