Engel Nyst 39a851bd95
Message property sent to llm (#1273)
* Add to_memory for observations

* Don't send 'message' property to the llm from observation; fix other agents
2024-04-22 12:14:45 -04:00

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 ''