Prompt Engineering and CAMEL: Role‑Playing AI Agents for Automated Prompt Generation
This article explains how Prompt Engineering combined with the CAMEL framework enables role‑playing AI agents to automatically generate and manage prompts, illustrates the concept with a stock‑trading example, and provides Python code using LangChain to build a marketing‑automation agent for a small business.
Prompt Engineering is a key technique for unlocking the potential of large language models (LLMs); when combined with role‑playing AI agents, it can dramatically improve efficiency. The article introduces the CAMEL framework (Communicate Agents for Mind Exploration of Large Scale Language Model Society), which uses role‑playing agents to exchange information and solve tasks autonomously.
CAMEL defines several agent roles, such as a Task Specifier that refines vague user requests into clear prompts, and specialized agents like a Python‑capable AI engineer and a financial analyst for a stock‑trading scenario. The process relies on Inception Prompting, where agents generate prompts for each other during interaction.
In the stock‑trading example, a user asks for a robot that collects social‑media sentiment and executes trades. The Task Specifier produces a concrete prompt:
开发一个股票交易robot,收集社交媒体上特定股票的信息,并根据情感分析执行交易。Two specialized agents (a Python engineer and a securities analyst) then collaborate through multiple dialogue rounds until the task is completed without further human intervention.
The article then presents a practical marketing‑automation project for a small shop, showing how to set up the required Python environment and import necessary libraries:
# 设置OPENAI_API_KEY 环境变量
import os
os.environ["OPENAI_API_KEY"]=""
from typing import List
from langchain.chat_models import ChatOpenAI
from langchain.propmts.chat import (
SystemMesssagePromptTemplate,
HumanMessagePromptTemplate
)
from langchain.schema import (
AIMessage,
HumanMessage,
SystemMessage,
BaseMessage
)A CAMELAgent class is defined to manage message initialization, updates, and interaction with the LLM:
class CAMELAgent:
def __init__(self, system_message: SystemMessage, model: ChatOpenAI) -> None:
self.system_message = system_message
self.model = model
self.init_messages()
def init_messages(self) -> None:
self.stored_messages = [self.system_message]
def update_messages(self, message: BaseMessage) -> List[BaseMessage]:
self.stored_messages.append(message)
return self.stored_messages
def reset(self) -> None:
self.init_messages()
return self.stored_messages
def step(self, input_message: HumanMessage) -> AIMessage:
messages = self.update_messages(input_message)
output_message = self.model(messages)
self.update_messages(output_message)
return output_messageRoles and task specifications for the marketing scenario are defined, and system‑message templates are generated using LangChain’s SystemMessagePromptTemplate:
assistant_role_name = "干货店营销经理"
user_role_name = "店老板老喻"
task = "整理出重阳节营销活动的策略"
word_limit = 60System messages for both the assistant and the user are created via a helper function get_sys_msgs, after which two CAMELAgent instances (assistant and user) are instantiated and their dialogues are simulated in a loop until the special token <CAMEL_TASK_DONE> appears.
The article concludes that Inception Prompting extends traditional Prompt Engineering by enabling agents to auto‑generate prompts, and that understanding agent development is essential for building sophisticated AI‑driven applications.
References include the original CAMEL paper, Task Specifier prompt design resources, and LangChain tutorials.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Rare Earth Juejin Tech Community
Juejin, a tech community that helps developers grow.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
