agent.py 911 B

1234567891011121314151617181920212223242526
  1. from agenthub.langchains_agent.utils.monologue import Monologue
  2. from agenthub.langchains_agent.utils.memory import LongTermMemory
  3. from opendevin.lib.event import Event
  4. import agenthub.langchains_agent.utils.llm as llm
  5. MAX_OUTPUT_LENGTH = 5000
  6. MAX_MONOLOGUE_LENGTH = 20000
  7. class Agent:
  8. def __init__(self, task):
  9. self.task = task
  10. self.monologue = Monologue()
  11. self.memory = LongTermMemory()
  12. def add_event(self, event):
  13. self.monologue.add_event(event)
  14. self.memory.add_event(event)
  15. if self.monologue.get_total_length() > MAX_MONOLOGUE_LENGTH:
  16. self.monologue.condense()
  17. def get_next_action(self, cmd_mgr):
  18. action_dict = llm.request_action(self.task, self.monologue.get_thoughts(), cmd_mgr.background_commands)
  19. event = Event(action_dict['action'], action_dict['args'])
  20. self.latest_action = event
  21. return event