skip to content

In CrewAI, how do you give one Agent a different LLM from the rest of the crew?

level: juniorimportance: should knowfreq 58%

answer

  1. It is an Agent field, not a crew one
  2. One argument on the constructor
  3. Accepts an object or a model string
  4. Provider-prefixed identifiers, LiteLLM style
  5. Unset means environment default, not inheritance

basics

~20 s

Pass the llm argument to that Agent's constructor — either a CrewAI LLM object such as LLM(model="openai/gpt-4o") or a plain model string. Agents that omit llm fall back to the environment-configured default model, so model choice is per-agent and opt-in.

solid answer

~40 s

Model selection in CrewAI is an **Agent-level** setting: `Agent(role=..., goal=..., backstory=..., llm=LLM(model="openai/gpt-4o", temperature=0.2))`. The `llm` argument accepts a `crewai.LLM` instance or a bare model string, and the model identifier uses LiteLLM-style `provider/model` naming, which is how you point one agent at OpenAI, another at Anthropic, and a third at a local Ollama model with a `base_url`. If you leave `llm` unset the agent uses the environment-configured default model rather than inheriting from a neighbouring agent, so "the crew is expensive" is usually a per-agent question. In practice you give the reasoning-heavy agent the strong model and leave the formatting or summarising agents on a cheap one. Related knobs live on the same object: `function_calling_llm` can route tool-call formatting to a different model, and `max_rpm` throttles that agent's request rate.

code

python · 17 lines
python
from crewai import Agent, LLM

strong = LLM(model="openai/gpt-4o", temperature=0.2)

researcher = Agent(
    role="Senior Research Analyst",
    goal="Find and verify primary sources on the topic",
    backstory="You have spent a decade checking claims against original documents.",
    llm=strong,
)

formatter = Agent(
    role="Report Formatter",
    goal="Turn a finished draft into a clean markdown report",
    backstory="You care only about structure and never rewrite the substance.",
    llm="openai/gpt-4o-mini",
)

go deeper

for a junior

Know that llm is an argument on the Agent constructor and accepts either a model string or an LLM object. Be able to write one agent with a strong model and another with a cheap one.

for a middle

Explain the resolution order: explicit llm, otherwise the environment-configured default — never inheritance from another agent. Mention the provider-prefixed model identifier and where credentials come from.

for a senior

Show that you allocate models by the work each agent does, and that you verify the resolved model rather than trusting the fallback. Bring up rate limits and context-window differences once agents run on different providers.

for a principal

Own the cost and risk tradeoff: which steps justify a frontier model, which must stay on self-hosted infrastructure for data reasons, and how you keep that policy from drifting as agents are added.

## What the llm field actually sets A CrewAI `Agent` carries its own model handle. The `llm` argument is not a hint or a default that a crew can override at run time — it is the client that agent will use for every reasoning step, every tool-call decision and its final answer. Two agents in the same crew can therefore run on completely different providers, and that is a deliberate design point of the framework: role specialization is cheap only if model cost can be specialized with it. ## The two ways to pass it The simplest form is a string: `Agent(role="Writer", goal="...", backstory="...", llm="openai/gpt-4o-mini")` CrewAI converts that into an `LLM` object internally. The explicit form gives you the tuning knobs: `from crewai import LLM` `llm = LLM(model="anthropic/claude-sonnet-4-5", temperature=0.2)` `LLM` accepts the usual generation parameters (`temperature`, `max_tokens`, `top_p`) plus transport parameters (`api_key`, `base_url`). Model identifiers follow the LiteLLM `provider/model` convention, which is why a bare `gpt-4o` and an explicit `openai/gpt-4o` both work for OpenAI but a self-hosted model needs the provider prefix plus a `base_url`. ## What happens when you omit it An agent without `llm` does **not** inherit the model of another agent and does not inherit anything from the task it is given. It falls back to the environment-configured default (the `OPENAI_MODEL_NAME` environment variable, with a framework default when that is unset). This is the single most common surprise in a first CrewAI project: someone sets a strong model on one agent, sees the bill, and assumes the crew is running that model everywhere — in fact the other agents are running whatever the environment says. ## Why per-agent selection is the point A crew is a pipeline of unequal work. A research agent that has to decide which of six tools to call, read long tool output and plan the next step needs a model that is good at tool selection and long context. A formatting agent that turns a finished draft into a bullet list does not. Because the model is attached to the agent rather than to the crew, the cheap-model/strong-model split is a one-line change per agent instead of a rewrite. The same mechanism lets you keep a data-sensitive step on a locally hosted model while the rest of the crew calls a hosted API. ## Neighbouring knobs on the same object - `function_calling_llm` lets an agent use a different, usually cheaper or more reliably structured, model purely for producing tool-call payloads while the main `llm` does the reasoning. - `max_rpm` bounds how many requests per minute that agent may issue, which matters when one agent sits on a rate-limited provider and the rest do not. - `respect_context_window` (on by default) keeps the agent's message history inside the model's context window instead of letting a request fail outright — relevant because different agents may now have very different context sizes. ## Failure modes to expect The first is a missing or wrong provider prefix: a model string the provider does not recognise fails at the first LLM call, not at construction time, so the error surfaces mid-run. The second is credentials — each provider reads its own environment variable, so mixing providers in one crew means the process needs every one of those keys present. The third is silent cost: because the fallback is an environment default rather than an error, an agent with a typo'd or forgotten `llm` still runs, just not on the model you intended. Logging the resolved model per agent at startup, or asserting it in a test, is a cheap guard. ## How to talk about it in an interview Say plainly that the model is a property of the agent, name the two accepted forms, mention the provider-prefixed identifier, and then move to judgment: which agents in a crew deserve the expensive model and why. That last part is what separates a recited constructor signature from an answer that shows you have run a crew and looked at the bill.

  • What does function_calling_llm change compared with the agent's main llm?
    `function_calling_llm` is used specifically for producing tool-call payloads, while `llm` still does the reasoning and writes the final answer. It is useful when your reasoning model is strong but inconsistent at emitting well-formed arguments, or when you want the frequent, short tool-call turns to run on a cheaper model. If you leave it unset, the main `llm` handles tool calls too.
  • How would you point one agent at a locally hosted model while the rest call a hosted API?
    Construct an `LLM` for that agent with a provider-prefixed model name and an explicit `base_url` pointing at the local server, for example an Ollama endpoint, and pass it as that agent's `llm`. Nothing else in the crew changes, because the model handle lives on the agent. Expect to tune that agent's expectations down: a small local model is usually worse at multi-tool selection.
  • An agent you never gave an llm to is running on a model you did not choose — why?
    Because omitting `llm` does not inherit from a sibling agent; it resolves to the environment-configured default model. Set `llm` explicitly on every agent you care about, or log the resolved model per agent at startup so the fallback cannot go unnoticed.

saying these in an interview costs you the question

  • Thinks the crew sets one model for all agents
  • Believes an agent inherits the previous agent's model
  • Assumes omitting llm raises an error at construction
  • Thinks the model must be identical across a crew
  • Confuses temperature settings with model selection

context