How to change LLM in crewai 0.76.2 whilst using create crew

@ahmadsm1

  1. Use the CrewAI LLM class, which leverages LiteLLM in the background.
  2. Make sure to set the LLM provider before configuring the LLM. For Anthropic, use anthropic/<LLM name>. If you’re unsure how to do this for a specific LLM provider, refer to the LiteLLM Providers page for guidance.

Also, see the docs.

from crewai import Agent, LLM

my_llm = LLM(
    api_key=os.getenv("ANTHROPIC_API_KEY"),
    model="anthropic/claude-3-5-sonnet-20240620",
),

my_agent = Agent(
    ...,
    llm=my_llm,
)
3 Likes