Skip to content

Commit

Permalink
Feat: Filter matching events in reverse order (All-Hands-AI#6485)
Browse files Browse the repository at this point in the history
  • Loading branch information
malhotra5 authored and idagelic committed Feb 12, 2025
1 parent 271e7a3 commit 095fee8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion openhands/events/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def get_matching_events(
end_date: str | None = None,
start_id: int = 0,
limit: int = 100,
reverse: bool = False,
) -> list:
"""Get matching events from the event stream based on filters.
Expand All @@ -378,6 +379,7 @@ def get_matching_events(
end_date: Filter events before this date (ISO format)
start_id: Starting ID in the event stream. Defaults to 0
limit: Maximum number of events to return. Must be between 1 and 100. Defaults to 100
reverse: Whether to retrieve events in reverse order. Defaults to False.
Returns:
list: List of matching events (as dicts)
Expand All @@ -390,7 +392,7 @@ def get_matching_events(

matching_events: list = []

for event in self.get_events(start_id=start_id):
for event in self.get_events(start_id=start_id, reverse=reverse):
if self._should_filter_event(
event, query, event_types, source, start_date, end_date
):
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_event_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def test_get_matching_events_type_filter(temp_dir: str):
events = event_stream.get_matching_events(event_types=(NullAction, MessageAction))
assert len(events) == 3

# Filter in reverse
events = event_stream.get_matching_events(reverse=True, limit=1)
assert events[0]['message'] == 'test'


def test_get_matching_events_query_search(temp_dir: str):
file_store = get_file_store('local', temp_dir)
Expand Down

0 comments on commit 095fee8

Please sign in to comment.