|
11 | 11 | # See the License for the specific language governing permissions and |
12 | 12 | # limitations under the License. |
13 | 13 | # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== |
14 | | -import copy |
15 | 14 | import random |
16 | 15 | import warnings |
17 | 16 | from typing import Any, Dict, Optional, Sequence |
18 | 17 |
|
19 | 18 | from colorama import Fore |
20 | 19 |
|
21 | | -from camel.agents import ChatAgent |
| 20 | +from camel.agents import ChatAgent, ChatAgentResponse |
22 | 21 | from camel.messages import BaseMessage |
23 | 22 | from camel.typing import ModelType |
24 | 23 | from camel.utils import get_first_int, print_text_animated |
@@ -141,33 +140,35 @@ def parse_critic(self, critic_msg: BaseMessage) -> Optional[str]: |
141 | 140 | choice = str(get_first_int(critic_msg.content)) |
142 | 141 | return choice |
143 | 142 |
|
144 | | - def step(self, messages: Sequence[BaseMessage]) -> BaseMessage: |
| 143 | + def reduce_step( |
| 144 | + self, |
| 145 | + input_messages: Sequence[BaseMessage], |
| 146 | + ) -> ChatAgentResponse: |
145 | 147 | r"""Performs one step of the conversation by flattening options to the |
146 | 148 | critic, getting the option, and parsing the choice. |
147 | 149 |
|
148 | 150 | Args: |
149 | 151 | messages (Sequence[BaseMessage]): A list of BaseMessage objects. |
150 | 152 |
|
151 | 153 | Returns: |
152 | | - BaseMessage: A `BaseMessage` object representing the critic's |
153 | | - choice. |
| 154 | + ChatAgentResponse: A `ChatAgentResponse` object includes the |
| 155 | + critic's choice. |
154 | 156 | """ |
155 | 157 | meta_chat_message = BaseMessage( |
156 | | - role_name=messages[0].role_name, |
157 | | - role_type=messages[0].role_type, |
158 | | - meta_dict=messages[0].meta_dict, |
| 158 | + role_name=input_messages[0].role_name, |
| 159 | + role_type=input_messages[0].role_type, |
| 160 | + meta_dict=input_messages[0].meta_dict, |
159 | 161 | content="", |
160 | 162 | ) |
161 | 163 |
|
162 | | - flatten_options = self.flatten_options(messages) |
| 164 | + flatten_options = self.flatten_options(input_messages) |
163 | 165 | if self.verbose: |
164 | 166 | print_text_animated(self.logger_color + |
165 | 167 | f"\x1b[3m{flatten_options}\x1b[0m\n") |
166 | | - input_msg = copy.deepcopy(meta_chat_message) |
167 | | - input_msg.content = flatten_options |
| 168 | + input_msg = meta_chat_message.create_new_instance(flatten_options) |
168 | 169 |
|
169 | 170 | option = self.get_option(input_msg) |
170 | | - output_msg = copy.deepcopy(meta_chat_message) |
171 | | - output_msg.content = option |
| 171 | + output_msg = meta_chat_message.create_new_instance(option) |
172 | 172 |
|
173 | | - return output_msg |
| 173 | + # TODO: The return `info` can be improved. |
| 174 | + return ChatAgentResponse([output_msg], terminated=False, info={}) |
0 commit comments