Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion openhands-sdk/openhands/sdk/conversation/visualizer/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
UserRejectObservation,
)
from openhands.sdk.event.base import Event
from openhands.sdk.event.condenser import Condensation
from openhands.sdk.event.condenser import Condensation, CondensationRequest


# These are external inputs
Expand Down Expand Up @@ -252,6 +252,19 @@ def _create_event_panel(self, event: Event) -> Panel | None:
border_style=_SYSTEM_COLOR,
expand=True,
)

elif isinstance(event, CondensationRequest):
title = f"[bold {_SYSTEM_COLOR}]"
if self._name:
title += f"{self._name} "
title += f"Condensation Request[/bold {_SYSTEM_COLOR}]"
return Panel(
content,
title=title,
border_style=_SYSTEM_COLOR,
padding=_PANEL_PADDING,
expand=True,
)
else:
# Fallback panel for unknown event types
title = f"[bold {_ERROR_COLOR}]"
Expand Down
11 changes: 11 additions & 0 deletions openhands-sdk/openhands/sdk/event/condenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ class CondensationRequest(Event):

source: SourceType = "environment"

@property
def visualize(self) -> Text:
text = Text()
text.append("Conversation Condensation Requested\n", style="bold")
message = (
"A condensation of the conversation history has been requested to "
"manage context window usage.\n"
)
text.append(message)
return text


class CondensationSummaryEvent(LLMConvertibleEvent):
"""This event represents a summary generated by a condenser."""
Expand Down
19 changes: 19 additions & 0 deletions tests/sdk/conversation/test_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from openhands.sdk.event import (
ActionEvent,
AgentErrorEvent,
CondensationRequest,
MessageEvent,
ObservationEvent,
PauseEvent,
Expand Down Expand Up @@ -290,6 +291,24 @@ def test_visualizer_user_reject_observation_panel():
assert "User rejected the proposed action." in renderable.plain


def test_visualizer_condensation_request_panel():
"""CondensationRequest should render a system-styled panel with friendly text."""
visualizer = DefaultConversationVisualizer()
event = CondensationRequest()
panel = visualizer._create_event_panel(event)
assert panel is not None
# Should not fall back to UNKNOWN
assert "UNKNOWN Event" not in str(panel.title)
# Title should indicate condensation request (case-insensitive check on substring)
assert "Condensation Request" in str(panel.title)
# Body should be the friendly visualize text
renderable = panel.renderable
assert isinstance(renderable, Text)
body = renderable.plain
assert "Conversation Condensation Requested" in body
assert "condensation of the conversation history" in body


def test_metrics_formatting():
"""Test metrics subtitle formatting."""
from unittest.mock import MagicMock
Expand Down
Loading