r"""Decompose a task to a list of sub-tasks. It can be used for data generation and planner of agent. Args: agent (ChatAgent): An agent that used to decompose the task. prompt (str, optional): A prompt to decompose the task. If not provided, t
(
self,
agent: ChatAgent,
prompt: Optional[str] = None,
task_parser: Callable[[str, str], List["Task"]] = parse_response,
)
| 210 | return _str |
| 211 | |
| 212 | def decompose( |
| 213 | self, |
| 214 | agent: ChatAgent, |
| 215 | prompt: Optional[str] = None, |
| 216 | task_parser: Callable[[str, str], List["Task"]] = parse_response, |
| 217 | ) -> List["Task"]: |
| 218 | r"""Decompose a task to a list of sub-tasks. It can be used for data |
| 219 | generation and planner of agent. |
| 220 | |
| 221 | Args: |
| 222 | agent (ChatAgent): An agent that used to decompose the task. |
| 223 | prompt (str, optional): A prompt to decompose the task. If not |
| 224 | provided, the default prompt will be used. |
| 225 | task_parser (Callable[[str, str], List[Task]], optional): A |
| 226 | function to extract Task from response. If not provided, |
| 227 | the default parse_response will be used. |
| 228 | |
| 229 | Returns: |
| 230 | List[Task]: A list of tasks which are :obj:`Task` instances. |
| 231 | """ |
| 232 | |
| 233 | role_name = agent.role_name |
| 234 | content = prompt or TASK_DECOMPOSE_PROMPT.format( |
| 235 | role_name=role_name, |
| 236 | content=self.content, |
| 237 | ) |
| 238 | msg = BaseMessage.make_user_message( |
| 239 | role_name=role_name, content=content |
| 240 | ) |
| 241 | response = agent.step(msg) |
| 242 | tasks = task_parser(response.msg.content, self.id) |
| 243 | for task in tasks: |
| 244 | task.additional_info = self.additional_info |
| 245 | return tasks |
| 246 | |
| 247 | def compose( |
| 248 | self, |
no test coverage detected