Install CrewAI: Your Guide to LLM Agent Orchestration

Learn how to install CrewAI, the lightweight Python framework for building LLM-powered multi-agent systems. Get started with your AI agent orchestration today!

Installing CrewAI

CrewAI is a lightweight Python framework designed for building and orchestrating collaborative multi-agent systems powered by large language models (LLMs). This guide will walk you through the installation process, ensuring you have the necessary components to get started.

1. System Requirements

Before installation, ensure your system meets the following requirements:

  • Python Version: 3.8 or higher
  • Operating System: Windows, macOS, or Linux
  • Internet Connection: Required for LLM API calls (e.g., to OpenAI)

2. Install CrewAI Core Library

You can install the core CrewAI framework using pip. This command will also install essential base dependencies such as pydantic, openai, and langchain.

pip install crewai

CrewAI integrates seamlessly with LangChain, a popular framework that simplifies interaction with LLMs and enables the creation of sophisticated toolchains.

pip install langchain

4. Install an LLM Backend

To leverage the power of LLMs within CrewAI, you'll need to install and configure an LLM backend. OpenAI's GPT models (like GPT-3.5 or GPT-4) are commonly used.

4.1. Install OpenAI Python SDK

pip install openai

4.2. Set Your OpenAI API Key

You need to set your OpenAI API key as an environment variable.

On Linux/macOS:

export OPENAI_API_KEY="your-api-key-here"

On Windows (Command Prompt):

set OPENAI_API_KEY="your-api-key-here"

On Windows (PowerShell):

$env:OPENAI_API_KEY="your-api-key-here"

Replace "your-api-key-here" with your actual OpenAI API key. It's highly recommended to use a secure method for managing your API keys, especially in production environments.

5. Optional: Install Tool Integrations

CrewAI agents can utilize various tools for enhanced functionality, such as web search, PDF processing, or code execution. Install the necessary packages for the tools your agents will employ.

To enable agents to perform web searches, install the google-search-results package (which provides SerpAPI integration).

pip install google-search-results

5.2. Example: Install Additional LangChain Tools

For other common tasks, you might need to install additional libraries:

pip install beautifulsoup4 faiss-cpu tiktoken

6. Verify Installation

You can confirm that CrewAI and its dependencies are installed correctly by importing them in a Python interactive session or script.

from crewai import Agent, Crew
from langchain.llms import OpenAI

# If no errors are raised, your installation is successful.
print("CrewAI and LangChain (OpenAI) imported successfully!")

7. First Example Run

To test your setup, run this minimal script to create and run a simple multi-agent workflow.

from crewai import Agent, Crew
from langchain.llms import OpenAI

# Initialize LLM
llm = OpenAI(model="gpt-4") # You can also use gpt-3.5-turbo

# Define agents
researcher = Agent(
    role="Senior Researcher",
    goal="Find and summarize recent AI trends",
    backstory="An AI research expert with a passion for staying ahead of the curve in artificial intelligence.",
    llm=llm,
    verbose=True,
    allow_delegation=True
)

writer = Agent(
    role="Content Writer",
    goal="Create a compelling blog post summarizing recent AI trends",
    backstory="A skilled tech writer with a knack for translating complex AI topics into engaging content for a broad audience.",
    llm=llm,
    verbose=True,
    allow_delegation=True
)

# Define the crew
crew = Crew(
    agents=[researcher, writer],
    tasks=[
        {
            "description": "Research and identify the top 3 emerging AI trends in the last 6 months.",
            "expected_output": "A concise summary of 3 key AI trends.",
            "agent": researcher
        },
        {
            "description": "Write a blog post based on the identified AI trends, targeting a general audience.",
            "expected_output": "A 500-word blog post on recent AI trends.",
            "agent": writer
        }
    ],
    verbose=2, # Setting verbose to 2 for more detailed output
    manager_llm=llm # Specify the manager LLM
)

# Kickoff the crew's work
print("## Starting Crew AI Workflow...")
result = crew.kickoff()

print("\n## Crew AI Workflow Finished!")
print("\nFinal Result:")
print(result)