mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 13:52:43 +08:00
* Add to_memory for observations * Don't send 'message' property to the llm from observation; fix other agents
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
import copy
|
|
from dataclasses import dataclass
|
|
from opendevin.schema import ObservationType
|
|
|
|
|
|
@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 and adds user message."""
|
|
memory_dict = self.to_memory()
|
|
memory_dict['message'] = self.message
|
|
return memory_dict
|
|
|
|
def to_memory(self) -> dict:
|
|
"""Converts the observation to a dictionary."""
|
|
extras = copy.deepcopy(self.__dict__)
|
|
content = extras.pop('content', '')
|
|
observation = extras.pop('observation', '')
|
|
return {
|
|
'observation': observation,
|
|
'content': content,
|
|
'extras': extras,
|
|
}
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
"""Returns a message describing the observation."""
|
|
return ''
|
|
|
|
|
|
@dataclass
|
|
class NullObservation(Observation):
|
|
"""
|
|
This data class represents a null observation.
|
|
This is used when the produced action is NOT executable.
|
|
"""
|
|
|
|
observation: str = ObservationType.NULL
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return ''
|