agent.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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"Let me dive into my memories to find what you're looking for! Searching for: '{self.query}'. This might take a moment."
  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 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 self.content
  36. @dataclass
  37. class AgentSummarizeAction(NotExecutableAction):
  38. summary: str
  39. @property
  40. def message(self) -> str:
  41. return self.summary
  42. @dataclass
  43. class AgentFinishAction(NotExecutableAction):
  44. runnable: bool = False
  45. def run(self, controller: "AgentController") -> "Observation":
  46. raise NotImplementedError
  47. @property
  48. def message(self) -> str:
  49. return "All done! What's next on the agenda?"