Choosing and configuring LLMs

CrewAI · Essentials · 10 min

Model choice drives quality, speed and cost, and different agents often need different models.

Every agent talks to an LLM. CrewAI names models as `provider/model-id`, for example openai/gpt-4o-mini or anthropic/claude-sonnet-4-6. The provider prefix is required. Model names change often, so check your provider's current list.

There are three places to choose a model:

  • The MODEL environment variable (often in .env) sets the default for agents that don't specify one.
  • A string on the agent: Agent(..., llm="anthropic/claude-sonnet-4-6").
  • An LLM object, when you need settings:
from crewai import LLM
llm = LLM(model="openai/gpt-4o-mini", temperature=0.2, max_tokens=800)

Common LLM parameters: temperature, max_tokens, timeout, api_key, base_url (a different server address) and stream.

OpenAI, Anthropic, Google Gemini, Azure, AWS Bedrock and a few others have native integrations, installed with extras like crewai[anthropic]. Everything else goes through LiteLLM, installed with crewai[litellm].

To run models on your own computer, use Ollama, a free app that serves open models locally: LLM(model="ollama/llama3.2", base_url="http://localhost:11434"). Local models are private and free per call, but smaller ones follow complex agent instructions and tool formats less reliably.

A practical pattern is mixing models: a strong model for planning or final writing, a cheaper, faster one for simple extraction steps. Some reasoning models reject temperature; if a call fails with a parameter error, remove it.

Example

from crewai import LLM, Agent

fast = LLM(model="openai/gpt-4o-mini", temperature=0.2)          # needs OPENAI_API_KEY
strong = LLM(model="anthropic/claude-sonnet-4-6", max_tokens=2000) # needs crewai[anthropic]
local = LLM(model="ollama/llama3.2", base_url="http://localhost:11434")  # crewai[litellm]

extractor = Agent(role="Data extractor", goal="Pull fields from text accurately",
                  backstory="You never guess missing values.", llm=fast)
editor = Agent(role="Editor", goal="Polish the final report",
               backstory="You edit for clarity and accuracy.", llm=strong)
offline = Agent(role="Note taker", goal="Summarize private notes",
                backstory="You work fully offline.", llm=local)

print(fast.model)   # gpt-4o-mini

Remember

  • Models are named provider/model-id; the prefix is required
  • Set a default with MODEL, override per agent with a string or LLM(...)
  • Native providers via extras; others via crewai[litellm]; local via Ollama

Watch out for

  • Writing just "gpt-4o" without the provider prefix, which CrewAI cannot route.

Check yourself

  1. Which agent setting would run a model on your own machine through Ollama?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.crewai.com/en/concepts/llms