Spaces:
Configuration error
Configuration error
Download openhands/memory/condenser/impl/observation_masking_condenser.py from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/memory/condenser/impl/observation_masking_condenser.py
- Command line
-
hf download hf://spaces/flyingdarkdev/README/openhands/memory/condenser/impl/observation_masking_condenser.py
-
curl -L -o observation_masking_condenser.py https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/memory/condenser/impl/observation_masking_condenser.py
1.49 kB
| from __future__ import annotations | |
| from openhands.core.config.condenser_config import ObservationMaskingCondenserConfig | |
| from openhands.events.event import Event | |
| from openhands.events.observation import Observation | |
| from openhands.events.observation.agent import AgentCondensationObservation | |
| from openhands.memory.condenser.condenser import Condensation, Condenser, View | |
| class ObservationMaskingCondenser(Condenser): | |
| """A condenser that masks the values of observations outside of a recent attention window.""" | |
| def __init__(self, attention_window: int = 5): | |
| self.attention_window = attention_window | |
| super().__init__() | |
| def condense(self, events: list[Event]) -> View | Condensation: | |
| """Replace the content of observations outside of the attention window with a placeholder.""" | |
| results: list[Event] = [] | |
| for i, event in enumerate(events): | |
| if ( | |
| isinstance(event, Observation) | |
| and i < len(events) - self.attention_window | |
| ): | |
| results.append(AgentCondensationObservation('<MASKED>')) | |
| else: | |
| results.append(event) | |
| return View(events=results) | |
| def from_config( | |
| cls, config: ObservationMaskingCondenserConfig | |
| ) -> ObservationMaskingCondenser: | |
| return ObservationMaskingCondenser(**config.model_dump(exclude=['type'])) | |
| ObservationMaskingCondenser.register_config(ObservationMaskingCondenserConfig) | |