Spaces:
Configuration error
Configuration error
Download openhands/memory/condenser/impl/recent_events_condenser.py from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/memory/condenser/impl/recent_events_condenser.py
- Command line
-
hf download hf://spaces/flyingdarkdev/README/openhands/memory/condenser/impl/recent_events_condenser.py
-
curl -L -o recent_events_condenser.py https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/memory/condenser/impl/recent_events_condenser.py
1.09 kB
| from __future__ import annotations | |
| from openhands.core.config.condenser_config import RecentEventsCondenserConfig | |
| from openhands.events.event import Event | |
| from openhands.memory.condenser.condenser import Condensation, Condenser, View | |
| class RecentEventsCondenser(Condenser): | |
| """A condenser that only keeps a certain number of the most recent events.""" | |
| def __init__(self, keep_first: int = 1, max_events: int = 10): | |
| self.keep_first = keep_first | |
| self.max_events = max_events | |
| super().__init__() | |
| def condense(self, events: list[Event]) -> View | Condensation: | |
| """Keep only the most recent events (up to `max_events`).""" | |
| head = events[: self.keep_first] | |
| tail_length = max(0, self.max_events - len(head)) | |
| tail = events[-tail_length:] | |
| return View(events=head + tail) | |
| def from_config(cls, config: RecentEventsCondenserConfig) -> RecentEventsCondenser: | |
| return RecentEventsCondenser(**config.model_dump(exclude=['type'])) | |
| RecentEventsCondenser.register_config(RecentEventsCondenserConfig) | |