tasks.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from dataclasses import dataclass, field
  2. from typing import TYPE_CHECKING
  3. from opendevin.observation import NullObservation
  4. from opendevin.schema import ActionType
  5. from .base import ExecutableAction, NotExecutableAction
  6. if TYPE_CHECKING:
  7. from opendevin.controller import AgentController
  8. @dataclass
  9. class AddTaskAction(ExecutableAction):
  10. parent: str
  11. goal: str
  12. subtasks: list = field(default_factory=list)
  13. thought: str = ''
  14. action: str = ActionType.ADD_TASK
  15. async def run(self, controller: 'AgentController') -> NullObservation: # type: ignore
  16. if controller.state is not None:
  17. controller.state.plan.add_subtask(self.parent, self.goal, self.subtasks)
  18. return NullObservation('')
  19. @property
  20. def message(self) -> str:
  21. return f'Added task: {self.goal}'
  22. @dataclass
  23. class ModifyTaskAction(ExecutableAction):
  24. id: str
  25. state: str
  26. thought: str = ''
  27. action: str = ActionType.MODIFY_TASK
  28. async def run(self, controller: 'AgentController') -> NullObservation: # type: ignore
  29. if controller.state is not None:
  30. controller.state.plan.set_subtask_state(self.id, self.state)
  31. return NullObservation('')
  32. @property
  33. def message(self) -> str:
  34. return f'Set task {self.id} to {self.state}'
  35. @dataclass
  36. class TaskStateChangedAction(NotExecutableAction):
  37. """Fake action, just to notify the client that a task state has changed."""
  38. task_state: str
  39. thought: str = ''
  40. action: str = ActionType.CHANGE_TASK_STATE
  41. @property
  42. def message(self) -> str:
  43. return f'Task state changed to {self.task_state}'