CAMEL AI Framework

Deep-dive source code analysis โ€” v0.2.91a4 ยท 502 Python modules ยท 155K LOC

Framework Overview

CAMEL (Communicative Agents for "Mind" Exploration of Large Language Model Society) is one of the earliest and most comprehensive multi-agent frameworks. Originating from the "AI Society" research paper (2023), it has evolved into a full-stack agent framework covering:

The framework is Apache-2.0 licensed, requires Python 3.10+, and is structured as a single monorepo package camel-ai.

By the Numbers

502
Python modules
155K
Lines of code
80+
Toolkits
40+
LLM backends
6444
ChatAgent LOC
6239
Workforce LOC
14
Agent types
3
Memory types

System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ CAMEL Framework โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ Societies โ”‚ Agents โ”‚ Toolkits โ”‚ Models โ”‚ โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ โ”‚ RolePlaying โ”‚ ChatAgent โ”‚ 80+ toolkits โ”‚ 40+ backends โ”‚ โ”‚ Workforce โ”‚ CriticAgent โ”‚ FunctionTool โ”‚ ModelFactory โ”‚ โ”‚ BabyAGI โ”‚ SearchAgent โ”‚ BaseToolkit โ”‚ ModelManager โ”‚ โ”‚ โ”‚ MCPAgent โ”‚ MCPToolkit โ”‚ BaseModelBackend โ”‚ โ”‚ โ”‚ EmbodiedAgentโ”‚ Registered... โ”‚ โ”‚ โ”‚ โ”‚ RepoAgent โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ Memory โ”‚ Messages โ”‚ Prompts โ”‚ Runtimes โ”‚ Environments โ”‚ Tasks โ”‚ โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ โ”‚ ChatHst โ”‚ BaseMsg โ”‚ TextPrmptโ”‚ Docker โ”‚ SingleStep โ”‚ Task โ”‚ โ”‚ VecDB โ”‚ FuncMsg โ”‚ CodePrmptโ”‚ Daytona โ”‚ MultiStep โ”‚ TaskPrmโ”‚ โ”‚ Longtrm โ”‚ ShareGPT โ”‚ PromptTmplโ”‚ HTTP โ”‚ RLCards โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The architecture follows a layered design: Models at the bottom, Agents in the middle, Societies at the top. Toolkits, Memory, and Runtimes are cross-cutting concerns that agents compose.

Agent Hierarchy

BaseAgent (ABC) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ reset() โ”‚ โ”‚ step() โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ ChatAgent โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ The 6400-line core โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ€ข memory โ”‚ โ”‚ โ€ข model_backend โ”‚ โ”‚ โ€ข _internal_tools โ”‚ โ”‚ โ€ข step() / astep() โ”‚ โ”‚ โ€ข summarize() โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ CriticAgent EmbodiedAgent SearchAgent โ”‚ โ”‚ โ”‚ TaskSpecify MCPAgent KnowledgeGraph TaskPlanner RepoAgent RoleAssignment TaskCreation DeductiveReasoner TaskPrioritization MultiHopGenerator โ”‚ BaseToolAgent โ”‚ HuggingFaceToolAgent

Agent Types

AgentPurposeKey Feature
ChatAgentGeneral-purpose conversationTool use, memory, streaming, summarization
CriticAgentEvaluate & select proposalsMultiple critic strategies
EmbodiedAgentPhysical world interactionAction space, code execution
SearchAgentInformation retrievalSearch tool integration
MCPAgentMCP protocol agentModel Context Protocol
RepoAgentRepository analysisCode understanding
KnowledgeGraphAgentKG operationsGraph-based reasoning
TaskSpecifyAgentMake tasks specificCreative task expansion
TaskPlannerAgentPlan task decompositionSequential planning
RoleAssignmentAgentAssign roles to agentsDynamic role allocation
DeductiveReasonerAgentStep-by-step reasoningChain-of-thought

ChatAgent โ€” The Core

ChatAgent is the beating heart of CAMEL at 6444 lines. It handles the complete agent lifecycle:

ChatAgent.__init__() โ”‚ โ”œโ”€โ”€ model โ†’ ModelManager (round-robin or custom scheduling) โ”‚ โ””โ”€โ”€ resolves: BaseModelBackend | ModelType | (Platform, Type) | List[...] โ”‚ โ”œโ”€โ”€ memory โ†’ AgentMemory (default: ChatHistoryMemory) โ”‚ โ””โ”€โ”€ ScoreBasedContextCreator(token_counter, token_limit) โ”‚ โ”œโ”€โ”€ tools โ†’ Dict[str, FunctionTool] (_internal_tools) โ”‚ โ”œโ”€โ”€ external_tools โ†’ Dict[str, schema] (returns ToolCallRequest) โ”‚ โ”œโ”€โ”€ response_terminators โ†’ List[ResponseTerminator] โ”‚ โ””โ”€โ”€ summarize_threshold โ†’ auto-compress context when exceeded

Step Execution Flow

step(input_message) โ”‚ โ”œโ”€ 1. Update memory with user message โ”œโ”€ 2. _get_context_with_summarization() โ”‚ โ””โ”€ If tokens > threshold โ†’ summarize old messages โ”‚ โ””โ”€ Progressive or full compression โ”œโ”€ 3. Call model_backend.run(messages, tools) โ”‚ โ””โ”€ Retry on RateLimitError (exponential backoff) โ”œโ”€ 4. Parse response: โ”‚ โ”œโ”€ Text response โ†’ return ChatAgentResponse โ”‚ โ””โ”€ Tool call โ†’ execute tool โ†’ loop back to step 3 โ”‚ โ”œโ”€ _internal_tools: auto-execute โ”‚ โ””โ”€ _external_tools: return ToolCallRequest โ”œโ”€ 5. Check response_terminators โ”œโ”€ 6. Update token cache from usage โ””โ”€ 7. Return ChatAgentResponse(msgs, terminated, info)

Key Design Decisions in ChatAgent

๐Ÿ”„ Auto-Summarization

When context exceeds summarize_threshold % of token limit, old messages are compressed into a [CONTEXT_SUMMARY]. Progressive compression appends new summaries; full compression replaces all. Last user message is preserved with a prefix linking to the summary.

๐Ÿ›ก๏ธ Tool Output Masking

mask_tool_output=True returns a sanitized placeholder instead of raw tool output. Snapshot content from browser tools can be cleaned to remove verbose DOM markers via enable_snapshot_clean.

๐Ÿ“Š Token Count Caching

ScoreBasedContextCreator caches token counts from LLM responses and uses character-based approximation (~2 chars/token) for new messages to avoid expensive re-counting.

โšก Streaming

Both sync and async streaming are supported. StreamContentAccumulator manages content across streaming chunks. StreamingChatAgentResponse wraps generators to be compatible with non-streaming code.

ChatAgent Constructor Signature (Key Params)

class ChatAgent(BaseAgent):
    def __init__(
        self,
        system_message: Optional[Union[BaseMessage, str]] = None,
        model: Optional[Union[BaseModelBackend, ModelManager, ...]] = None,
        memory: Optional[AgentMemory] = None,
        message_window_size: Optional[int] = None,
        summarize_threshold: Optional[int] = 50,  # % of token limit
        token_limit: Optional[int] = None,
        output_language: Optional[str] = None,
        tools: Optional[List[Union[FunctionTool, Callable]]] = None,
        external_tools: Optional[List[...]] = None,
        response_terminators: Optional[List[ResponseTerminator]] = None,
        max_iteration: Optional[int] = None,
        tool_execution_timeout: Optional[float] = 10,
        mask_tool_output: bool = False,
        prune_tool_calls_from_memory: bool = False,
        retry_attempts: int = 3,
        retry_delay: float = 1.0,
        step_timeout: Optional[float] = 10,
        stream_accumulate: Optional[bool] = None,
        summary_window_ratio: float = 0.6,
    )

Societies & Orchestration

RolePlaying

The original CAMEL pattern: two agents (assistant + user) converse in character to solve a task. A CriticAgent or Human can be added to the loop.

class RolePlaying:
    def __init__(
        self,
        assistant_role_name: str,
        user_role_name: str,
        critic_role_name: str = "critic",
        task_prompt: str = "",
        with_task_specify: bool = True,
        with_task_planner: bool = False,
        with_critic_in_the_loop: bool = False,
        task_type: TaskType = TaskType.AI_SOCIETY,
        ...
    )
RolePlaying โ”‚ โ”œโ”€โ”€ TaskSpecifyAgent โ†’ Make task more specific โ”œโ”€โ”€ TaskPlannerAgent โ†’ Decompose into subtasks โ”œโ”€โ”€ assistant (ChatAgent) โŸท user (ChatAgent) โ”‚ โ””โ”€โ”€ Alternate turns via step() โ””โ”€โ”€ critic (CriticAgent | Human) โ””โ”€โ”€ Evaluate proposals, provide feedback

Workforce โ€” Hierarchical Multi-Agent

A 6239-line orchestrator for distributed task execution. Workers form a tree structure with a coordinator at the root.

Workforce (Coordinator) โ”Œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ Worker Worker Worker Worker SingleAg SingleAg RolePlay Workforce โ”‚ โ”‚ โ”‚ ChatAgent 2 agents Sub-tree...

Workforce manages task assignment, decomposition, and worker lifecycle. Key features:

Memory System

MemoryBlock (ABC) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ write_recordsโ”‚ โ”‚ clear() โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ AgentMemory (ABC) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ retrieve() โ”‚ โ”‚ get_context() โ”‚ โ”‚ get_context_creator() โ”‚ โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ChatHistory โ”‚ โ”‚VectorDB โ”‚ โ”‚LongtermAgent โ”‚ โ”‚Memory โ”‚ โ”‚Memory โ”‚ โ”‚Memory โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ ChatHstBlk โ”‚ โ”‚ VecDBBlock โ”‚ โ”‚ ChatHst + VecDB โ”‚ โ”‚ window_sizeโ”‚ โ”‚ topic track โ”‚ โ”‚ hybrid retrieve โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Memory Block Types

ChatHistoryBlock

Stores messages sequentially in BaseKeyValueStorage (default: in-memory). Supports window_size for sliding window retrieval. Can pop_records and remove_records_by_indices.

VectorDBBlock

Embeds messages and stores in BaseVectorStorage (default: Qdrant). Retrieves semantically similar messages by topic. Tracks current topic from last user message.

LongtermAgentMemory โ€” Hybrid

Combines both blocks. On retrieve():

def retrieve(self) -> List[ContextRecord]:
    chat_history = self.chat_history_block.retrieve()
    vector_db = self.vector_db_block.retrieve(
        self._current_topic, self.retrieve_limit,
    )
    # Insert relevant history BETWEEN system msg and recent msgs
    return chat_history[:1] + vector_db + chat_history[1:]

Context Creation Strategy

ScoreBasedContextCreator orders records chronologically and uses token counting with caching:

Messages & Prompts

BaseMessage

A @dataclass that serves as the universal message type. Not a Pydantic model โ€” it's a plain dataclass for performance.

@dataclass
class BaseMessage:
    role_name: str
    role_type: RoleType          # USER | ASSISTANT | SYSTEM | CRITIC | EMBODIMENT
    meta_dict: Optional[Dict]
    content: str
    video_bytes: Optional[bytes]
    image_list: Optional[List[Union[Image.Image, str]]]
    image_detail: Literal["auto", "low", "high"]
    parsed: Optional[Union[BaseModel, dict]]
    reasoning_content: Optional[str]

Key conversion methods:

FunctionCallingMessage

Extends BaseMessage for tool calls with func_name, args, and result fields.

Prompt System

TextPrompt extends str with template keyword extraction and partial formatting:

@wrap_prompt_functions
class TextPrompt(str):
    @property
    def key_words(self) -> Set[str]:
        # Extracts {placeholder} patterns from the string
        return get_prompt_template_key_words(self)

    def format(self, *args, **kwargs) -> 'TextPrompt':
        # Allows partial formatting โ€” unfilled keys stay as {key}
        default_kwargs = {key: '{' + f'{key}' + '}' for key in self.key_words}
        default_kwargs.update(kwargs)
        return TextPrompt(super().format(*args, **default_kwargs))

CodePrompt extends TextPrompt with code_type and an execute() method that runs through an interpreter.

Tool System

FunctionTool

The core abstraction โ€” wraps any callable into an OpenAI-compatible tool:

class FunctionTool:
    def __init__(
        self,
        func: Callable,
        openai_tool_schema: Optional[Dict] = None,
        synthesize_schema: bool = False,    # Auto-generate schema via LLM
        synthesize_output: bool = False,     # Mock execution via LLM
        ...
    )

Key features:

BaseToolkit

class BaseToolkit(metaclass=AgentOpsMeta):
    timeout: Optional[float] = Constants.TIMEOUT_THRESHOLD

    def get_tools(self) -> List[FunctionTool]:  # Abstract
        ...

    def run_mcp_server(self, mode):  # MCP protocol support
        self.mcp.run(mode)

All toolkit methods auto-wrapped with with_timeout unless they have a timeout parameter or are marked @manual_timeout.

RegisteredAgentToolkit Mixin

Toolkits that need a reference to their owning ChatAgent can inherit this. The agent auto-registers itself via toolkits_to_register_agent.

Toolkit Ecosystem (80+)

๐Ÿ” Search & Web

SearchToolkit, BrowserToolkit, WebFetchToolkit, HybridBrowserToolkit, HeadlessBrowserSearchToolkit, SearxNGToolkit, AskNewsToolkit, DappierToolkit

๐Ÿ’ป Code & Dev

CodeExecution, TerminalToolkit, GitHubToolkit, FileToolkit, ExcelToolkit, PPTXToolkit, MarkitdownToolkit, SQLToolkit, SympyToolkit

๐Ÿ“ง Communication

GmailToolkit, ImapMailToolkit, OutlookToolkit, SlackToolkit, DingTalkToolkit, LarkToolkit, WhatsAppToolkit, WeChatToolkit, LinkedInToolkit, TwitterToolkit, RedditToolkit, ResendToolkit

๐ŸŽจ Media

ImageGenerationToolkit, ImageAnalysisToolkit, VideoAnalysisToolkit, VideoDownloadToolkit, AudioAnalysisToolkit, MeshyToolkit, VertexAIVeoToolkit

๐Ÿ“Š Data & Research

ArxivToolkit, PubMedToolkit, SemanticScholarToolkit, GoogleScholarToolkit, OpenBBToolkit, DataCommonsToolkit, EarthScienceToolkit, WeatherToolkit

โ˜๏ธ Cloud & MCP

MCPToolkit, GoogleDriveMCPToolkit, NotionMCPToolkit, PlaywrightMCPToolkit, MinimaxMCPToolkit, EdgeOnePagesMCPToolkit, KlavisToolkit, ZapierToolkit, ACIToolkit

๐Ÿง  Agent Utilities

ThinkingToolkit, MemoryToolkit, ContextSummarizerToolkit, TodoToolkit, TaskPlanningToolkit, PlanningWorktreeToolkit, SkillToolkit, HumanToolkit, NoteTakingToolkit

๐Ÿ—บ๏ธ Other

GoogleMapsToolkit, StripeToolkit, WolframAlphaToolkit, MathToolkit, PyAutoGUIToolkit, ScreenshotToolkit, NetworkXToolkit, BohriumToolkit, MinerUToolkit, WebDeployToolkit

Model Layer

BaseModelBackend (ABC, metaclass=ModelBackendMeta) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ run() / arun() โ”‚ โ† Auto-wrapped by metaclass โ”‚ _run() / _arun() โ”‚ โ† Abstract, subclass implements โ”‚ preprocess_messages() โ”‚ โ† Remove <think> tags, format tool calls โ”‚ postprocess_response() โ”‚ โ† Extract reasoning_content โ”‚ token_counter (abstract) โ”‚ โ”‚ token_limit (property) โ”‚ โ”‚ _log_request / _log_responseโ”‚ โ† Optional JSON logging โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ OpenAIModel Anthropic Gemini DeepSeek ...40+ backends

ModelFactory

Creates backend instances from (ModelPlatformType, ModelType) tuples:

class ModelFactory:
    _MODEL_PLATFORM_TO_CLASS_MAP = {
        ModelPlatformType.OPENAI: OpenAIModel,
        ModelPlatformType.ANTHROPIC: AnthropicModel,
        ModelPlatformType.GEMINI: GeminiModel,
        ModelPlatformType.DEEPSEEK: DeepSeekModel,
        ModelPlatformType.OLLAMA: OllamaModel,
        ModelPlatformType.VLLM: VLLMModel,
        ModelPlatformType.SGLANG: SGLangModel,
        ModelPlatformType.LITELLM: LiteLLMModel,
        # ... 40+ more
    }

    @classmethod
    def create(cls, model_platform, model_type, **kwargs) -> BaseModelBackend

ModelManager

Manages multiple model backends with scheduling strategies:

ModelBackendMeta (Metaclass)

Automatically wraps run() and arun() to:

  1. preprocess_messages() โ€” Remove <think> tags, format parallel tool calls
  2. Call original _run()
  3. postprocess_response() โ€” Extract <think> content into reasoning_content

Environments

CAMEL provides RL-style environments for agent evaluation:

Action โ†’ Environment โ†’ StepResult โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ SingleStep MultiStep RLCards TicTacToe
class StepResult(BaseModel):
    observation: Observation
    reward: float
    rewards_dict: Dict[str, float]
    done: bool
    info: Dict[str, Any]

Standard RL interface with reset() and step() methods. Used for benchmarking and evaluating agent performance on structured tasks.

Runtimes

Sandboxed execution environments for tool code:

BaseRuntime (ABC) โ”‚ โ”œโ”€โ”€ DockerRuntime โ† Isolated Docker containers โ”œโ”€โ”€ UbuntuDockerRuntime โ† Ubuntu-based Docker โ”œโ”€โ”€ DaytonaRuntime โ† Daytona sandbox โ”œโ”€โ”€ RemoteHTTPRuntime โ† Remote HTTP server โ””โ”€โ”€ LLMGuardRuntime โ† LLM-based safety guard
class BaseRuntime(ABC):
    def add(self, funcs: Union[FunctionTool, List[FunctionTool]]) -> BaseRuntime
    def reset(self) -> Any
    def cleanup(self) -> None
    def get_tools(self) -> List[FunctionTool]

Runtimes can be used as context managers (with runtime:) for automatic cleanup.

Prompt Template Analysis

AI Society Prompts

The original CAMEL research prompts define a structured dialogue protocol:

ASSISTANT_PROMPT

===== RULES OF ASSISTANT =====
Never forget you are a {assistant_role} and I am a {user_role}.
Never flip roles! Never instruct me!
We share a common interest in collaborating to successfully complete a task.
You must help me to complete the task.
Here is the task: {task}. Never forget our task!
...
Always end <YOUR_SOLUTION> with: Next request.

USER_PROMPT

===== RULES OF USER =====
Never forget you are a {user_role} and I am a {assistant_role}.
Never flip roles! You will always instruct me.
...
Instruction: <YOUR_INSTRUCTION>
Input: <YOUR_INPUT>
...
When the task is completed, you must only reply with
a single word <CAMEL_TASK_DONE>.

Embodiment Prompt

You are the physical embodiment of the {role} who is working on
solving a task: {task}.
You can do things in the physical world including browsing the Internet,
reading documents, drawing images, creating videos, executing code and so on.
...
Here is your action space but it is not limited:
{action_space}

Prompt Design Patterns

PatternUsageExample
Role anchoring"Never forget you are a {role}"Prevents role confusion in multi-agent
Task fixation"Never forget our task!"Maintains focus across long conversations
Structured output format"Instruction: / Input: / Solution:"Parseable dialogue turns
Completion signal<CAMEL_TASK_DONE>Clear termination condition
Partial formattingTextPrompt.format() with defaultsTemplates work with unfilled keys

Design Patterns

Patterns Used in CAMEL

PatternWhereHow
Abstract FactoryModelFactoryCreates model backends from platform+type specs
StrategyModelManager schedulingPluggable scheduling strategies (round_robin, custom)
Template MethodBaseModelBackendrun() calls abstract _run()
Decorator / MetaclassModelBackendMetaAuto-wraps run/arun with pre/post processing
ObserverWorkforce task channelWorkers listen to shared TaskChannel
CompositeWorkforce treeWorkforce contains Workers or sub-Workforces
BuilderPipelineTaskBuilderFluent API for constructing task pipelines
Wrapper / AdapterStreamingChatAgentResponseWraps generator to be compatible with non-streaming
MixinRegisteredAgentToolkitAdds agent registration to any toolkit
Value ObjectTextPrompt(str)Immutable string extension with template features

Framework Comparison

Feature CAMEL LangChain/LangGraph CrewAI AutoGen PydanticAI
Core Paradigm Role-playing agents Chains & graphs Crew of agents Conversational agents Type-safe agents
Agent Definition Class inheritance Runnable/LCEL Decorator-based Class-based Decorator + generics
Memory 3 types (chat, vector, hybrid) Multiple backends Short/long term List-based Minimal
Tool System 80+ toolkits, auto-schema Tool/Toolkit classes Decorator-based Function calling Pydantic-validated
Multi-Agent RolePlaying + Workforce LangGraph state machines Crew + Process GroupChat Manual composition
Model Support 40+ backends 100+ via integrations Litellm-based OpenAI-centric Multiple providers
Streaming Sync + async with accumulation Full streaming support Limited Yes Yes
MCP Support Native (MCPAgent, MCPToolkit) Plugin-based Plugin Plugin Plugin
Sandboxed Execution Docker, Daytona, HTTP runtimes No native sandbox No native sandbox Docker executor No native sandbox
RL Evaluation Environments (gym-style) No No No No
Schema Synthesis LLM-generates tool schemas No No No No
Output Synthesis LLM-mocks tool execution No No No No
Auto-Summarization Progressive + full ConversationSummaryMemory No No No
Type Safety Moderate (Pydantic in tools) Moderate Low Low High (Pydantic-first)
Codebase Size 155K LOC, 502 modules ~300K+ LOC ~30K LOC ~50K LOC ~10K LOC

Strengths & Weaknesses

โœ… Strengths

  • Massive toolkit ecosystem โ€” 80+ pre-built toolkits covering search, browser, cloud, communication, media, code exec, etc. Unmatched breadth.
  • Model provider coverage โ€” 40+ backends with unified interface. Best-in-class provider diversity.
  • Sophisticated memory system โ€” Three memory types including hybrid vector+chat. Auto-summarization with progressive compression is well-engineered.
  • MCP native support โ€” First-class MCPAgent and MCPToolkit. MCP server capability built into BaseToolkit.
  • Sandboxed runtimes โ€” Docker, Daytona, and HTTP runtimes for safe code execution. Rare in agent frameworks.
  • RL evaluation โ€” Gym-style environments for agent benchmarking. Unique differentiator.
  • Schema synthesis โ€” LLM can auto-generate or fix tool schemas. Novel feature.
  • Workforce orchestration โ€” Hierarchical task decomposition with failure recovery, pipeline mode, and quality evaluation.
  • Streaming maturity โ€” Full sync/async streaming with content accumulation, reasoning extraction, and compatible wrappers.
  • Research heritage โ€” Born from academic research on multi-agent societies. Strong theoretical foundation.

โŒ Weaknesses

  • ChatAgent bloat โ€” 6444 lines in a single class. Violates SRP. Hard to maintain, test, and extend. Should be decomposed.
  • Workforce complexity โ€” 6239 lines in one file. Task assignment, decomposition, worker management, failure handling all tangled together.
  • Tight coupling โ€” ChatAgent directly depends on memory, model, tools, summarization. Hard to swap or mock components.
  • No graph-based orchestration โ€” Unlike LangGraph, there's no DAG/state-machine abstraction for complex workflows. RolePlaying is turn-based; Workforce is tree-based.
  • Weak typing in core โ€” BaseMessage is a dataclass, not Pydantic. OpenAIMessage is Dict[str, Any]. Type safety is inconsistent.
  • Inconsistent abstractions โ€” Some agents inherit ChatAgent, others don't. Tool system has both FunctionTool and BaseToolkit with overlapping responsibilities.
  • Documentation gaps โ€” Many toolkits have minimal docs. Internal APIs are sparsely documented despite public visibility.
  • Testing concerns โ€” 155K LOC with synthesize_output mode (mocking tool execution) suggests testing challenges.
  • Performance overhead โ€” Metaclass wrapping, auto-timeout decoration, and logging infrastructure add overhead to every model call.
  • Configuration complexity โ€” ChatAgent has 25+ constructor parameters. Too many knobs for common use cases.

Verdict

CAMEL is the "Swiss Army Knife" of agent frameworks โ€” it has the broadest toolkit ecosystem and model coverage of any open-source agent framework. Its research roots give it unique features (RL environments, role-playing, schema synthesis) that no other framework offers.

However, this breadth comes at a cost: the core classes (ChatAgent, Workforce) are monolithic, making the framework harder to learn, extend, and maintain than more focused alternatives. The lack of a graph-based orchestration layer limits its applicability for complex, non-hierarchical workflows.

Best suited for: Research teams exploring multi-agent societies, developers needing maximum toolkit/model coverage out-of-the-box, and teams working on agent evaluation with RL-style environments.

Less ideal for: Production systems needing clean separation of concerns, teams wanting a minimal learning curve, and applications requiring complex DAG-based workflow orchestration.

Analysis generated from source code of camel-ai v0.2.91a4 ยท Repository: github.com/camel-ai/camel

502 Python modules analyzed ยท Key files: chat_agent.py (6444 LOC), workforce.py (6239 LOC), base_model.py (1049 LOC), function_tool.py (1197 LOC)