Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

Fix `TaskPlannerAgent` and improving prompts (#31)

Guohao Libf33adb330e7
diff --git a/camel/agent/role_playing.py b/camel/agent/role_playing.py
index f61429d48..4e056270c 100644
--- a/camel/agent/role_playing.py
+++ b/camel/agent/role_playing.py
@@ -1,12 +1,11 @@
from typing import Dict, List, Optional, Tuple
-from camel.configs import ChatGPTConfig
from camel.generator import SystemMessageGenerator
from camel.message import AssistantChatMessage, ChatMessage, UserChatMessage
from camel.typing import ModeType, RoleType
from .chat_agent import ChatAgent
-from .task_agent import TaskSpecifyAgent
+from .task_agent import TaskPlannerAgent, TaskSpecifyAgent
class RolePlaying:
@@ -19,18 +18,34 @@ class RolePlaying:
task_prompt: str = "",
with_task: bool = True,
with_task_specify: bool = True,
+ with_task_planner: bool = True,
mode_type: ModeType = ModeType.GPT_3_5_TURBO,
assistant_agent_kwargs: Optional[Dict] = None,
user_agent_kwargs: Optional[Dict] = None,
+ task_specify_agent_kwargs: Optional[Dict] = None,
+ task_planner_agent_kwargs: Optional[Dict] = None,
) -> None:
if with_task_specify:
task_specify_agent = TaskSpecifyAgent(
- ModeType.GPT_3_5_TURBO, ChatGPTConfig(temperature=1.0))
- task_prompt = task_specify_agent.specify_task(
+ ModeType.GPT_3_5_TURBO,
+ **(task_specify_agent_kwargs or {}),
+ )
+ self.specified_task_prompt = task_specify_agent.specify_task(
task_prompt,
[("<ASSISTANT_ROLE>", assistant_role_name),
("<USER_ROLE>", user_role_name)],
)
+ task_prompt = self.specified_task_prompt
+
+ if with_task_planner:
+ task_planner_agent = TaskPlannerAgent(
+ ModeType.GPT_3_5_TURBO,
+ **(task_planner_agent_kwargs or {}),
+ )
+ self.planned_task_prompt = task_planner_agent.plan_task(
+ task_prompt)
+ task_prompt = f"{task_prompt}\n{self.planned_task_prompt}"
+
self.task_prompt = task_prompt
sys_msg_generator = SystemMessageGenerator(with_task=with_task)
diff --git a/camel/agent/task_agent.py b/camel/agent/task_agent.py
index 56c14499d..e9118c989 100644
--- a/camel/agent/task_agent.py
+++ b/camel/agent/task_agent.py
@@ -1,6 +1,7 @@
from typing import Any, List, Optional, Tuple
from camel.agent import ChatAgent
+from camel.configs import ChatGPTConfig
from camel.message import SystemMessage, UserChatMessage
from camel.typing import ModeType, RoleType, TaskType
@@ -30,6 +31,8 @@ class TaskSpecifyAgent(ChatAgent):
else:
self.task_specify_prompt = task_specify_prompt
+ model_config = model_config or ChatGPTConfig(temperature=1.0)
+
system_message = SystemMessage(
role_name="task_specifier",
role_type=RoleType.ASSISTANT,
@@ -72,7 +75,8 @@ class TaskPlannerAgent(ChatAgent):
model_config: Any = None,
) -> None:
- self.task_planner_prompt = "Divide this task into subtasks: <TASK>"
+ self.task_planner_prompt = (
+ "Divide this task into subtasks: <TASK>. Be concise.")
system_message = SystemMessage(
role_name="task_planner",
@@ -92,10 +96,10 @@ class TaskPlannerAgent(ChatAgent):
task_msg = UserChatMessage(role_name="task_specifier",
content=self.task_planner_prompt)
- specified_task_msgs, terminated, _ = self.step(task_msg)
- specified_task_msg = specified_task_msgs[0]
+ sub_tasks_msgs, terminated, _ = self.step(task_msg)
+ sub_tasks_msg = sub_tasks_msgs[0]
if terminated:
- raise RuntimeError("Task specification failed.")
+ raise RuntimeError("Task planning failed.")
else:
- return specified_task_msg.content
+ return sub_tasks_msg.content
diff --git a/examples/ai_society/role_playing.py b/examples/ai_society/role_playing.py
index eb3df7b26..973d724df 100644
--- a/examples/ai_society/role_playing.py
+++ b/examples/ai_society/role_playing.py
@@ -12,12 +12,24 @@ def print_text_animated(text):
def main() -> None:
- task_prompt = "Coding with Python Programming Language."
+ task_prompt = "Develop a trading bot for the stock market"
+ role_play_session = RolePlaying("Python Programmer", "Stock Trader",
+ task_prompt, with_task_specify=True,
+ with_task_planner=True)
+
+ 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")
- role_play_session = RolePlaying("Python coder", "Student", task_prompt,
- with_task_specify=False)
- print(Fore.CYAN +
- f"Specified task prompt:\n{role_play_session.task_prompt}\n")
+ print(
+ Fore.CYAN +
+ f"Specified task prompt:\n{role_play_session.specified_task_prompt}\n")
+ print(Fore.MAGENTA +
+ f"Planned task prompt:\n{role_play_session.planned_task_prompt}\n")
+ print(Fore.RED + f"Final task prompt:\n{role_play_session.task_prompt}\n")
chat_turn_limit, n = 50, 0
assistant_msg, _ = role_play_session.init_chat()
@@ -29,7 +41,7 @@ def main() -> None:
print_text_animated(Fore.GREEN +
f"AI Assistant:\n\n{assistant_msg.content}\n\n")
- if "<CAMEL_TASK_DONE>" in assistant_msg.content:
+ if "<CAMEL_TASK_DONE>" in user_msg.content:
break
diff --git a/prompts/ai_society/assistant_prompt.txt b/prompts/ai_society/assistant_prompt.txt
index 9937030ad..63bcf1f3a 100644
--- a/prompts/ai_society/assistant_prompt.txt
+++ b/prompts/ai_society/assistant_prompt.txt
@@ -13,6 +13,6 @@ The "Instruction" describes a task or question. The paired "Input" provides furt
I must give you one instruction at a time.
You must write a response that appropriately completes the requested instruction.
-You must decline my instruction politely and honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.
+You must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.
Now I must start to instruct you using the two ways described above.
Do not add anything else other than your response to my instruction.
\ No newline at end of file
diff --git a/prompts/ai_society/assistant_prompt_with_task.txt b/prompts/ai_society/assistant_prompt_with_task.txt
index c3e4bc56c..b953c8a86 100644
--- a/prompts/ai_society/assistant_prompt_with_task.txt
+++ b/prompts/ai_society/assistant_prompt_with_task.txt
@@ -5,8 +5,15 @@ Here is the task: <TASK>. Never forget our task!
I must instruct you based on your expertise and my needs to complete the task.
I must give you one instruction at a time.
-You must write a response that appropriately completes the requested instruction.
-You must decline my instruction politely and honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.
+You must write a solution that appropriately completes the requested instruction.
+You must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.
Now I must start to instruct you using the two ways described above.
-Do not add anything else other than your response to my instruction.
-You are never supposed to ask me any questions you only answer questions.
\ No newline at end of file
+Do not add anything else other than your solution to my instruction.
+You are never supposed to ask me any questions you only answer questions.
+You are never supposed to reply a flake solution. Just do it now!
+You solution must be declarative sentence and simple present tense.
+Unless I say the task is completed, you should always start with:
+
+Solution: <YOUR_SOLUTION>
+
+, and end with: Next instruction.
diff --git a/prompts/ai_society/generate_tasks.txt b/prompts/ai_society/generate_tasks.txt
index f976993cb..2e8f18f2b 100644
--- a/prompts/ai_society/generate_tasks.txt
+++ b/prompts/ai_society/generate_tasks.txt
@@ -1 +1 @@
-List <NUM_TASKS> diverse tasks that a programmer can assist a person working in <DOMAIN> using <LANGUAGE>. Be concise. Be creative.
\ No newline at end of file
+List <NUM_TASKS> diverse tasks that <ROLE_1> can assist <ROLE_2> cooperatively to achieve together. Be concise. Be creative.
\ No newline at end of file
diff --git a/prompts/ai_society/user_prompt.txt b/prompts/ai_society/user_prompt.txt
index 2a5f11c5f..501ad1df3 100644
--- a/prompts/ai_society/user_prompt.txt
+++ b/prompts/ai_society/user_prompt.txt
@@ -13,7 +13,7 @@ The "Instruction" describes a task or question. The paired "Input" provides furt
You must give me one instruction at a time.
I must write a response that appropriately completes the requested instruction.
-I must decline your instruction politely and honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.
+I must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.
Now you must start to instruct me using the two ways described above.
Do not add anything else other than your instruction and the optional corresponding input!
Keep giving me instructions and necessary inputs. Do not stopping!
\ No newline at end of file
diff --git a/prompts/ai_society/user_prompt_with_task.txt b/prompts/ai_society/user_prompt_with_task.txt
index 972834f28..1fa897190 100644
--- a/prompts/ai_society/user_prompt_with_task.txt
+++ b/prompts/ai_society/user_prompt_with_task.txt
@@ -16,7 +16,7 @@ The "Instruction" describes a task or question. The paired "Input" provides furt
You must give me one instruction at a time.
I must write a response that appropriately completes the requested instruction.
-I must decline your instruction politely and honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.
+I must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.
Now you must start to instruct me using the two ways described above.
Do not add anything else other than your instruction and the optional corresponding input!
Keep giving me instructions and necessary inputs until you think the task is completed.