r"""Task is specific assignment that can be passed to a agent. Attributes: content: string content for task. id: An unique string identifier for the task. This should ideally be provided by the provider/model which created the task. state: The state which should
| 66 | |
| 67 | |
| 68 | class Task(BaseModel): |
| 69 | r"""Task is specific assignment that can be passed to a agent. |
| 70 | |
| 71 | Attributes: |
| 72 | content: string content for task. |
| 73 | id: An unique string identifier for the task. This should |
| 74 | ideally be provided by the provider/model which created the task. |
| 75 | state: The state which should be OPEN, RUNNING, DONE or DELETED. |
| 76 | type: task type |
| 77 | parent: The parent task, None for root task. |
| 78 | subtasks: The childrent sub-tasks for the task. |
| 79 | result: The answer for the task. |
| 80 | """ |
| 81 | |
| 82 | content: str |
| 83 | |
| 84 | id: str = "" |
| 85 | |
| 86 | state: TaskState = TaskState.OPEN |
| 87 | |
| 88 | type: Optional[str] = None |
| 89 | |
| 90 | parent: Optional["Task"] = None |
| 91 | |
| 92 | subtasks: List["Task"] = [] |
| 93 | |
| 94 | result: Optional[str] = "" |
| 95 | |
| 96 | failure_count: int = 0 |
| 97 | |
| 98 | additional_info: Optional[str] = None |
| 99 | |
| 100 | @classmethod |
| 101 | def from_message(cls, message: BaseMessage) -> "Task": |
| 102 | r"""Create a task from a message. |
| 103 | |
| 104 | Args: |
| 105 | message (BaseMessage): The message to the task. |
| 106 | |
| 107 | Returns: |
| 108 | Task |
| 109 | """ |
| 110 | return cls(content=message.content, id="0") |
| 111 | |
| 112 | @staticmethod |
| 113 | def to_message(): |
| 114 | r"""Convert a Task to a Message.""" |
| 115 | # TODO |
| 116 | pass |
| 117 | |
| 118 | def reset(self): |
| 119 | r"""Reset Task to initial state.""" |
| 120 | self.state = TaskState.OPEN |
| 121 | self.result = "" |
| 122 | |
| 123 | def update_result(self, result: str): |
| 124 | r"""Set task result and mark the task as DONE. |
| 125 |