6.4 Framework Three: CAMEL
Unlike comprehensive frameworks like AutoGen and AgentScope, CAMEL's original core goal is to explore how to enable two agents to autonomously collaborate to solve complex tasks through "role-playing" with minimal human intervention.
6.4.1 Autonomous Collaboration in CAMEL
The cornerstone of CAMEL's autonomous collaboration is two core concepts: Role-Playing and Inception Prompting.
(1) Role-Playing
In CAMEL's original design, a task is usually completed by two agents collaborating. These two agents are assigned complementary, clearly defined "roles." One plays the "AI User", responsible for proposing requirements, issuing instructions, and conceiving task steps; the other plays the "AI Assistant", responsible for executing specific operations and providing solutions based on instructions.
For example, in a task to "develop a stock trading strategy analysis tool":
- The AI User role might be a "senior stock trader." It understands the market and strategies but doesn't understand programming.
- The AI Assistant role is an "excellent Python programmer." It is proficient in programming but knows nothing about stock trading.
Through this setup, the task-solving process is naturally transformed into a conversation between two "cross-domain experts." The trader proposes professional requirements, the programmer transforms them into code implementation, and the two collaborate to complete complex tasks that neither could accomplish independently.
(2) Inception Prompting
Simply setting roles is not enough. How can we ensure that two AIs can always "stay in their roles" and efficiently move toward a common goal without continuous human supervision? This is where CAMEL's core technology, inception prompting, comes into play. "Inception prompting" is a carefully designed, structured initial instruction (System Prompt) injected into both agents before the conversation begins. This instruction is like an "action program" implanted in the agents, and it usually includes the following key parts:
- Clarify own role: For example, "You are a senior stock trader..."
- Inform collaborator's role: For example, "You are working with an excellent Python programmer..."
- Define common goal: For example, "Your common goal is to develop a stock trading strategy analysis tool."
- Set behavioral constraints and communication protocols: This is the most critical part. For example, the instruction will require the AI user to "propose only one clear, specific step at a time" and require the AI assistant to "not ask for more details before completing the previous step," while also specifying that both parties need to use specific markers (such as
<SOLUTION>) at the end of their replies to identify task completion.
These constraints ensure that the conversation does not deviate from the topic or fall into ineffective loops but advances in a highly structured, task-driven manner, as shown in Figure 6.3.

Figure 6.3 CAMEL Creating Stock Trading Robot
In the next section, we will experience this process through a specific example.
6.4.2 AI Popular Science E-book
To understand CAMEL framework's role-playing capabilities, we will build a practical collaborative case: having an AI psychologist work with an AI author to co-create a short e-book on "The Psychology of Procrastination." This case embodies CAMEL's core advantage of allowing two agents to leverage their respective professional domains to collaboratively complete complex creative tasks that a single agent would struggle with.
(1) Task Setup
Scenario Setup: Create a popular science e-book on the psychology of procrastination for general readers, requiring both scientific rigor and good readability.
Agent Roles:
- Psychologist: Possesses deep theoretical foundation in psychology, familiar with cognitive behavioral science, neuroscience, and other related fields, able to provide professional academic insights and empirical research support
- Writer: Has excellent writing skills and narrative ability, good at transforming complex academic concepts into vivid and easy-to-understand text, focusing on reader experience and content readability
(2) Define Collaboration Task
First, we need to clarify the common goal of the two AI experts. We define this task through a detailed string task_prompt.
from colorama import Fore
from camel.societies import RolePlaying
from camel.utils import print_text_animated
from camel.models import ModelFactory
from camel.types import ModelPlatformType
from dotenv import load_dotenv
import os
load_dotenv()
LLM_API_KEY = os.getenv("LLM_API_KEY")
LLM_BASE_URL = os.getenv("LLM_BASE_URL")
LLM_MODEL = os.getenv("LLM_MODEL")
# Create model, using Qwen as an example, calling Alibaba Cloud Bailian platform API
model = ModelFactory.create(
model_platform=ModelPlatformType.QWEN,
model_type=LLM_MODEL,
url=LLM_BASE_URL,
api_key=LLM_API_KEY
)
# Define collaboration task
task_prompt = """
Create a short e-book on "The Psychology of Procrastination" for general readers interested in psychology.
Requirements:
1. Content should be scientifically rigorous, based on empirical research
2. Language should be easy to understand, avoiding excessive professional terminology
3. Include practical improvement suggestions and case analysis
4. Length controlled at 8000-10000 words
5. Clear structure, including introduction, core chapters, and summary
"""
print(Fore.YELLOW + f"Collaboration task:\n{task_prompt}\n")task_prompt is the "task specification" for the entire collaboration. It is not only the goal we want to achieve but will also be used behind the scenes by CAMEL to generate "inception prompts," ensuring that the conversation between the two agents always revolves around this core goal.
(3) Initialize Role-Playing "Society"
Next, we create a RolePlaying session instance. This is CAMEL's core operation, which quickly builds a two-agent collaboration "society" based on the roles and tasks we provide.
# Initialize role-playing session
# AI writer as "user", responsible for proposing writing structure and requirements
# AI psychologist as "assistant", responsible for providing professional knowledge and content
role_play_session = RolePlaying(
assistant_role_name="Psychologist",
user_role_name="Writer",
task_prompt=task_prompt,
model=model,
with_task_specify=False, # In this example, we directly use the given task_prompt
)
print(Fore.CYAN + f"Specific task description:\n{role_play_session.task_prompt}\n")RolePlaying is a high-level API provided by CAMEL that encapsulates complex prompt engineering. We only need to pass in the names of the two roles and the task. In CAMEL's design, the user role is the "driver" and "demander" of the conversation, while the assistant role is the "executor" and "solution provider." Therefore, we assign the "writer" responsible for planning structure to user_role_name and the "psychologist" responsible for providing professional knowledge to assistant_role_name.
(4) Start and Run Automated Conversation
Finally, we write a loop to drive the entire conversation process, allowing the two AI experts to begin their automated collaboration.
# Start collaboration conversation
chat_turn_limit, n = 30, 0
# Call init_chat() to get the initial conversation message generated by AI
input_msg = role_play_session.init_chat()
while n < chat_turn_limit:
n += 1
# step() method drives a complete round of conversation, AI user and AI assistant each speak once
assistant_response, user_response = role_play_session.step(input_msg)
# Check if messages are returned to prevent premature conversation termination
if assistant_response.msg is None or user_response.msg is None:
break
print_text_animated(Fore.BLUE + f"Writer (AI User):\n\n{user_response.msg.content}\n")
print_text_animated(Fore.GREEN + f"Psychologist (AI Assistant):\n\n{assistant_response.msg.content}\n")
# Check task completion flag
if "<CAMEL_TASK_DONE>" in user_response.msg.content or "<CAMEL_TASK_DONE>" in assistant_response.msg.content:
print(Fore.MAGENTA + "✅ E-book creation completed!")
break
# Use assistant's reply as input for next round of conversation
input_msg = assistant_response.msg
print(Fore.YELLOW + f"Total of {n} rounds of collaborative conversation")This while loop is the core of automated collaboration. The conversation is automatically initiated by the init_chat() method based on the task and roles, without the need to manually write an opening. Each step of the loop drives a complete round of interaction by calling step() (writer proposes requirements, psychologist provides content), and uses the psychologist's output from the previous round as input for the next round, forming a chain of creation. The entire process will continue until the preset conversation turn limit is reached, or automatically terminates after either agent outputs the task completion flag <CAMEL_TASK_DONE>.
(5) Collaboration Process Demonstration
When executing the above code, we don't just get a long string of monotonous Q&A but can observe a highly structured collaboration process, like a human expert team, automatically proceeding. The entire creation process naturally divides into several stages:
Stage 1 (approximately rounds 1-5): Framework Building and Goal Alignment In the early stages of the conversation, the "writer" agent first plays the leading role, proposing initial ideas for the overall structure and chapter arrangement of the e-book. Subsequently, the "psychologist" reviews and supplements this framework from a professional perspective, ensuring that core academic modules (such as theoretical foundations, key concepts, etc.) are not omitted, thereby reaching consensus on the final output at the beginning of collaboration.
Stage 2 (approximately rounds 6-20): Core Content Generation and Knowledge Translation This is the most efficient content creation stage. The collaboration mode becomes a stable "request-response" loop:
- Psychologist: Responsible for providing "hardcore" professional knowledge, such as scientific explanations of core concepts like "temporal discounting theory" and "executive function deficits," and citing relevant experimental research to support viewpoints.
- Writer: Plays the role of "translator," transforming these rigorous but potentially obscure academic concepts into vivid, figurative metaphors and life-related cases. For example, it might compare the concept of "present bias in the brain" to "a willful child who only cares about immediate candy and not long-term health."
Stage 3 (approximately rounds 21-25): Iterative Optimization and Quality Assurance When the main content of the book is completed, the focus of the conversation shifts to polishing and improving the existing text. At this time, the roles of the two agents undergo subtle changes:
- Writer: More focused on examining the overall fluency, logical coherence, and language style of the article, proposing revision suggestions from the perspective of "reader experience."
- Psychologist: Again plays the role of "fact checker," ensuring that the scientific accuracy of core knowledge is not lost during translation and polishing, and supplementing certain viewpoints with more powerful empirical research support.
Stage 4 (Conclusion): Summary and Elevation In the last few rounds of conversation, both parties collaborate to complete the summary of practical suggestions and the review of the entire book, ensuring that the e-book has a clear, powerful ending that leaves a deep impression on readers and provides practical value.
Collaboration task:
Create a short e-book on "The Psychology of Procrastination" for general readers interested in psychology.
Requirements:
1. Content should be scientifically rigorous, based on empirical research
2. Language should be easy to understand, avoiding excessive professional terminology
3. Include practical improvement suggestions and case analysis
4. Length controlled at 8000-10000 words
5. Clear structure, including introduction, core chapters, and summary
Specific task description:
Write an 8000–10000 word short e-book "The Psychology of Procrastination" for general readers: empirically based, easy to understand. Structure: introduction, causes (cognitive/emotional/reward), motivation and decision-making, habit formation and intervention, practical strategies and exercises, three case analyses, summary and resources. Each chapter contains research citations and actionable steps.
Writer:
Instruction: Please write a 400–600 word Chinese draft for the "Introduction" chapter of the e-book...
Input: None
Psychologist:
Solution:
Draft: Procrastination refers to the behavior and internal tendency of repeatedly postponing or avoiding a task despite knowing it should be completed. It can be an occasional time management problem...
Next request.
Writer:
Instruction: Please revise the following introduction draft into a 450–550 word Chinese text...
Input: Draft: Procrastination refers to the behavior and internal tendency of repeatedly postponing or avoiding a task...
.....6.4.3 Analysis of CAMEL's Advantages and Limitations
Through the previous e-book creation case, we deeply experienced CAMEL framework's unique role-playing paradigm. Now let's objectively analyze the advantages and limitations of this design philosophy to make wise technical choices in actual projects.
(1) Advantages
CAMEL's greatest advantage lies in its "light architecture, heavy prompting" design philosophy. Compared to AutoGen's complex conversation management and AgentScope's distributed architecture, CAMEL can achieve high-quality agent collaboration through carefully designed initial prompts. This naturally emergent collaborative behavior is often more flexible and efficient than hard-coded workflows.
It's worth noting that the CAMEL framework is undergoing rapid development and evolution. From its GitHub repository, we can see that CAMEL is far more than a simple two-agent collaboration framework and currently has:
- Multimodal Capabilities: Supports agent collaboration in multiple modalities such as text, image, and audio
- Tool Integration: Built-in rich tool library, including search, calculation, code execution, etc.
- Model Adaptation: Supports multiple LLM backends such as OpenAI, Anthropic, Google, and open-source models
- Ecosystem Linkage: Achieved interoperability with mainstream frameworks such as LangChain, CrewAI, and AutoGen
(2) Main Limitations
- High Dependence on Prompt Engineering
CAMEL's success largely depends on the quality of initial prompts. This brings several challenges:
- Prompt Design Threshold: Requires deep understanding of the target domain and LLM behavioral characteristics
- Debugging Complexity: When collaboration is ineffective, it's difficult to pinpoint whether the problem lies in role definition, task description, or interaction rules
- Consistency Challenge: Different LLMs may have different understandings of the same prompt
- Collaboration Scale Limitations
Although CAMEL performs excellently in two-agent collaboration, it faces challenges when handling large-scale multi-agent scenarios:
- Conversation Management: Lacks complex conversation routing mechanisms like AutoGen
- State Synchronization: Doesn't have distributed state management capabilities like AgentScope
- Conflict Resolution: Lacks effective arbitration mechanisms when multiple agents disagree
- Task Applicability Boundaries
CAMEL is particularly suitable for tasks requiring deep collaboration and creative thinking, but may not be the optimal choice in certain scenarios:
- Strict Process Control: For tasks requiring precise step control, LangGraph's graph structure is more suitable
- Large-scale Concurrency: AgentScope's message-driven architecture has more advantages in high-concurrency scenarios
- Complex Decision Trees: AutoGen's group chat mode is more flexible in multi-party decision scenarios
Overall, CAMEL represents a unique and elegant multi-agent collaboration paradigm. Through its "human-centered" role-playing design, it transforms complex system engineering problems into intuitive interpersonal collaboration patterns. As its ecosystem continues to improve and functions continue to expand, CAMEL is becoming one of the important choices for building intelligent collaboration systems.