agent.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from dataclasses import dataclass
  2. from typing import TYPE_CHECKING
  3. from opendevin.observation import (
  4. AgentRecallObservation,
  5. AgentMessageObservation,
  6. Observation,
  7. )
  8. from opendevin.schema import ActionType
  9. from .base import ExecutableAction, NotExecutableAction
  10. if TYPE_CHECKING:
  11. from opendevin.controller import AgentController
  12. @dataclass
  13. class AgentRecallAction(ExecutableAction):
  14. query: str
  15. action: str = ActionType.RECALL
  16. def run(self, controller: 'AgentController') -> AgentRecallObservation:
  17. return AgentRecallObservation(
  18. content='Recalling memories...',
  19. memories=controller.agent.search_memory(self.query),
  20. )
  21. @property
  22. def message(self) -> str:
  23. return f"Let me dive into my memories to find what you're looking for! Searching for: '{self.query}'. This might take a moment."
  24. @dataclass
  25. class AgentThinkAction(NotExecutableAction):
  26. thought: str
  27. action: str = ActionType.THINK
  28. def run(self, controller: 'AgentController') -> 'Observation':
  29. raise NotImplementedError
  30. @property
  31. def message(self) -> str:
  32. return self.thought
  33. @dataclass
  34. class AgentEchoAction(ExecutableAction):
  35. content: str
  36. action: str = 'echo'
  37. def run(self, controller: 'AgentController') -> 'Observation':
  38. return AgentMessageObservation(self.content)
  39. @property
  40. def message(self) -> str:
  41. return self.content
  42. @dataclass
  43. class AgentSummarizeAction(NotExecutableAction):
  44. summary: str
  45. action: str = ActionType.SUMMARIZE
  46. @property
  47. def message(self) -> str:
  48. return self.summary
  49. @dataclass
  50. class AgentFinishAction(NotExecutableAction):
  51. action: str = ActionType.FINISH
  52. def run(self, controller: 'AgentController') -> 'Observation':
  53. raise NotImplementedError
  54. @property
  55. def message(self) -> str:
  56. return "All done! What's next on the agenda?"