What is the Prompt Module?

The prompt module in CAMEL guides AI models to produce accurate, relevant, and personalized outputs. It provides a library of templates and dictionaries for diverse tasks — like role description, code generation, evaluation, embeddings, and even object recognition.

You can also craft your own prompts to precisely shape your agent’s behavior.

Using Prompt Templates

CAMEL provides many ready-to-use prompt templates for quickly spinning up task-specific agents.
from camel.agents import TaskSpecifyAgent
from camel.configs import ChatGPTConfig
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType, TaskType

model = ModelFactory.create(
    model_platform=ModelPlatformType.OPENAI,
    model_type=ModelType.GPT_4O_MINI,
)
task_specify_agent = TaskSpecifyAgent(
    model=model, task_type=TaskType.AI_SOCIETY
)
specified_task_prompt = task_specify_agent.run(
    task_prompt="Improving stage presence and performance skills",
    meta_dict=dict(
        assistant_role="Musician", user_role="Student", word_limit=100
    ),
)

print(f"Specified task prompt:\n{specified_task_prompt}\n")
Set task_type=TaskType.AI_SOCIETY to use the default society prompt template, or define your own.

Using Your Own Prompt

Create and pass your own prompt template with full flexibility:
from camel.agents import TaskSpecifyAgent
from camel.configs import ChatGPTConfig
from camel.models import ModelFactory
from camel.prompts import TextPrompt
from camel.types import ModelPlatformType, ModelType

model = ModelFactory.create(
    model_platform=ModelPlatformType.OPENAI,
    model_type=ModelType.GPT_4O_MINI,
)

my_prompt_template = TextPrompt(
    'Here is a task: I\'m a {occupation} and I want to {task}. Help me to make this task more specific.'
)
task_specify_agent = TaskSpecifyAgent(
    model=model, task_specify_prompt=my_prompt_template
)
response = task_specify_agent.run(
    task_prompt="get promotion",
    meta_dict=dict(occupation="Software Engineer"),
)
print(response)

Introduction to the CodePrompt Class

The CodePrompt class represents a code prompt and extends TextPrompt. It’s perfect for code generation and execution tasks.
from camel.prompts import CodePrompt

Creating a CodePrompt

code_prompt = CodePrompt("a = 1 + 1", code_type="python")

Accessing and Modifying the Code and Type

print(code_prompt)          # >>> "a = 1 + 1"
print(code_prompt.code_type)  # >>> "python"

code_prompt.set_code_type("python")
print(code_prompt.code_type)  # >>> "python"

Executing the Code

code_prompt = CodePrompt("a = 1 + 1\nb = a + 1\nprint(a,b)", code_type="python")
output = code_prompt.execute()
# Running code? [Y/n]: y
print(output)
# >>> 2 3

Write Your Prompts with the TextPrompt Class

The TextPrompt class is a subclass of Python’s str, with extra features for managing key words and advanced formatting.
from camel.prompts import TextPrompt

prompt = TextPrompt('Please enter your name and age: {name}, {age}')
print(prompt)
# >>> 'Please enter your name and age: {name}, {age}'

The key_words Property

from camel.prompts import TextPrompt

prompt = TextPrompt('Please enter your name and age: {name}, {age}')
print(prompt.key_words)
# >>> {'name', 'age'}

The format Method (Partial Formatting Supported)

from camel.prompts import TextPrompt

prompt = TextPrompt('Your name and age are: {name}, {age}')
name, age = 'John', 30
formatted_prompt = prompt.format(name=name, age=age)
print(formatted_prompt)
# >>> "Your name and age are: John, 30"

# Partial formatting
partial_formatted_prompt = prompt.format(name=name)
print(partial_formatted_prompt)
# >>> "Your name and age are: John, {age}"

Manipulating TextPrompt Instances

You can concatenate, join, and use string methods with TextPrompt just like Python strings:
from camel.prompts import TextPrompt

prompt1 = TextPrompt('Hello, {name}!')
prompt2 = TextPrompt('Welcome, {name}!')

# Concatenation
prompt3 = prompt1 + ' ' + prompt2
print(prompt3)  
# >>> "Hello, {name}! Welcome, {name}!"
print(isinstance(prompt3, TextPrompt))  # >>> True
print(prompt3.key_words)                # >>> {'name'}

# Joining
prompt4 = TextPrompt(' ').join([prompt1, prompt2])
print(prompt4)
# >>> "Hello, {name}! Welcome, {name}!"
print(isinstance(prompt4, TextPrompt))  # >>> True
print(prompt4.key_words)                # >>> {'name'}

# String methods
prompt5 = prompt4.upper()
print(prompt5)
# >>> "HELLO, {NAME}! WELCOME, {NAME}!"
print(isinstance(prompt5, TextPrompt))  # >>> True
print(prompt5.key_words)                # >>> {'NAME'}

Supported Prompt Templates

This class defines prompt templates for the AI Society role-playing and task handling workflow.Templates include:
  • GENERATE_ASSISTANTS: List roles the AI assistant can play.
  • GENERATE_USERS: List common user groups or occupations.
  • GENERATE_TASKS: List diverse tasks for assistants.
  • TASK_SPECIFY_PROMPT: Detail a task given assistant and user roles.
  • ASSISTANT_PROMPT: Rules for assistants to complete tasks.
  • USER_PROMPT: Rules for giving instructions to assistants.
  • CRITIC_PROMPT: Criteria for critics choosing among proposals.
This class provides prompts for code-related tasks (language, domain, code task generation, and instructions for coders).Templates include:
  • GENERATE_LANGUAGES: List computer programming languages.
  • GENERATE_DOMAINS: List common programming domains.
  • GENERATE_TASKS: List tasks for programmers.
  • TASK_SPECIFY_PROMPT: Specify a programming-related task.
  • ASSISTANT_PROMPT: Rules for completing code tasks.
  • USER_PROMPT: User instructions for coding agents.
Prompts for generating questions to evaluate knowledge.Templates include:
  • GENERATE_QUESTIONS: Create question sets for evaluating knowledge emergence, with optional field-specific examples.
Prompts for generating text embedding tasks and synthetic data for embedding model improvement.Templates include:
  • GENERATE_TASKS: Generate synthetic text embedding tasks.
  • ASSISTANT_PROMPT: Generate synthetic queries (JSON), positive docs, and hard negatives.
Prompts to test model alignment by introducing misleading or jailbreak tasks.Templates include:
  • DAN_PROMPT: Do-Anything-Now jailbreak prompt.
  • GENERATE_TASKS: List unique malicious tasks.
  • TASK_SPECIFY_PROMPT: Specify a malicious task in detail.
  • ASSISTANT_PROMPT: Rules for misaligned assistant tasks.
  • USER_PROMPT: User instructions in misalignment contexts.
Prompts for object recognition tasks.Templates include:
  • ASSISTANT_PROMPT: Detect all objects in images, minimizing redundancy.
Inherits from AISocietyPromptTemplateDict and adds prompts for describing roles and responsibilities.Templates include:
  • ROLE_DESCRIPTION_PROMPT: Explain roles and responsibilities for agents.
Prompts to focus AI on finding solutions using particular knowledge.Templates include:
  • ASSISTANT_PROMPT: Rules for extracting and presenting solutions.
Prompts for translation assistants (English → target language).Templates include:
  • ASSISTANT_PROMPT: Rules for completing translation tasks.
Prompts for describing video content.Templates include:
  • ASSISTANT_PROMPT: Rules for generating video descriptions.