mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 14:57:59 -05:00
62 lines
1.3 KiB
Python
62 lines
1.3 KiB
Python
from dataclasses import asdict, dataclass
|
|
from typing import TYPE_CHECKING
|
|
|
|
from opendevin.schema import ActionType
|
|
|
|
if TYPE_CHECKING:
|
|
from opendevin.controller import AgentController
|
|
from opendevin.observation import Observation
|
|
|
|
|
|
@dataclass
|
|
class Action:
|
|
async def run(self, controller: 'AgentController') -> 'Observation':
|
|
raise NotImplementedError
|
|
|
|
def to_memory(self):
|
|
d = asdict(self)
|
|
try:
|
|
v = d.pop('action')
|
|
except KeyError:
|
|
raise NotImplementedError(f'{self=} does not have action attribute set')
|
|
return {'action': v, 'args': d}
|
|
|
|
def to_dict(self):
|
|
d = self.to_memory()
|
|
d['message'] = self.message
|
|
return d
|
|
|
|
@property
|
|
def executable(self) -> bool:
|
|
raise NotImplementedError
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
raise NotImplementedError
|
|
|
|
|
|
@dataclass
|
|
class ExecutableAction(Action):
|
|
@property
|
|
def executable(self) -> bool:
|
|
return True
|
|
|
|
|
|
@dataclass
|
|
class NotExecutableAction(Action):
|
|
@property
|
|
def executable(self) -> bool:
|
|
return False
|
|
|
|
|
|
@dataclass
|
|
class NullAction(NotExecutableAction):
|
|
"""An action that does nothing.
|
|
"""
|
|
|
|
action: str = ActionType.NULL
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return 'No action'
|