CrewAI Tutorial: Building Multi-Agent AI Framework

# CrewAI - Framework AI Multi-Agen ## Daftar Isi 1. [Pendahuluan](#pendahuluan) 2. [Prasyarat](#prasyarat) 3. [Instalasi dan Pengaturan](#instalasi-dan-pengaturan) 4. [Konsep Dasar](#konsep-dasar) 5...

By Ruby Abdullah · · tutorial
CrewAIMulti-AgentAI AgentLLMAutomationPython

CrewAI - Multi-Agent AI Framework

Table of Contents

  • Introduction
  • Prerequisites
  • Installation and Setup
  • Core Concepts
  • Creating Agents
  • Defining Tasks
  • Crew Orchestration
  • Tool Integration
  • Sequential vs Parallel Execution
  • Memory and Context Management
  • Delegation Between Agents
  • Real-World Use Case: Research Agent Team
  • Real-World Use Case: Coding Agent Team
  • Best Practices
  • Conclusion

  • Introduction

    CrewAI is a cutting-edge framework for orchestrating autonomous AI agents that work together as a collaborative team. Inspired by real-world crew dynamics, it enables developers to create sophisticated multi-agent systems where each agent has a specific role, expertise, and set of tools.

    Key features of CrewAI:

    • Role-based agents: Define agents with specific roles, goals, and backstories
    • Task management: Create structured tasks with expected outputs and dependencies
    • Flexible orchestration: Sequential, parallel, and hierarchical execution modes
    • Tool ecosystem: Rich set of built-in tools plus custom tool creation
    • Memory systems: Short-term, long-term, and entity memory for context persistence
    • Delegation: Agents can delegate tasks to other agents when appropriate

    Multi-agent systems outperform single-agent approaches for complex tasks because they allow specialization, parallel processing, and collaborative problem-solving — much like a human team.

    In this tutorial, you will learn how to create agents, define tasks, orchestrate crews, integrate tools, and build real-world multi-agent applications.


    Prerequisites

    • Python 3.10 or higher
    • An OpenAI API key (or other supported LLM provider)
    • Basic understanding of Large Language Models (LLMs)
    • Familiarity with Python async patterns (for parallel execution)


    Installation and Setup

    # Install CrewAI with all tools
    

    pip install crewai[tools]

    Or minimal installation

    pip install crewai

    Set up environment variables

    export OPENAIAPIKEY="your-openai-api-key"

    Optional: for other LLM providers

    export ANTHROPICAPIKEY="your-anthropic-key"

    Verify the installation:

    import crewai
    

    print(f"CrewAI version: {crewai.version}")

    from crewai import Agent, Task, Crew

    print("All core components imported successfully")


    Core Concepts

    CrewAI is built around three core abstractions:

  • Agent: An autonomous entity with a role, goal, backstory, and tools
  • Task: A specific piece of work with a description, expected output, and assigned agent
  • Crew: An orchestrator that manages agents and coordinates task execution
  • from crewai import Agent, Task, Crew, Process
    
    

    The simplest possible crew

    agent = Agent(

    role="Greeting Agent",

    goal="Greet the user warmly",

    backstory="You are a friendly agent that welcomes users.",

    verbose=True,

    )

    task = Task(

    description="Greet the user and wish them a productive day.",

    expectedoutput="A warm, personalized greeting message.",

    agent=agent,

    )

    crew = Crew(

    agents=[agent],

    tasks=[task],

    process=Process.sequential,

    verbose=True,

    )

    result = crew.kickoff()

    print(result)


    Creating Agents

    Agents are the core workers in CrewAI. Each agent should have a clearly defined role and area of expertise.

    from crewai import Agent
    

    from crewaitools import SerperDevTool, WebsiteSearchTool

    Research analyst agent

    researchanalyst = Agent(

    role="Senior Research Analyst",

    Related Articles

    AutoGen: Microsoft's Multi-Agent Conversation Framework

    AutoGen: Framework Multi-Agent Conversation dari Microsoft AutoGen adalah framework open-source dari Microsoft Research ...

    Phidata (Agno) Tutorial: Build Powerful AI Agents with a Simple Framework

    Tutorial Phidata (Agno): Framework AI Agent yang Simpel dan Powerful Membangun AI agent yang cerdas dan otonom kini sema...

    Complete LangGraph Tutorial: Building Complex AI Agents

    Tutorial Lengkap LangGraph: Membangun AI Agents yang Kompleks LangGraph adalah library dari LangChain untuk membangun st...

    TRL Tutorial: LLM Post-Training with SFT, DPO, and Reward Modeling

    Post-Training LLM dengan TRL: SFT, Reward Modeling, dan DPO Setelah sebuah base language model selesai dipretraining, mo...