agent.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. runnable: bool = False
  23. action: str = "think"
  24. def run(self, controller: "AgentController") -> "Observation":
  25. raise NotImplementedError
  26. @property
  27. def message(self) -> str:
  28. return self.thought
  29. @dataclass
  30. class AgentEchoAction(ExecutableAction):
  31. content: str
  32. runnable: bool = True
  33. action: str = "echo"
  34. def run(self, controller: "AgentController") -> "Observation":
  35. return AgentMessageObservation(self.content)
  36. @property
  37. def message(self) -> str:
  38. return self.content
  39. @dataclass
  40. class AgentSummarizeAction(NotExecutableAction):
  41. summary: str
  42. action: str = "summarize"
  43. @property
  44. def message(self) -> str:
  45. return self.summary
  46. @dataclass
  47. class AgentFinishAction(NotExecutableAction):
  48. runnable: bool = False
  49. action: str = "finish"
  50. def run(self, controller: "AgentController") -> "Observation":
  51. raise NotImplementedError
  52. @property
  53. def message(self) -> str:
  54. return "All done! What's next on the agenda?"