agent.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. action: str = "recall"
  11. def run(self, controller: "AgentController") -> AgentRecallObservation:
  12. return AgentRecallObservation(
  13. content="Recalling memories...",
  14. memories=controller.agent.search_memory(self.query)
  15. )
  16. @property
  17. def message(self) -> str:
  18. return f"Let me dive into my memories to find what you're looking for! Searching for: '{self.query}'. This might take a moment."
  19. @dataclass
  20. class AgentThinkAction(NotExecutableAction):
  21. thought: str
  22. action: str = "think"
  23. def run(self, controller: "AgentController") -> "Observation":
  24. raise NotImplementedError
  25. @property
  26. def message(self) -> str:
  27. return self.thought
  28. @dataclass
  29. class AgentEchoAction(ExecutableAction):
  30. content: str
  31. action: str = "echo"
  32. def run(self, controller: "AgentController") -> "Observation":
  33. return AgentMessageObservation(self.content)
  34. @property
  35. def message(self) -> str:
  36. return self.content
  37. @dataclass
  38. class AgentSummarizeAction(NotExecutableAction):
  39. summary: str
  40. action: str = "summarize"
  41. @property
  42. def message(self) -> str:
  43. return self.summary
  44. @dataclass
  45. class AgentFinishAction(NotExecutableAction):
  46. action: str = "finish"
  47. def run(self, controller: "AgentController") -> "Observation":
  48. raise NotImplementedError
  49. @property
  50. def message(self) -> str:
  51. return "All done! What's next on the agenda?"