🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
Improve task specifier (#26)
Guohao Lie590db4afb3e
diff --git a/camel/agent.py b/camel/agent.pyindex f8bf30e15..fcd8fcfc4 100644--- a/camel/agent.py+++ b/camel/agent.py@@ -135,14 +135,24 @@ class TaskSpecifyAgent(ChatAgent):system_message = SystemMessage(role_name="task_specifier",role_type=RoleType.ASSISTANT,- content="You can specify a task for the assistant to perform.",+ content="You can make a task more specific.",)super().__init__(system_message, model, model_config)- def specify_task(self, original_task_prompt: str) -> str:+ def specify_task(+ self,+ original_task_prompt: str,+ role_names: Optional[List[str]] = None,+ ) -> str:self.reset()self.task_specify_prompt = self.task_specify_prompt.replace("<TASK>", original_task_prompt)++ # TODO: This is a hacky way to replace the role names.+ if role_names is not None:+ self.task_specify_prompt = self.task_specify_prompt.replace(+ "<ASSISTANT_ROLE>",+ role_names[0]).replace("<USER_ROLE>", role_names[1])task_msg = UserChatMessage(role_name="task_specifier",content=self.task_specify_prompt)specified_task_msgs, terminated, _ = self.step(task_msg)@@ -169,8 +179,9 @@ class RolePlaying:) -> None:if with_task_specify:task_specify_agent = TaskSpecifyAgent(- ModeType.GPT_3_5_TURBO, ChatGPTConfig(temperature=1.4))- task_prompt = task_specify_agent.specify_task(task_prompt)+ ModeType.GPT_3_5_TURBO, ChatGPTConfig(temperature=1.0))+ task_prompt = task_specify_agent.specify_task(+ task_prompt, [assistant_role_name, user_role_name])self.task_prompt = task_promptsys_msg_generator = SystemMessageGenerator(with_task=with_task)diff --git a/examples/role_playing_multiprocess.py b/examples/role_playing_multiprocess.pyindex 11b8cf6d5..873bebd49 100644--- a/examples/role_playing_multiprocess.py+++ b/examples/role_playing_multiprocess.py@@ -5,8 +5,12 @@ import osfrom camel.agent import ChatAgent, TaskSpecifyAgentfrom camel.configs import ChatGPTConfigfrom camel.generator import SystemMessageGenerator-from camel.message import (AssistantChatMessage, AssistantSystemMessage,- UserChatMessage, UserSystemMessage)+from camel.message import (+ AssistantChatMessage,+ AssistantSystemMessage,+ UserChatMessage,+ UserSystemMessage,+)from camel.typing import ModeType, RoleType@@ -44,7 +48,7 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,task_specify_agent = TaskSpecifyAgent(ModeType.GPT_3_5_TURBO,ChatGPTConfig(temperature=1.4))specified_task_prompt = task_specify_agent.specify_task(- original_task_prompt)+ original_task_prompt, [assistant_role_name, user_role_name])print(f"Original Task: {original_task_prompt}")print(f"Specfied Task: {specified_task_prompt}")sys_msg_generator = SystemMessageGenerator(with_task=True)diff --git a/prompts/assistant_prompt.txt b/prompts/assistant_prompt.txtindex dba2099fd..9937030ad 100644--- a/prompts/assistant_prompt.txt+++ b/prompts/assistant_prompt.txt@@ -1,4 +1,5 @@-Never forget you are a <ASSISTANT_ROLE> and I am a <USER_ROLE>. I must instruct you based on your expertise and my needs to perform any tasks or answer any questions in the following two ways:+Never forget you are a <ASSISTANT_ROLE> and I am a <USER_ROLE>. Never flip roles!+I must instruct you based on your expertise and my needs to perform any tasks or answer any questions in the following two ways:1. Instruct with a necessary input:Instruction: <MY_INSTRUCTION>@@ -10,6 +11,7 @@ Input: NoneThe "Instruction" describes a task or question. The paired "Input" provides further context or information for the requested "Instruction".+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.Now I must start to instruct you using the two ways described above.diff --git a/prompts/assistant_prompt_with_task.txt b/prompts/assistant_prompt_with_task.txtindex 6dbef5d37..6a8204e3f 100644--- a/prompts/assistant_prompt_with_task.txt+++ b/prompts/assistant_prompt_with_task.txt@@ -1,8 +1,8 @@Never forget you are a <ASSISTANT_ROLE> and I am a <USER_ROLE>. Never flip roles!-We share a common interest in collaborating to successfully complete a task in the minimum number of steps.+We share a common interest in collaborating to successfully complete a task.You must help me to complete the task.Here is the task: <TASK>. Never forget our task!-I must instruct you based on your expertise and my needs to complete the task in the following two ways:+I must instruct you based on your expertise and my needs to complete the task in the following two ways:1. Instruct with a necessary input:Instruction: <MY_INSTRUCTION>@@ -14,6 +14,7 @@ Input: NoneThe "Instruction" describes a task or question. The paired "Input" provides further context or information for the requested "Instruction".+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.Now I must start to instruct you using the two ways described above.diff --git a/prompts/task_specify_prompt.txt b/prompts/task_specify_prompt.txtindex 2e0eacb4c..f3eba7bac 100644--- a/prompts/task_specify_prompt.txt+++ b/prompts/task_specify_prompt.txt@@ -1,2 +1,2 @@-Here is a task: <TASK>. Please make it more specific? Be creative and imaginative.+Here is a task that <ASSISTANT_ROLE> will help <USER_ROLE> to complete: <TASK>. Please make it more specific. Be creative and imaginative.Please reply with the specified task in <WORD_LIMIT> words or less. Do not add anything else.\ No newline at end of filediff --git a/prompts/user_prompt.txt b/prompts/user_prompt.txtindex b9e6772e3..2a5f11c5f 100644--- a/prompts/user_prompt.txt+++ b/prompts/user_prompt.txt@@ -1,4 +1,5 @@-Never forget you are a <USER_ROLE> and I am a <ASSISTANT_ROLE>. You must instruct me based on my expertise and your needs to perform any tasks or ask any questions in the following two ways:+Never forget you are a <USER_ROLE> and I am a <ASSISTANT_ROLE>. Never flip roles!+You must instruct me based on my expertise and your needs to perform any tasks or ask any questions in the following two ways:1. Instruct with a necessary input:Instruction: <YOUR_INSTRUCTION>@@ -10,6 +11,7 @@ Input: NoneThe "Instruction" describes a task or question. The paired "Input" provides further context or information for the requested "Instruction".+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.Now you must start to instruct me using the two ways described above.diff --git a/prompts/user_prompt_with_task.txt b/prompts/user_prompt_with_task.txtindex 84562dada..601253cfa 100644--- a/prompts/user_prompt_with_task.txt+++ b/prompts/user_prompt_with_task.txt@@ -1,8 +1,8 @@Never forget you are a <USER_ROLE> and I am a <ASSISTANT_ROLE>. Never flip roles!-We share a common interest in collaborating to successfully complete a task in the minimum number of steps.+We share a common interest in collaborating to successfully complete a task.I must help you to complete the task.Here is the task: <TASK>. Never forget our task!-You must instruct me based on my expertise and your needs to complete the task in the following two ways:+You must instruct me based on my expertise and your needs to complete the task in the following two ways:1. Instruct with a necessary input:Instruction: <YOUR_INSTRUCTION>@@ -14,6 +14,7 @@ Input: NoneThe "Instruction" describes a task or question. The paired "Input" provides further context or information for the requested "Instruction".+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.Now you must start to instruct me using the two ways described above.diff --git a/test/test_chat_agent.py b/test/test_chat_agent.pyindex 53f0cc953..67f908535 100644--- a/test/test_chat_agent.py+++ b/test/test_chat_agent.py@@ -40,10 +40,10 @@ def test_chat_agent():def test_task_specify_agent():- original_task_prompt = "Developing custom game mods or plugins"+ original_task_prompt = "Improving stage presence and performance skills."print(f"Original task prompt:\n{original_task_prompt}\n")task_specify_agent = TaskSpecifyAgent(- ModeType.GPT_3_5_TURBO, model_config=ChatGPTConfig(temperature=1.4))+ ModeType.GPT_3_5_TURBO, model_config=ChatGPTConfig(temperature=1.0))specified_task_prompt = task_specify_agent.specify_task(- original_task_prompt)+ original_task_prompt, ["Musician", "Student"])print(f"Specified task prompt:\n{specified_task_prompt}\n")