MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / evolve

Method evolve

camel/tasks/task.py:395–430  ·  view source on GitHub ↗

r"""Evolve a task to a new task. Evolve is only used for data generation. Args: task (Task): A given task. agent (ChatAgent): An agent that used to evolve the task. template (TextPrompt, optional): A prompt template to evolve task.

(
        self,
        task: Task,
        agent: ChatAgent,
        template: Optional[TextPrompt] = None,
        task_parser: Optional[Callable[[str, str], List[Task]]] = None,
    )

Source from the content-addressed store, hash-verified

393 self.task_map = {task.id: task for task in self.tasks}
394
395 def evolve(
396 self,
397 task: Task,
398 agent: ChatAgent,
399 template: Optional[TextPrompt] = None,
400 task_parser: Optional[Callable[[str, str], List[Task]]] = None,
401 ) -> Optional[Task]:
402 r"""Evolve a task to a new task.
403 Evolve is only used for data generation.
404 Args:
405 task (Task): A given task.
406 agent (ChatAgent): An agent that used to evolve the task.
407 template (TextPrompt, optional): A prompt template to evolve task.
408 If not provided, the default template will be used.
409 task_parser (Callable, optional): A function to extract Task from
410 response. If not provided, the default parser will be used.
411
412 Returns:
413 Task: The created :obj:`Task` instance or None.
414 """
415
416 if template is None:
417 template = TASK_EVOLVE_PROMPT
418
419 role_name = agent.role_name
420 content = template.format(role_name=role_name, content=task.content)
421 msg = BaseMessage.make_user_message(
422 role_name=role_name, content=content
423 )
424 response = agent.step(msg)
425 if task_parser is None:
426 task_parser = parse_response
427 tasks = task_parser(response.msg.content, task.id)
428 if tasks:
429 return tasks[0]
430 return None

Callers

nothing calls this directly

Calls 3

formatMethod · 0.45
make_user_messageMethod · 0.45
stepMethod · 0.45

Tested by

no test coverage detected