Skip to content

Commit

Permalink
feat: support filter_hidden query param in trajectory endpoint
Browse files Browse the repository at this point in the history
- Add filter_hidden query parameter support to /trajectory endpoint
- Add hidden property to Event class
- Add hidden to serialization keys for proper serialization/deserialization
  • Loading branch information
openhands-agent committed Feb 7, 2025
1 parent d3fa9ab commit a2746db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions openhands/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,13 @@ def tool_call_metadata(self) -> ToolCallMetadata | None:
@tool_call_metadata.setter
def tool_call_metadata(self, value: ToolCallMetadata) -> None:
self._tool_call_metadata = value

@property
def hidden(self) -> bool:
if hasattr(self, '_hidden'):
return self._hidden # type: ignore[attr-defined]
return False

@hidden.setter
def hidden(self, value: bool) -> None:
self._hidden = value
3 changes: 2 additions & 1 deletion openhands/events/serialization/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
'action',
'observation',
'tool_call_metadata',
'hidden',
]
UNDERSCORE_KEYS = ['id', 'timestamp', 'source', 'cause', 'tool_call_metadata']
UNDERSCORE_KEYS = ['id', 'timestamp', 'source', 'cause', 'tool_call_metadata', 'hidden']

DELETE_FROM_TRAJECTORY_EXTRAS = {
'screenshot',
Expand Down
7 changes: 6 additions & 1 deletion openhands/server/routes/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ async def get_trajectory(request: Request):
events.
"""
try:
filter_hidden = True
if hasattr(request, 'query_params') and 'filter_hidden' in request.query_params:
filter_hidden = request.query_params['filter_hidden'].lower() == 'true'

async_stream = AsyncEventStreamWrapper(
request.state.conversation.event_stream, filter_hidden=True
request.state.conversation.event_stream,
filter_hidden=filter_hidden,
)
trajectory = []
async for event in async_stream:
Expand Down

0 comments on commit a2746db

Please sign in to comment.