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

Refactor agents and add `TaskPlannerAgent` and `TaskType` (#29)

Guohao Lie493c11c3250
diff --git a/camel/__init__.py b/camel/__init__.py
index d94b16404..e8e247b79 100644
--- a/camel/__init__.py
+++ b/camel/__init__.py
@@ -1,4 +1,4 @@
-from .agent import ChatAgent, TaskSpecifyAgent
+from .agent import ChatAgent, RolePlaying, TaskPlannerAgent, TaskSpecifyAgent
from .configs import ChatGPTConfig
from .generator import (
AISocietyTaskPromptGenerator,
@@ -21,6 +21,8 @@ __all__ = [
'ChatGPTConfig',
'ChatAgent',
'TaskSpecifyAgent',
+ 'TaskPlannerAgent',
+ 'RolePlaying',
'SystemMessageGenerator',
'RoleNameGenerator',
'AISocietyTaskPromptGenerator',
diff --git a/camel/agent.py b/camel/agent.py
deleted file mode 100644
index fcd8fcfc4..000000000
--- a/camel/agent.py
+++ /dev/null
@@ -1,241 +0,0 @@
-from typing import Any, Dict, List, Optional, Tuple
-
-import openai
-from tenacity import retry, stop_after_attempt, wait_exponential
-
-from camel.configs import ChatGPTConfig
-from camel.generator import SystemMessageGenerator
-from camel.message import (
- AssistantChatMessage,
- ChatMessage,
- MessageType,
- SystemMessage,
- UserChatMessage,
-)
-from camel.typing import ModeType, RoleType
-from camel.utils import get_model_token_limit, num_tokens_from_messages
-
-
-class ChatAgent:
-
- def __init__(
- self,
- system_message: SystemMessage,
- model: ModeType,
- model_config: Any = None,
- message_window_size: Optional[int] = None,
- ) -> None:
- self.system_message = system_message
- self.role_name = system_message.role_name
- self.role_type = system_message.role_type
-
- self.model = model
- self.model_config = model_config or ChatGPTConfig()
- self.model_token_limit = get_model_token_limit(self.model)
- self.message_window_size = message_window_size
-
- self.terminated = False
- self.init_messages()
-
- def reset(self) -> None:
- self.terminated = False
- self.init_messages()
- return self.stored_messages
-
- def get_info(
- self,
- id: Optional[str],
- usage: Optional[Dict[str, int]],
- finish_reasons: List[str],
- num_tokens: int,
- ) -> Dict[str, Any]:
- return {
- "id": id,
- "usage": usage,
- "finish_reasons": finish_reasons,
- "num_tokens": num_tokens,
- }
-
- def init_messages(self) -> None:
- self.stored_messages: List[MessageType] = [self.system_message]
-
- def update_messages(self, message: ChatMessage) -> List[ChatMessage]:
- self.stored_messages.append(message)
- return self.stored_messages
-
- @retry(wait=wait_exponential(min=5, max=60), stop=stop_after_attempt(5))
- def step(
- self,
- input_message: ChatMessage,
- ) -> Tuple[List[ChatMessage], bool, Dict[str, Any]]:
- messages = self.update_messages(input_message)
- if self.message_window_size is not None and len(
- messages) > self.message_window_size:
- messages = [self.system_message
- ] + messages[-self.message_window_size:]
- openai_messages = [message.to_openai_message() for message in messages]
- num_tokens = num_tokens_from_messages(openai_messages, self.model)
-
- if num_tokens < self.model_token_limit:
- response = openai.ChatCompletion.create(
- model=self.model.value,
- messages=openai_messages,
- **self.model_config.__dict__,
- )
- output_messages = [
- ChatMessage(self.role_name, self.role_type,
- **dict(choice["message"]))
- for choice in response["choices"]
- ]
- info = self.get_info(
- response["id"],
- response["usage"],
- [
- str(choice["finish_reason"])
- for choice in response["choices"]
- ],
- num_tokens,
- )
- self.update_messages(output_messages[0])
-
- else:
- self.terminated = True
- output_messages = []
-
- info = self.get_info(
- None,
- None,
- ["max_tokens_exceeded"],
- num_tokens,
- )
-
- return output_messages, self.terminated, info
-
- def __repr__(self) -> str:
- return f"ChatAgent({self.role_name}, {self.role_type}, {self.model})"
-
-
-class TaskSpecifyAgent(ChatAgent):
-
- def __init__(
- self,
- model: ModeType,
- model_config: Any = None,
- task_specify_prompt: Optional[str] = None,
- task_specify_prompt_path: str = "prompts/task_specify_prompt.txt",
- word_limit: int = 50,
- ) -> None:
- if task_specify_prompt is None:
- with open(task_specify_prompt_path, "r") as f:
- self.task_specify_prompt = f.read().replace(
- "<WORD_LIMIT>", str(word_limit))
- else:
- self.task_specify_prompt = task_specify_prompt
-
- system_message = SystemMessage(
- role_name="task_specifier",
- role_type=RoleType.ASSISTANT,
- content="You can make a task more specific.",
- )
- super().__init__(system_message, model, model_config)
-
- 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)
- specified_task_msg = specified_task_msgs[0]
-
- if terminated:
- raise RuntimeError("Task specification failed.")
- else:
- return specified_task_msg.content
-
-
-class RolePlaying:
-
- def __init__(
- self,
- assistant_role_name: str,
- user_role_name: str,
- task_prompt: str = "",
- with_task: bool = True,
- with_task_specify: bool = True,
- mode_type: ModeType = ModeType.GPT_3_5_TURBO,
- assistant_agent_kwargs: Optional[Dict] = None,
- user_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(
- task_prompt, [assistant_role_name, user_role_name])
- self.task_prompt = task_prompt
-
- sys_msg_generator = SystemMessageGenerator(with_task=with_task)
- self.assistant_sys_msg, self.user_sys_msg = (
- sys_msg_generator.from_roles(
- roles=[
- (assistant_role_name, RoleType.ASSISTANT),
- (user_role_name, RoleType.USER),
- ], task_prompt=task_prompt))
-
- self.assistant_agent = ChatAgent(
- self.assistant_sys_msg,
- mode_type,
- **(assistant_agent_kwargs or {}),
- )
- self.user_agent = ChatAgent(
- self.user_sys_msg,
- mode_type,
- **(user_agent_kwargs or {}),
- )
-
- def init_chat(self) -> Tuple[AssistantChatMessage, List[ChatMessage]]:
- self.assistant_agent.reset()
- self.user_agent.reset()
-
- # Send the system messages again to the agents using chat messages
- assistant_msg = AssistantChatMessage(
- self.assistant_agent.role_name,
- content=(f"{self.user_sys_msg.content}. "
- "Now start to give me introductions one by one. "
- "Only reply with Instruction and Input."))
- assistant_msg.role = "user"
-
- user_msg = UserChatMessage(self.user_sys_msg.role_name,
- content=f"{self.assistant_sys_msg.content}")
- msgs, _, _ = self.assistant_agent.step(user_msg)
-
- return assistant_msg, msgs
-
- def step(
- self,
- assistant_msg: ChatMessage,
- ) -> Tuple[ChatMessage, ChatMessage]:
- user_msgs, user_terminated, _ = self.user_agent.step(assistant_msg)
- if user_terminated:
- raise RuntimeError("User agent is terminated.")
- user_msg = user_msgs[0]
- user_msg.role = "user"
-
- assistant_msgs, assistant_terminated, _ = self.assistant_agent.step(
- user_msg)
- if assistant_terminated:
- raise RuntimeError("Assistant agent is terminated.")
- assistant_msg = assistant_msgs[0]
- assistant_msg.role = "user"
-
- return assistant_msg, user_msg
diff --git a/camel/agent/__init__.py b/camel/agent/__init__.py
new file mode 100644
index 000000000..a6766998f
--- /dev/null
+++ b/camel/agent/__init__.py
@@ -0,0 +1,10 @@
+from .chat_agent import ChatAgent
+from .role_playing import RolePlaying
+from .task_agent import TaskPlannerAgent, TaskSpecifyAgent
+
+__all__ = [
+ 'ChatAgent',
+ 'TaskSpecifyAgent',
+ 'TaskPlannerAgent',
+ 'RolePlaying',
+]
diff --git a/camel/agent/chat_agent.py b/camel/agent/chat_agent.py
new file mode 100644
index 000000000..6cabca8df
--- /dev/null
+++ b/camel/agent/chat_agent.py
@@ -0,0 +1,108 @@
+from typing import Any, Dict, List, Optional, Tuple
+
+import openai
+from tenacity import retry, stop_after_attempt, wait_exponential
+
+from camel.configs import ChatGPTConfig
+from camel.message import ChatMessage, MessageType, SystemMessage
+from camel.typing import ModeType
+from camel.utils import get_model_token_limit, num_tokens_from_messages
+
+
+class ChatAgent:
+
+ def __init__(
+ self,
+ system_message: SystemMessage,
+ model: ModeType,
+ model_config: Any = None,
+ message_window_size: Optional[int] = None,
+ ) -> None:
+ self.system_message = system_message
+ self.role_name = system_message.role_name
+ self.role_type = system_message.role_type
+
+ self.model = model
+ self.model_config = model_config or ChatGPTConfig()
+ self.model_token_limit = get_model_token_limit(self.model)
+ self.message_window_size = message_window_size
+
+ self.terminated = False
+ self.init_messages()
+
+ def reset(self) -> None:
+ self.terminated = False
+ self.init_messages()
+ return self.stored_messages
+
+ def get_info(
+ self,
+ id: Optional[str],
+ usage: Optional[Dict[str, int]],
+ finish_reasons: List[str],
+ num_tokens: int,
+ ) -> Dict[str, Any]:
+ return {
+ "id": id,
+ "usage": usage,
+ "finish_reasons": finish_reasons,
+ "num_tokens": num_tokens,
+ }
+
+ def init_messages(self) -> None:
+ self.stored_messages: List[MessageType] = [self.system_message]
+
+ def update_messages(self, message: ChatMessage) -> List[ChatMessage]:
+ self.stored_messages.append(message)
+ return self.stored_messages
+
+ @retry(wait=wait_exponential(min=5, max=60), stop=stop_after_attempt(5))
+ def step(
+ self,
+ input_message: ChatMessage,
+ ) -> Tuple[List[ChatMessage], bool, Dict[str, Any]]:
+ messages = self.update_messages(input_message)
+ if self.message_window_size is not None and len(
+ messages) > self.message_window_size:
+ messages = [self.system_message
+ ] + messages[-self.message_window_size:]
+ openai_messages = [message.to_openai_message() for message in messages]
+ num_tokens = num_tokens_from_messages(openai_messages, self.model)
+
+ if num_tokens < self.model_token_limit:
+ response = openai.ChatCompletion.create(
+ model=self.model.value,
+ messages=openai_messages,
+ **self.model_config.__dict__,
+ )
+ output_messages = [
+ ChatMessage(self.role_name, self.role_type,
+ **dict(choice["message"]))
+ for choice in response["choices"]
+ ]
+ info = self.get_info(
+ response["id"],
+ response["usage"],
+ [
+ str(choice["finish_reason"])
+ for choice in response["choices"]
+ ],
+ num_tokens,
+ )
+ self.update_messages(output_messages[0])
+
+ else:
+ self.terminated = True
+ output_messages = []
+
+ info = self.get_info(
+ None,
+ None,
+ ["max_tokens_exceeded"],
+ num_tokens,
+ )
+
+ return output_messages, self.terminated, info
+
+ def __repr__(self) -> str:
+ return f"ChatAgent({self.role_name}, {self.role_type}, {self.model})"
diff --git a/camel/agent/role_playing.py b/camel/agent/role_playing.py
new file mode 100644
index 000000000..f61429d48
--- /dev/null
+++ b/camel/agent/role_playing.py
@@ -0,0 +1,90 @@
+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
+
+
+class RolePlaying:
+ """Role playing between two agents."""
+
+ def __init__(
+ self,
+ assistant_role_name: str,
+ user_role_name: str,
+ task_prompt: str = "",
+ with_task: bool = True,
+ with_task_specify: bool = True,
+ mode_type: ModeType = ModeType.GPT_3_5_TURBO,
+ assistant_agent_kwargs: Optional[Dict] = None,
+ user_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(
+ task_prompt,
+ [("<ASSISTANT_ROLE>", assistant_role_name),
+ ("<USER_ROLE>", user_role_name)],
+ )
+ self.task_prompt = task_prompt
+
+ sys_msg_generator = SystemMessageGenerator(with_task=with_task)
+ self.assistant_sys_msg, self.user_sys_msg = (
+ sys_msg_generator.from_roles(
+ roles=[
+ (assistant_role_name, RoleType.ASSISTANT),
+ (user_role_name, RoleType.USER),
+ ], task_prompt=task_prompt))
+
+ self.assistant_agent = ChatAgent(
+ self.assistant_sys_msg,
+ mode_type,
+ **(assistant_agent_kwargs or {}),
+ )
+ self.user_agent = ChatAgent(
+ self.user_sys_msg,
+ mode_type,
+ **(user_agent_kwargs or {}),
+ )
+
+ def init_chat(self) -> Tuple[AssistantChatMessage, List[ChatMessage]]:
+ self.assistant_agent.reset()
+ self.user_agent.reset()
+
+ # Send the system messages again to the agents using chat messages
+ assistant_msg = AssistantChatMessage(
+ self.assistant_agent.role_name,
+ content=(f"{self.user_sys_msg.content}. "
+ "Now start to give me introductions one by one. "
+ "Only reply with Instruction and Input."))
+ assistant_msg.role = "user"
+
+ user_msg = UserChatMessage(self.user_sys_msg.role_name,
+ content=f"{self.assistant_sys_msg.content}")
+ msgs, _, _ = self.assistant_agent.step(user_msg)
+
+ return assistant_msg, msgs
+
+ def step(
+ self,
+ assistant_msg: ChatMessage,
+ ) -> Tuple[ChatMessage, ChatMessage]:
+ user_msgs, user_terminated, _ = self.user_agent.step(assistant_msg)
+ if user_terminated:
+ raise RuntimeError("User agent is terminated.")
+ user_msg = user_msgs[0]
+ user_msg.role = "user"
+
+ assistant_msgs, assistant_terminated, _ = self.assistant_agent.step(
+ user_msg)
+ if assistant_terminated:
+ raise RuntimeError("Assistant agent is terminated.")
+ assistant_msg = assistant_msgs[0]
+ assistant_msg.role = "user"
+
+ return assistant_msg, user_msg
diff --git a/camel/agent/task_agent.py b/camel/agent/task_agent.py
new file mode 100644
index 000000000..56c14499d
--- /dev/null
+++ b/camel/agent/task_agent.py
@@ -0,0 +1,101 @@
+from typing import Any, List, Optional, Tuple
+
+from camel.agent import ChatAgent
+from camel.message import SystemMessage, UserChatMessage
+from camel.typing import ModeType, RoleType, TaskType
+
+
+class TaskSpecifyAgent(ChatAgent):
+
+ def __init__(
+ self,
+ model: ModeType,
+ task_type: TaskType = TaskType.AI_SOCIETY,
+ model_config: Any = None,
+ task_specify_prompt: Optional[str] = None,
+ word_limit: int = 50,
+ ) -> None:
+ if task_specify_prompt is None:
+ if task_type == TaskType.AI_SOCIETY:
+ task_specify_prompt_path = (
+ "prompts/ai_society/task_specify_prompt.txt")
+
+ if task_type == TaskType.CODE:
+ task_specify_prompt_path = (
+ "prompts/code/task_specify_prompt.txt")
+
+ with open(task_specify_prompt_path, "r") as f:
+ self.task_specify_prompt = f.read().replace(
+ "<WORD_LIMIT>", str(word_limit))
+ else:
+ self.task_specify_prompt = task_specify_prompt
+
+ system_message = SystemMessage(
+ role_name="task_specifier",
+ role_type=RoleType.ASSISTANT,
+ content="You can make a task more specific.",
+ )
+ super().__init__(system_message, model, model_config)
+
+ def specify_task(
+ self,
+ original_task_prompt: str,
+ replace_tuples: Optional[List[Tuple[str, 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 replace_tuples is not None:
+ for replace_tuple in replace_tuples:
+ self.task_specify_prompt = self.task_specify_prompt.replace(
+ replace_tuple[0], replace_tuple[1])
+ print(self.task_specify_prompt)
+ assert "<" and ">" not in self.task_specify_prompt
+ task_msg = UserChatMessage(role_name="task_specifier",
+ content=self.task_specify_prompt)
+ specified_task_msgs, terminated, _ = self.step(task_msg)
+ specified_task_msg = specified_task_msgs[0]
+
+ if terminated:
+ raise RuntimeError("Task specification failed.")
+ else:
+ return specified_task_msg.content
+
+
+class TaskPlannerAgent(ChatAgent):
+
+ def __init__(
+ self,
+ model: ModeType,
+ model_config: Any = None,
+ ) -> None:
+
+ self.task_planner_prompt = "Divide this task into subtasks: <TASK>"
+
+ system_message = SystemMessage(
+ role_name="task_planner",
+ role_type=RoleType.ASSISTANT,
+ content="You are a helpful task planner.",
+ )
+ super().__init__(system_message, model, model_config)
+
+ def plan_task(
+ self,
+ task_prompt: str,
+ ) -> str:
+ # TODO: Maybe include roles information.
+ self.reset()
+ self.task_planner_prompt = self.task_planner_prompt.replace(
+ "<TASK>", task_prompt)
+
+ 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]
+
+ if terminated:
+ raise RuntimeError("Task specification failed.")
+ else:
+ return specified_task_msg.content
diff --git a/camel/typing.py b/camel/typing.py
index 189c3f7c1..8b0c3d30f 100644
--- a/camel/typing.py
+++ b/camel/typing.py
@@ -11,4 +11,9 @@ class ModeType(Enum):
GPT_3_5_TURBO = "gpt-3.5-turbo"
-__all__ = ['RoleType', 'ModeType']
+class TaskType(Enum):
+ AI_SOCIETY = "ai_society"
+ CODE = "code"
+
+
+__all__ = ['RoleType', 'ModeType', 'TaskType']
diff --git a/examples/ai_society/role_playing_multiprocess.py b/examples/ai_society/role_playing_multiprocess.py
index 0d62546f7..00e3adc05 100644
--- a/examples/ai_society/role_playing_multiprocess.py
+++ b/examples/ai_society/role_playing_multiprocess.py
@@ -48,7 +48,10 @@ 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, [assistant_role_name, user_role_name])
+ original_task_prompt, [
+ ("<ASSISTANT_ROLE>", assistant_role_name),
+ ("<USER_ROLE>", user_role_name),
+ ])
print(f"Original Task: {original_task_prompt}")
print(f"Specified Task: {specified_task_prompt}")
sys_msg_generator = SystemMessageGenerator(with_task=True)
diff --git a/prompts/assistant_prompt.txt b/prompts/assistant_prompt.txt
deleted file mode 100644
index 9937030ad..000000000
--- a/prompts/assistant_prompt.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-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>
-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 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.
\ No newline at end of file
diff --git a/prompts/assistant_prompt_with_task.txt b/prompts/assistant_prompt_with_task.txt
deleted file mode 100644
index 6a8204e3f..000000000
--- a/prompts/assistant_prompt_with_task.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-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.
-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 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
diff --git a/prompts/code/task_specify_prompt.txt b/prompts/code/task_specify_prompt.txt
new file mode 100644
index 000000000..e68ae7814
--- /dev/null
+++ b/prompts/code/task_specify_prompt.txt
@@ -0,0 +1,3 @@
+Here is a task that a programmer will help a person working in <DOMAIN> to complete using <LANGUAGE>: <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 file
diff --git a/prompts/task_specify_prompt.txt b/prompts/task_specify_prompt.txt
deleted file mode 100644
index f3eba7bac..000000000
--- a/prompts/task_specify_prompt.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-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 file
diff --git a/prompts/user_prompt.txt b/prompts/user_prompt.txt
deleted file mode 100644
index 2a5f11c5f..000000000
--- a/prompts/user_prompt.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-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>
-Input: <YOUR_INPUT>
-
-2. Instruct without any input:
-Instruction: <YOUR_INSTRUCTION>
-Input: None
-
-The "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.
-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/user_prompt_with_task.txt b/prompts/user_prompt_with_task.txt
deleted file mode 100644
index 601253cfa..000000000
--- a/prompts/user_prompt_with_task.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-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.
-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:
-
-1. Instruct with a necessary input:
-Instruction: <YOUR_INSTRUCTION>
-Input: <YOUR_INPUT>
-
-2. Instruct without any input:
-Instruction: <YOUR_INSTRUCTION>
-Input: None
-
-The "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.
-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.
-When the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.
-Never say <CAMEL_TASK_DONE> unless my responses have solved your task.
\ No newline at end of file
diff --git a/test/test_chat_agent.py b/test/agent/test_chat_agent.py
similarity index 68%
rename from test/test_chat_agent.py
rename to test/agent/test_chat_agent.py
index 67f908535..5c843c93d 100644
--- a/test/test_chat_agent.py
+++ b/test/agent/test_chat_agent.py
@@ -1,6 +1,6 @@
import os
-from camel.agent import ChatAgent, TaskSpecifyAgent
+from camel.agent import ChatAgent
from camel.configs import ChatGPTConfig
from camel.generator import SystemMessageGenerator
from camel.message import ChatMessage
@@ -37,13 +37,3 @@ def test_chat_agent():
assert terminated is True
assert messages == []
assert info['finish_reasons'][0] == "max_tokens_exceeded"
-
-
-def test_task_specify_agent():
- 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.0))
- specified_task_prompt = task_specify_agent.specify_task(
- original_task_prompt, ["Musician", "Student"])
- print(f"Specified task prompt:\n{specified_task_prompt}\n")
diff --git a/test/agent/test_task_agent.py b/test/agent/test_task_agent.py
new file mode 100644
index 000000000..59e7a05bf
--- /dev/null
+++ b/test/agent/test_task_agent.py
@@ -0,0 +1,56 @@
+import os
+
+from camel.agent import TaskPlannerAgent, TaskSpecifyAgent
+from camel.configs import ChatGPTConfig
+from camel.typing import ModeType, TaskType
+
+assert os.environ.get("OPENAI_API_KEY") is not None, "Missing OPENAI_API_KEY"
+
+
+def test_task_specify_ai_society_agent():
+ 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.0))
+ specified_task_prompt = task_specify_agent.specify_task(
+ original_task_prompt, [
+ ("<ASSISTANT_ROLE>", "Musician"),
+ ("<USER_ROLE>", "Student"),
+ ])
+ print(f"Specified task prompt:\n{specified_task_prompt}\n")
+
+
+def test_task_specify_code_agent():
+ original_task_prompt = "Modeling molecular dynamics"
+ print(f"Original task prompt:\n{original_task_prompt}\n")
+ task_specify_agent = TaskSpecifyAgent(
+ ModeType.GPT_3_5_TURBO,
+ task_type=TaskType.CODE,
+ model_config=ChatGPTConfig(temperature=1.0),
+ )
+ specified_task_prompt = task_specify_agent.specify_task(
+ original_task_prompt, [
+ ("<DOMAIN>", "Chemistry"),
+ ("<LANGUAGE>", "Python"),
+ ])
+ print(f"Specified task prompt:\n{specified_task_prompt}\n")
+
+
+def test_task_planner_agent():
+ original_task_prompt = "Modeling molecular dynamics"
+ print(f"Original task prompt:\n{original_task_prompt}\n")
+ task_specify_agent = TaskSpecifyAgent(
+ ModeType.GPT_3_5_TURBO,
+ task_type=TaskType.CODE,
+ model_config=ChatGPTConfig(temperature=1.0),
+ )
+ specified_task_prompt = task_specify_agent.specify_task(
+ original_task_prompt, [
+ ("<DOMAIN>", "Chemistry"),
+ ("<LANGUAGE>", "Python"),
+ ])
+ print(f"Specified task prompt:\n{specified_task_prompt}\n")
+ task_planner_agent = TaskPlannerAgent(
+ ModeType.GPT_3_5_TURBO, model_config=ChatGPTConfig(temperature=1.0))
+ planned_task_prompt = task_planner_agent.plan_task(specified_task_prompt)
+ print(f"Planned task prompt:\n{planned_task_prompt}\n")