mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-10 07:18:10 -05:00
* add message if exit happens before finish * fix kill command * fix browse action * fix sandbox * update requirements * add status code * refactor controller * add try to callbacks * fix background log collection * format logs a bit more nicely * run background procs in same container * fix close command * rename sockt * fix up kills * fix lint issues * fix ruff --------- Co-authored-by: Xingyao Wang <xingyao6@illinois.edu>
118 lines
2.5 KiB
Python
118 lines
2.5 KiB
Python
import copy
|
|
from typing import List
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class Observation:
|
|
"""
|
|
This data class represents an observation of the environment.
|
|
"""
|
|
|
|
content: str
|
|
|
|
def __str__(self) -> str:
|
|
return self.content
|
|
|
|
def to_dict(self) -> dict:
|
|
"""Converts the observation to a dictionary."""
|
|
extras = copy.deepcopy(self.__dict__)
|
|
extras.pop("content", None)
|
|
return {
|
|
"observation": self.__class__.__name__,
|
|
"content": self.content,
|
|
"extras": extras,
|
|
"message": self.message,
|
|
}
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
"""Returns a message describing the observation."""
|
|
return "The agent made an observation."
|
|
|
|
|
|
@dataclass
|
|
class CmdOutputObservation(Observation):
|
|
"""
|
|
This data class represents the output of a command.
|
|
"""
|
|
|
|
command_id: int
|
|
command: str
|
|
exit_code: int = 0
|
|
|
|
@property
|
|
def error(self) -> bool:
|
|
return self.exit_code != 0
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return f'The agent observed command "{self.command}" executed with exit code {self.exit_code}.'
|
|
|
|
|
|
@dataclass
|
|
class BrowserOutputObservation(Observation):
|
|
"""
|
|
This data class represents the output of a browser.
|
|
"""
|
|
|
|
url: str
|
|
status_code: int = 200
|
|
error: bool = False
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return "The agent observed the browser output at URL."
|
|
|
|
|
|
@dataclass
|
|
class UserMessageObservation(Observation):
|
|
"""
|
|
This data class represents a message sent by the user.
|
|
"""
|
|
|
|
role: str = "user"
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return "The agent received a message from the user."
|
|
|
|
|
|
@dataclass
|
|
class AgentMessageObservation(Observation):
|
|
"""
|
|
This data class represents a message sent by the agent.
|
|
"""
|
|
|
|
role: str = "assistant"
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return "The agent received a message from itself."
|
|
|
|
|
|
@dataclass
|
|
class AgentRecallObservation(Observation):
|
|
"""
|
|
This data class represents a list of memories recalled by the agent.
|
|
"""
|
|
|
|
memories: List[str]
|
|
role: str = "assistant"
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return "The agent recalled memories."
|
|
|
|
|
|
@dataclass
|
|
class NullObservation(Observation):
|
|
"""
|
|
This data class represents a null observation.
|
|
This is used when the produced action is NOT executable.
|
|
"""
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return ""
|