Add a sub-task (or list of subtasks) that this task can delegate (or fail-over) to. Note that the sequence of sub-tasks is important, since these are tried in order, as the parent task searches for a valid response (unless a sub-task is explicitly addressed).
(
self,
task: (
Task | List[Task] | Tuple[Task, TaskConfig] | List[Tuple[Task, TaskConfig]]
),
)
| 570 | return self._indent + "<<<" |
| 571 | |
| 572 | def add_sub_task( |
| 573 | self, |
| 574 | task: ( |
| 575 | Task | List[Task] | Tuple[Task, TaskConfig] | List[Tuple[Task, TaskConfig]] |
| 576 | ), |
| 577 | ) -> None: |
| 578 | """ |
| 579 | Add a sub-task (or list of subtasks) that this task can delegate |
| 580 | (or fail-over) to. Note that the sequence of sub-tasks is important, |
| 581 | since these are tried in order, as the parent task searches for a valid |
| 582 | response (unless a sub-task is explicitly addressed). |
| 583 | |
| 584 | Args: |
| 585 | task: A task, or list of tasks, or a tuple of task and task config, |
| 586 | or a list of tuples of task and task config. |
| 587 | These tasks are added as sub-tasks of the current task. |
| 588 | The task configs (if any) dictate how the tasks are run when |
| 589 | invoked as sub-tasks of other tasks. This allows users to specify |
| 590 | behavior applicable only in the context of a particular task-subtask |
| 591 | combination. |
| 592 | """ |
| 593 | if isinstance(task, list): |
| 594 | for t in task: |
| 595 | self.add_sub_task(t) |
| 596 | return |
| 597 | |
| 598 | if isinstance(task, tuple): |
| 599 | task, config = task |
| 600 | else: |
| 601 | config = TaskConfig() |
| 602 | task.config_sub_task = config |
| 603 | self.sub_tasks.append(task) |
| 604 | self.name_sub_task_map[task.name] = task |
| 605 | self.responders.append(cast(Responder, task)) |
| 606 | self.responders_async.append(cast(Responder, task)) |
| 607 | self.non_human_responders.append(cast(Responder, task)) |
| 608 | self.non_human_responders_async.append(cast(Responder, task)) |
| 609 | |
| 610 | def init(self, msg: None | str | ChatDocument = None) -> ChatDocument | None: |
| 611 | """ |