This cookbook provides a example of an agent uses custom prompt to set a task for selling products.
import asyncio
import os
from camel.models import ModelFactory
from camel.prompts import TextPrompt
from camel.types import ModelPlatformType, ModelType
import oasis
from oasis import ActionType, AgentGraph, LLMAction, SocialAgent, UserInfo
async def main():
# Define the model for the agents
openai_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
)
# Define the available actions for the agents
available_actions = [
ActionType.LIKE_POST, ActionType.DISLIKE_POST, ActionType.CREATE_POST,
ActionType.CREATE_COMMENT, ActionType.LIKE_COMMENT,
ActionType.DISLIKE_COMMENT, ActionType.FOLLOW, ActionType.MUTE,
ActionType.PURCHASE_PRODUCT
]
seller_template = TextPrompt('Your aim is: {aim} Your task is: {task}')
profile = {
"aim": "Persuade people to buy `GlowPod` lamp.",
"task": "Using roleplay to tell some story about the product.",
}
agent_graph = AgentGraph()
agent_1 = SocialAgent(
agent_id=0,
user_info=UserInfo(
user_name="snackslut",
name="Snack Slut",
description="I taste so you don’t have to.",
profile=profile,
),
user_info_template=seller_template,
agent_graph=agent_graph,
model=openai_model,
available_actions=available_actions,
)
agent_graph.add_agent(agent_1)
agent_2 = SocialAgent(
agent_id=1,
user_info=UserInfo(
user_name="bubble",
name="Bob",
description="A boy",
profile=None,
recsys_type="reddit",
),
agent_graph=agent_graph,
model=openai_model,
available_actions=available_actions,
)
agent_graph.add_agent(agent_2)
# Define the path to the database
db_path = "./data/reddit_simulation.db"
# Delete the old database
if os.path.exists(db_path):
os.remove(db_path)
# Make the environment
env = oasis.make(
agent_graph=agent_graph,
platform=oasis.DefaultPlatformType.REDDIT,
database_path=db_path,
)
# Run the environment
await env.reset()
# Sign up the profuct
await env.platform.sign_up_product(product_id=1, product_name="GlowPod")
for _ in range(5):
actions = {
agent: LLMAction()
for _, agent in env.agent_graph.get_agents()
}
await env.step(actions)
# Close the environment
await env.close()
if __name__ == "__main__":
asyncio.run(main())