Role-Play diagramIdea, Task specifier, AI user, AI assistant, Result. Step captions follow the diagram.IdeaTask specifierAI userrole: stock traderAI assistantrole: Python programmerResultRole-Play diagramIdea, Task specifier, AI user, AI assistant, Result. Step captions follow the diagram.IdeaTaskspecifierAI userrole: stocktraderAIassistantrole: PythonprogrammerResult

All steps

Instruction and solution

Role drift, caught

Parts of this pattern
Idea Input / output
The rough goal a human types once, such as 'Develop a trading bot for the stock market'.
Task specifier LLM call
Turns the vague idea into a concrete task with a clear deliverable, before either agent starts.
AI user Agent
The instructor. Plays the stock trader: decides what to do next and gives one instruction at a time; never writes the solution.
AI assistant Agent
The doer. Plays the Python programmer: carries out each instruction with a concrete solution; never gives instructions.
Result Input / output
The transcript and the assistant's solutions, returned once the AI user declares the task done.
Idea → Task specifier
The rough idea and both role names go to the task specifier.Idea: Develop a trading bot for the stock market. Roles: Stock Trader, Python Programmer.
Task specifier → AI usertask
The specified task is written into the AI user's inception prompt, alongside both roles.Task: Build a Python bot that reads Reddit sentiment on 5 tickers and places paper trades when sentiment flips.
Task specifier → AI assistanttask
The same specified task is written into the AI assistant's inception prompt, so both agents share one goal.Never forget you are a Python Programmer and I am a Stock Trader. Task: Build a Python bot that reads Reddit sentiment...
AI user → AI assistantInstruction
One instruction at a time, with the input it needs, passed to the assistant as its next user message.Instruction: Write a function that fetches the last 24 hours of posts mentioning a ticker. Input: tickers = ['AAPL', 'TSLA']
AI assistant → AI userSolution
The assistant's solution goes back to the AI user, who reads it and decides the next instruction.Solution: def fetch_posts(ticker, hours=24): ... returns a list of {text, score, created}. Next request.
AI user → ResultTASK_DONE
When the AI user judges the task complete, it sends the done token instead of another instruction.<CAMEL_TASK_DONE>

← → neighboursesc atlas

Multi-Agent

Role-Play

Also known as CAMEL · Inception prompting · AI user and AI assistant · Two-agent society

Two role-prompted agents, an instructor and a doer, trade instructions and solutions turn by turn until the instructor declares the task done.

Introduced by Li et al. (2023) · KAUST

CAMEL introduced inception prompting: each agent's system prompt fixes both roles and the task, so the pair can cooperate for many turns without a human.

Measured over one run

Nodes
5. Boxes in the diagram: models, tools, stores, people and plain code.
LLM calls
9. Model invocations in the first scenario: each time a model or agent node starts thinking, plus each branch it decides.
Tool calls
0. Messages sent to a tool node in the first scenario.
Steps
5. Steps in the first scenario, with repeated steps counted every time they run.
Scenarios
2. Distinct example runs you can switch between on the diagram.
Loop
yes. Whether the flow cycles back on itself until a condition is met.
Parallel
yes. Whether two or more messages are in flight at the same time.
Branch
yes. Whether the flow takes one path out of several, chosen at run time.
Human in the loop
no. Whether a person appears as a node, to approve, correct or answer.
Autonomy
high. How much the model decides the control flow itself, from fixed code paths (low) to open-ended (high).
Cost
medium. Relative token spend per request.
Latency
high. Relative wall-clock time per request.

Counted from the first scenario's timeline when the site is built.

Problem

A single prompt like “develop a trading bot for the stock market” is too vague for a model to finish in one go, and a human who breaks it into steps has to keep prompting, reading and re-prompting for an hour. You want the model to do both jobs: decide the next step and carry it out. But one model that plans and executes in the same breath tends to skip steps, lose the thread or wander off the task.

How it works

Role-play splits the two jobs between two agents and makes them talk. First a task specifier turns the rough idea into something concrete: “build a Python bot that reads Reddit sentiment on five tickers and places paper trades when sentiment flips.”

Each agent then gets an inception prompt that fixes both roles and the task. The AI user plays the stock trader. It knows what the bot should do, and it gives exactly one instruction at a time, in the form Instruction: … Input: …. The AI assistant plays the Python programmer. It answers each instruction with Solution: … and ends with “Next request.” Your code passes each message across as the other agent’s next user turn, so each agent has its own history and the two simply alternate.

There is no manager. The AI user is both the planner and the judge: when it thinks the bot is complete, it sends <CAMEL_TASK_DONE> instead of another instruction, and the transcript goes to the result.

The inception prompts do the heavy lifting. “Never forget you are a Stock Trader and I am a Python Programmer. Never flip roles!” sounds blunt, but without it the pair soon drifts: the assistant starts giving instructions, or both agents just thank each other.

When to use

  • A task needs many small steps and you want them driven with no human prompting in between.
  • Two clear, complementary perspectives exist: a domain expert who knows what is needed and a practitioner who knows how to build it.
  • You want to generate realistic instruction-and-solution dialogue as training or evaluation data, which is what CAMEL was first used for.

When to avoid

  • The task mostly needs tools, tests or verification. Two agents chatting does not check that the code runs; add an executor or a test step.
  • More than two roles are needed. Use a group chat or an SOP-driven team instead.
  • Cost and latency matter. Every round is two model calls over two growing histories, and the conversation can run for dozens of rounds.

Trade-offs

Role-play buys autonomy cheaply: two prompts and a loop, with no orchestration logic. In exchange, the AI user is a model judging its own team’s progress, so “done” means the instructor is satisfied, not that the work is verified. Splitting the roles keeps each agent focused, but neither one sees the whole picture the way a single planner would.

Failure modes

  • Role flipping: the assistant starts instructing, or the user starts solving. Check each reply’s prefix, and resend the role rules when it is wrong.
  • Instruction repeating: the AI user asks for the same thing again and again. Detect repeated messages and stop the run.
  • Flake replies: the assistant says “I will do that” without giving a solution. Require a concrete Solution: body.
  • Infinite politeness: both agents thank each other and wrap up without finishing. Cap the rounds and return the transcript with a status saying it did not finish.

Build it with your AI

Paste this into Claude Code, Cursor, ChatGPT or any AI coding assistant.

Implement the Role-Play pattern in this codebase, using the LLM client and language we already use.

## Goal

Complete a task through a conversation between two role-prompted agents, an AI user that gives one instruction at a time and an AI assistant that carries each one out, after a specifier turns the rough idea into a concrete task.

## How it works

1. Call the model with the Task specifier prompt, passing the rough idea and both role names, to get a specific, concrete task.
2. Build the AI user's system prompt from the AI user (instructor) prompt and the AI assistant's from the AI assistant (doer) prompt, each with both role names and the specified task. Keep a separate message history for each agent.
3. Ask the AI user for its first instruction. Pass each instruction to the AI assistant as a user message, and pass each solution back to the AI user the same way.
4. Check the format of every reply: the AI user must start with 'Instruction:' or send the done token, and the AI assistant must start with 'Solution:'. On a mismatch, resend that agent's role rules and ask again, once.
5. When the AI user's message contains <CAMEL_TASK_DONE>, return the specified task, the full transcript and the assistant's solutions in order.

## Prompts

### Task specifier prompt

```markdown
Here is a task that {{assistant_role}} will help {{user_role}} to complete:
<idea>{{idea}}</idea>

Make it more specific: name the concrete deliverable, the inputs it works on
and how we will know it is finished. Be creative but realistic.
Reply with the specified task only, in {{word_limit}} words or fewer.
```

### AI user (instructor) prompt

```markdown
Never forget you are a {{user_role}} and I am a {{assistant_role}}. Never flip roles!
We share a common interest in completing this task: {{task}}

You must instruct me, one instruction at a time, to complete the task.
Always reply in this form:
Instruction: <one concrete instruction>
Input: <the input it needs, or None>

Give instructions only, never solutions. Do not ask me questions.
When the task is fully complete, reply with only: <CAMEL_TASK_DONE>
Never say <CAMEL_TASK_DONE> unless my responses have solved the task.
```

### AI assistant (doer) prompt

```markdown
Never forget you are a {{assistant_role}} and I am a {{user_role}}. Never flip roles!
We share a common interest in completing this task: {{task}}

I will give you one instruction at a time. Carry out each one with a
specific, complete solution. If you cannot, say why and decline.
Always reply in this form:
Solution: <your solution, with any code or detail it needs>
Next request.

Never give me instructions, and never ask me questions.
```

## Stop rule

Stop when the AI user sends <CAMEL_TASK_DONE>, or after 20 instruction and solution rounds. On the cap, return the transcript with a status of max_rounds. If one agent repeats the same message three times, stop early with a status of looping.

## Requirements

- Never let the roles flip: the AI user only instructs and the AI assistant only solves. Treat a reply in the wrong role as a format error.
- Make the round cap a parameter (default 20), and detect three identical consecutive messages from either agent as a loop.
- The two agents may use different models, configured separately; the specifier can be a cheaper model.
- Log every message with its role, its round number and its token count.
- Add a test with a stub LLM whose AI user replies 'Instruction: a', 'Instruction: b', then <CAMEL_TASK_DONE>, and whose AI assistant always replies 'Solution: ... Next request.'; assert exactly two AI assistant calls and a transcript ordered instruction, solution, instruction, solution, done.

Prompt templates

Task specifier prompt
Here is a task that {{assistant_role}} will help {{user_role}} to complete:
<idea>{{idea}}</idea>
Make it more specific: name the concrete deliverable, the inputs it works on
and how we will know it is finished. Be creative but realistic.
Reply with the specified task only, in {{word_limit}} words or fewer.
AI user (instructor) prompt
Never forget you are a {{user_role}} and I am a {{assistant_role}}. Never flip roles!
We share a common interest in completing this task: {{task}}
You must instruct me, one instruction at a time, to complete the task.
Always reply in this form:
Instruction: <one concrete instruction>
Input: <the input it needs, or None>
Give instructions only, never solutions. Do not ask me questions.
When the task is fully complete, reply with only: <CAMEL_TASK_DONE>
Never say <CAMEL_TASK_DONE> unless my responses have solved the task.
AI assistant (doer) prompt
Never forget you are a {{assistant_role}} and I am a {{user_role}}. Never flip roles!
We share a common interest in completing this task: {{task}}
I will give you one instruction at a time. Carry out each one with a
specific, complete solution. If you cannot, say why and decline.
Always reply in this form:
Solution: <your solution, with any code or detail it needs>
Next request.
Never give me instructions, and never ask me questions.

Related patterns

Composes well with:

Sources

  1. CAMEL: Communicative Agents for 'Mind' Exploration of Large Language Model Society (Li et al., 2023)

From the Agentic Atlas by Joran Kikke · Edit on GitHub · Suggest a correction