agent.py 1.6 KB

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