agent.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from dataclasses import dataclass
  2. from typing import TYPE_CHECKING
  3. from opendevin.observation import AgentRecallObservation, AgentMessageObservation, Observation
  4. from .base import ExecutableAction, NotExecutableAction
  5. if TYPE_CHECKING:
  6. from opendevin.controller import AgentController
  7. @dataclass
  8. class AgentRecallAction(ExecutableAction):
  9. query: str
  10. def run(self, controller: "AgentController") -> AgentRecallObservation:
  11. return AgentRecallObservation(
  12. content="Recalling memories...",
  13. memories=controller.agent.search_memory(self.query)
  14. )
  15. @property
  16. def message(self) -> str:
  17. return f"Recalling memories with query: {self.query}"
  18. @dataclass
  19. class AgentThinkAction(NotExecutableAction):
  20. thought: str
  21. runnable: bool = False
  22. def run(self, controller: "AgentController") -> "Observation":
  23. raise NotImplementedError
  24. @property
  25. def message(self) -> str:
  26. return f"Thinking: {self.thought}"
  27. @dataclass
  28. class AgentEchoAction(ExecutableAction):
  29. content: str
  30. runnable: bool = True
  31. def run(self, controller: "AgentController") -> "Observation":
  32. return AgentMessageObservation(self.content)
  33. @property
  34. def message(self) -> str:
  35. return f"Echoing: {self.content}"
  36. @dataclass
  37. class AgentFinishAction(NotExecutableAction):
  38. runnable: bool = False
  39. def run(self, controller: "AgentController") -> "Observation":
  40. raise NotImplementedError
  41. @property
  42. def message(self) -> str:
  43. return "Finished!"