Run This Ai
EN DE

Getting Started with Camel-AI: Build Your First Multi-Agent System

A hands-on tutorial to build your first multi-agent system with Camel-AI. Create a Task Planner and Code Executor in under 20 lines of Python.

Camel-AI Banner

Introduction

Camel-AI makes it remarkably simple to create multi-agent systems. In this tutorial, you will build a two-agent system where a Task Planner and a Code Executor collaborate to write and test a Python script — completely autonomously. You will see firsthand how role-playing agents divide work, communicate, and deliver results.

Prerequisites

Before starting, ensure you have:

  • Python 3.9+ installed
  • An OpenAI API key (or Anthropic/Gemini)
  • Basic familiarity with Python

Step 1: Install Camel-AI

pip install camel-ai

This installs the core library along with all dependencies for agent communication, memory, and tool use.

Step 2: Set Your API Key

export OPENAI_API_KEY="sk-..."

Step 3: Create Your First Multi-Agent System

Create a file called multi_agent_demo.py:

from camel.agents import ChatAgent
from camel.messages import BaseMessage
from camel.types import RoleType

# Create two agents with distinct roles
planner = ChatAgent(
    system_message=BaseMessage(
        role_name="Task Planner",
        role_type=RoleType.ASSISTANT,
        content="You are a meticulous task planner. Break down coding tasks into clear, sequential steps.",
    ),
)

coder = ChatAgent(
    system_message=BaseMessage(
        role_name="Python Coder",
        role_type=RoleType.ASSISTANT,
        content="You are an expert Python developer. Write clean, well-documented code.",
    ),
)

# Planner assigns a task
task = "Write a Python function that calculates Fibonacci numbers using dynamic programming."
planner_msg = BaseMessage(
    role_name="User",
    role_type=RoleType.USER,
    content=task,
)
response = planner.step(planner_msg)
print(f"Planner: {response.msg.content}")

# Coder executes
coder_msg = BaseMessage(
    role_name="User",
    role_type=RoleType.USER,
    content=f"Implement this plan:\n{response.msg.content}",
)
code_response = coder.step(coder_msg)
print(f"Coder: {code_response.msg.content}")

Step 4: Run It

python multi_agent_demo.py

You will see the Planner break down the task into steps, and the Coder produce the actual implementation. This simple pattern scales to dozens of agents with specialized roles.

Camel-AI GitHub Repository

Exploring Further

Camel-AI supports much more than two-agent chats:

  • Role-Playing Societies: Create any number of agents with custom personas
  • Task-Oriented Loops: Agents can iterate on tasks with feedback loops
  • Data Generation: Use built-in pipelines for synthetic data creation
  • Tool Integration: Give agents access to external APIs and tools

Conclusion

In just a few lines of Python, you built a functioning multi-agent system. Camel-AI abstracts away the complexity of inter-agent communication, letting you focus on what matters: designing agent behaviors that solve real problems. Check out the official documentation for advanced topics like memory, tool use, and multi-turn conversations.