Files
OpenHands/opendevin/lib/event.py
geohotstan fb1822123a Adding pre-commit and CI for ruff and mypy (#69)
* don't modify directories

* oops typo

* dev_config/python

* add config to CI

* bump CI python to 3.10

* 3.11?

* del actions/

* add suggestions

* delete unused code

* missed some

* oops missed another one

* remove a file
2024-03-23 19:41:49 -04:00

55 lines
1.9 KiB
Python

import opendevin.lib.actions as actions
ACTION_TYPES = ['run', 'kill', 'browse', 'read', 'write', 'recall', 'think', 'summarize', 'output', 'error', 'finish']
RUNNABLE_ACTIONS = ['run', 'kill', 'browse', 'read', 'write', 'recall']
class Event:
def __init__(self, action, args):
if action not in ACTION_TYPES:
raise ValueError('Invalid action type: ' + action)
self.action = action
self.args = args
def __str__(self):
return self.action + " " + str(self.args)
def str_truncated(self, max_len=1000):
s = str(self)
if len(s) > max_len:
s = s[:max_len] + '...'
return s
def to_dict(self):
return {
'action': self.action,
'args': self.args
}
def is_runnable(self):
return self.action in RUNNABLE_ACTIONS
def run(self, agent_controller):
if self.action == 'run':
cmd = self.args['command']
background = False
if 'background' in self.args and self.args['background']:
background = True
return agent_controller.command_manager.run_command(cmd, background)
if self.action == 'kill':
id = self.args['id']
return agent_controller.command_manager.kill_command(id)
elif self.action == 'browse':
url = self.args['url']
return actions.browse(url)
elif self.action == 'read':
path = self.args['path']
return actions.read(agent_controller.command_manager.directory, path)
elif self.action == 'write':
path = self.args['path']
contents = self.args['contents']
return actions.write(agent_controller.command_manager.directory, path, contents)
elif self.action == 'recall':
return agent_controller.agent.search_memory(self.args['query'])
else:
raise ValueError('Invalid action type')