đ« CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
title: "Society" description: "Collaborative agent frameworks in CAMEL: autonomous social behaviors, role-based task solving, and turn-based agent societies." icon: people-group
The society module simulates agent social behaviors and collaborative workflows.It powers autonomous, multi-role agents that can plan, debate, critique, and solve tasks together, minimizing human intervention while maximizing alignment with your goals.
Task: An objective or idea, given as a simple prompt.
AI User: The role responsible for providing instructions or challenges.
AI Assistant: The role tasked with generating solutions, plans, or step-by-step responses.
Critic (optional): An agent that reviews or critiques the assistant's responses for quality control.
Frameworks:
RolePlayingâ Advanced turn-taking, prompt-guarded collaboration (most common for LLM societies).
đ€ Frameworks
Turn-based, prompt-engineered, zero-role-flip agent collaboration.
- Guards against role-flipping, infinite loops, vague responses
- Structured, strict turn-takingâuser and assistant never switch
- Supports optional task planners, critics, and meta-reasoning
- Every message follows a system-enforced structure
Built-in Prompt Rules:
- Never forget you are
<ASSISTANT_ROLE>, I am<USER_ROLE> - Never flip roles or instruct me
- Decline impossible or unsafe requests, explain why
- Always answer as:
Solution: <YOUR_SOLUTION> - Always end with:
Next request.
đ§© RolePlaying Attributes
| Attribute | Type | Description |
|---|---|---|
| assistant_role_name | str | Name of assistant's role |
| user_role_name | str | Name of user's role |
| critic_role_name | str | Name of critic's role (optional) |
| task_prompt | str | Prompt for the main task |
| with_task_specify | bool | Enable task specification agent |
| with_task_planner | bool | Enable task planner agent |
| with_critic_in_the_loop | bool | Include critic in conversation loop |
| critic_criteria | str | How the critic scores/evaluates outputs |
| model | BaseModelBackend | Model backend for responses |
| task_type | TaskType | Type/category of the task |
| assistant_agent_kwargs | Dict | Extra options for assistant agent |
| user_agent_kwargs | Dict | Extra options for user agent |
| task_specify_agent_kwargs | Dict | Extra options for task specify agent |
| task_planner_agent_kwargs | Dict | Extra options for task planner agent |
| critic_kwargs | Dict | Extra options for critic agent |
| sys_msg_generator_kwargs | Dict | Options for system message generator |
| extend_sys_msg_meta_dicts | List[Dict] | Extra metadata for system messages |
| extend_task_specify_meta_dict | Dict | Extra metadata for task specification |
| output_language | str | Target output language |
Example: Turn-based multi-agent chat with custom roles and live output colors.
~~~python from colorama import Fore from camel.societies import RolePlaying from camel.utils import print_text_animated
def main(model=None, chat_turn_limit=50) -> None: # Initialize a session for developing a trading bot task_prompt = "Develop a trading bot for the stock market" role_play_session = RolePlaying( assistant_role_name="Python Programmer", assistant_agent_kwargs=dict(model=model), user_role_name="Stock Trader", user_agent_kwargs=dict(model=model), task_prompt=task_prompt, with_task_specify=True, task_specify_agent_kwargs=dict(model=model), )
# Print initial system messages
print(
Fore.GREEN
+ f"AI Assistant sys message:\\n{role_play_session.assistant_sys_msg}\\n"
)
print(
Fore.BLUE + f"AI User sys message:\\n{role_play_session.user_sys_msg}\\n"
)
print(Fore.YELLOW + f"Original task prompt:\\n{task_prompt}\\n")
print(
Fore.CYAN
+ "Specified task prompt:"
+ f"\\n{role_play_session.specified_task_prompt}\\n"
)
print(Fore.RED + f"Final task prompt:\\n{role_play_session.task_prompt}\\n")
n = 0
input_msg = role_play_session.init_chat()
# Turn-based simulation
while n < chat_turn_limit:
n += 1
assistant_response, user_response = role_play_session.step(input_msg)
if assistant_response.terminated:
print(
Fore.GREEN
+ (
"AI Assistant terminated. Reason: "
f"{assistant_response.info['termination_reasons']}."
)
)
break
if user_response.terminated:
print(
Fore.GREEN
+ (
"AI User terminated. "
f"Reason: {user_response.info['termination_reasons']}."
)
)
break
print_text_animated(
Fore.BLUE + f"AI User:\\n\\n{user_response.msg.content}\\n"
)
print_text_animated(
Fore.GREEN + "AI Assistant:\\n\\n"
f"{assistant_response.msg.content}\\n"
)
if "CAMEL_TASK_DONE" in user_response.msg.content:
break
input_msg = assistant_response.msg
if name == "main": main()
</Card>
---
<AccordionGroup>
<Accordion title="Tips & Best Practices">
<ul>
<li>Use <b>RolePlaying</b> for most multi-agent conversations, with or without a critic.</li>
<li>Define specific roles and prompt-guardrails for your agentsâstructure is everything!</li>
<li>Leverage the <code>with_task_specify</code> and <code>with_task_planner</code> options for highly complex tasks.</li>
<li>Monitor for infinite loopsâevery agent response should have a clear next step or end.</li>
</ul>
</Accordion>
<Accordion title="More Examples & Advanced Use">
<ul>
<li>Check <code>[examples/society/](https://github.com/camel-ai/camel/tree/master/examples/runtimes)</code> in the CAMEL repo for advanced agent society demos.</li>
<li>Explore <b>critic-in-the-loop</b> setups for higher accuracy and safety.</li>
<li>Integrate toolkits or external APIs into agent society loops for real-world workflows.</li>
</ul>
</Accordion>
</AccordionGroup>