tasks.py 1.5 KB

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