agent.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from dataclasses import dataclass, field
  2. from typing import TYPE_CHECKING, Dict
  3. from opendevin.core.schema import ActionType
  4. from opendevin.events.observation import (
  5. AgentRecallObservation,
  6. NullObservation,
  7. Observation,
  8. )
  9. from .action import Action
  10. if TYPE_CHECKING:
  11. from opendevin.controller import AgentController
  12. @dataclass
  13. class ChangeAgentStateAction(Action):
  14. """Fake action, just to notify the client that a task state has changed."""
  15. agent_state: str
  16. thought: str = ''
  17. action: str = ActionType.CHANGE_AGENT_STATE
  18. @property
  19. def message(self) -> str:
  20. return f'Agent state changed to {self.agent_state}'
  21. @dataclass
  22. class AgentRecallAction(Action):
  23. query: str
  24. thought: str = ''
  25. action: str = ActionType.RECALL
  26. async def run(self, controller: 'AgentController') -> AgentRecallObservation:
  27. return AgentRecallObservation(
  28. content='',
  29. memories=controller.agent.search_memory(self.query),
  30. )
  31. @property
  32. def message(self) -> str:
  33. return f"Let me dive into my memories to find what you're looking for! Searching for: '{self.query}'. This might take a moment."
  34. @dataclass
  35. class AgentSummarizeAction(Action):
  36. summary: str
  37. action: str = ActionType.SUMMARIZE
  38. @property
  39. def message(self) -> str:
  40. return self.summary
  41. @dataclass
  42. class AgentFinishAction(Action):
  43. outputs: Dict = field(default_factory=dict)
  44. thought: str = ''
  45. action: str = ActionType.FINISH
  46. @property
  47. def message(self) -> str:
  48. return "All done! What's next on the agenda?"
  49. @dataclass
  50. class AgentRejectAction(Action):
  51. outputs: Dict = field(default_factory=dict)
  52. thought: str = ''
  53. action: str = ActionType.REJECT
  54. @property
  55. def message(self) -> str:
  56. return 'Task is rejected by the agent.'
  57. @dataclass
  58. class AgentDelegateAction(Action):
  59. agent: str
  60. inputs: dict
  61. thought: str = ''
  62. action: str = ActionType.DELEGATE
  63. async def run(self, controller: 'AgentController') -> Observation:
  64. await controller.start_delegate(self)
  65. return NullObservation('')
  66. @property
  67. def message(self) -> str:
  68. return f"I'm asking {self.agent} for help with this task."