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 conditions for termination (#30)

Hasan Abed Al Kader Hammoud9702a6bf0ee3
diff --git a/examples/ai_society/role_playing_multiprocess.py b/examples/ai_society/role_playing_multiprocess.py
index 00e3adc05..fe98f9bf5 100644
--- a/examples/ai_society/role_playing_multiprocess.py
+++ b/examples/ai_society/role_playing_multiprocess.py
@@ -5,12 +5,8 @@ import os
from camel.agent import ChatAgent, TaskSpecifyAgent
from camel.configs import ChatGPTConfig
from 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
@@ -42,9 +38,11 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,
user_role_name: str, task_idx: int,
task_prompt: str) -> None:
- max_num_messages = 30
+ max_num_messages = 40
+
+ # Remove number from task prompt
+ original_task_prompt = task_prompt.replace(f"{task_idx+1}. ", "")
- original_task_prompt = task_prompt
task_specify_agent = TaskSpecifyAgent(ModeType.GPT_3_5_TURBO,
ChatGPTConfig(temperature=1.4))
specified_task_prompt = task_specify_agent.specify_task(
@@ -77,16 +75,14 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,
message_dict["role_2"] = f"{user_role_name}_{str(user_agent.role_type)}"
message_dict[
"id"] = f"{(assistant_idx+1):03}_{(user_idx+1):03}_{(task_idx+1):03}"
- message_dict["original_task"] = task_prompt.replace(f"{task_idx+1}. ", "")
- message_dict["specified_task"] = specified_task_prompt.replace(
- f"{task_idx+1}. ", "")
+ message_dict["original_task"] = original_task_prompt
+ message_dict["specified_task"] = specified_task_prompt
# Threshold to terminate the conversation if no end token appears
repeat_word_counter = 0
repeat_word_threshold = 4
repeat_word_list = [
- "goodbye", "good bye", "thank", "bye", "welcome",
- "As an AI language model,"
+ "goodbye", "good bye", "thank", "bye", "welcome", "language model"
]
assistant_instruct_counter = 0
@@ -129,12 +125,14 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,
assistant_msg.role = "user"
# Condition 3: Break if user does not give instruction
- if user_no_instruct_word in user_msg.content:
+ if user_no_instruct_word not in user_msg.content:
user_no_instruct_counter += 1
if user_no_instruct_counter == user_no_instruct_threshold:
message_dict[
'termination_reason'] = "user_no_instruct_threshold"
break
+ else:
+ user_no_instruct_counter = 0
# Condition 4: Break if assistant gives instruction (flipped role)
if assistant_instruct_word in assistant_msg.content:
@@ -143,6 +141,8 @@ def generate_data(assistant_idx: int, assistant_role_name: str, user_idx: int,
message_dict[
'termination_reason'] = "assistant_instruct_threshold"
break
+ else:
+ assistant_instruct_counter = 0
# Condition 5: Repeat word observed
for repeat_word in repeat_word_list:
diff --git a/prompts/ai_society/assistant_prompt_with_task.txt b/prompts/ai_society/assistant_prompt_with_task.txt
index 6a8204e3f..c3e4bc56c 100644
--- a/prompts/ai_society/assistant_prompt_with_task.txt
+++ b/prompts/ai_society/assistant_prompt_with_task.txt
@@ -1,22 +1,12 @@
-Never forget you are a <ASSISTANT_ROLE> and I am a <USER_ROLE>. Never flip roles!
+Never forget you are a <ASSISTANT_ROLE> and I am a <USER_ROLE>. Never flip roles! Never instruct me!
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:
-
-1. Instruct with a necessary input:
-Instruction: <MY_INSTRUCTION>
-Input: <MY_INPUT>
-
-2. Instruct without any input:
-Instruction: <MY_INSTRUCTION>
-Input: None
-
-The "Instruction" describes a task or question. The paired "Input" provides further context or information for the requested "Instruction".
+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.
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
+You are never supposed to ask me any questions you only answer questions.
\ 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 601253cfa..972834f28 100644
--- a/prompts/ai_society/user_prompt_with_task.txt
+++ b/prompts/ai_society/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!
+Never forget you are a <USER_ROLE> and I am a <ASSISTANT_ROLE>. Never flip roles! You will always instruct me.
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:
+At all time you must instruct me based on my expertise and your needs to complete the task ONLY in the following two ways:
1. Instruct with a necessary input:
Instruction: <YOUR_INSTRUCTION>