agent.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. from dataclasses import dataclass, field
  2. from typing import ClassVar
  3. from opendevin.core.schema import ActionType
  4. from .action import Action
  5. @dataclass
  6. class ChangeAgentStateAction(Action):
  7. """Fake action, just to notify the client that a task state has changed."""
  8. agent_state: str
  9. thought: str = ''
  10. action: str = ActionType.CHANGE_AGENT_STATE
  11. @property
  12. def message(self) -> str:
  13. return f'Agent state changed to {self.agent_state}'
  14. @dataclass
  15. class AgentRecallAction(Action):
  16. query: str
  17. thought: str = ''
  18. action: str = ActionType.RECALL
  19. runnable: ClassVar[bool] = True
  20. @property
  21. def message(self) -> str:
  22. return f"Let me dive into my memories to find what you're looking for! Searching for: '{self.query}'. This might take a moment."
  23. @dataclass
  24. class AgentSummarizeAction(Action):
  25. summary: str
  26. action: str = ActionType.SUMMARIZE
  27. @property
  28. def message(self) -> str:
  29. return self.summary
  30. def __str__(self) -> str:
  31. ret = '**AgentSummarizeAction**\n'
  32. ret += f'SUMMARY: {self.summary}'
  33. return ret
  34. @dataclass
  35. class AgentFinishAction(Action):
  36. outputs: dict = field(default_factory=dict)
  37. thought: str = ''
  38. action: str = ActionType.FINISH
  39. @property
  40. def message(self) -> str:
  41. return "All done! What's next on the agenda?"
  42. @dataclass
  43. class AgentRejectAction(Action):
  44. outputs: dict = field(default_factory=dict)
  45. thought: str = ''
  46. action: str = ActionType.REJECT
  47. @property
  48. def message(self) -> str:
  49. return 'Task is rejected by the agent.'
  50. @dataclass
  51. class AgentDelegateAction(Action):
  52. agent: str
  53. inputs: dict
  54. thought: str = ''
  55. action: str = ActionType.DELEGATE
  56. @property
  57. def message(self) -> str:
  58. return f"I'm asking {self.agent} for help with this task."