base.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from dataclasses import dataclass
  2. from typing import TYPE_CHECKING
  3. if TYPE_CHECKING:
  4. from opendevin.controller import AgentController
  5. from opendevin.observation import Observation
  6. @dataclass
  7. class Action:
  8. def run(self, controller: "AgentController") -> "Observation":
  9. raise NotImplementedError
  10. def to_dict(self):
  11. return {"action": self.__class__.__name__, "args": self.__dict__, "message": self.message}
  12. @property
  13. def executable(self) -> bool:
  14. raise NotImplementedError
  15. @property
  16. def message(self) -> str:
  17. raise NotImplementedError
  18. class ExecutableAction(Action):
  19. @property
  20. def executable(self) -> bool:
  21. return True
  22. class NotExecutableAction(Action):
  23. @property
  24. def executable(self) -> bool:
  25. return False
  26. class NullAction(NotExecutableAction):
  27. """An action that does nothing.
  28. This is used when the agent need to receive user follow-up messages from the frontend.
  29. """
  30. @property
  31. def message(self) -> str:
  32. return "No action"