Skip to content

Commit b24c9cc

Browse files
enystopenhands-agentxingyaoww
authored
visualizer: render CondensationRequest nicely (#1113)
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
1 parent 9b7799b commit b24c9cc

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

openhands-sdk/openhands/sdk/conversation/visualizer/default.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
UserRejectObservation,
1818
)
1919
from openhands.sdk.event.base import Event
20-
from openhands.sdk.event.condenser import Condensation
20+
from openhands.sdk.event.condenser import Condensation, CondensationRequest
2121

2222

2323
# These are external inputs
@@ -252,6 +252,19 @@ def _create_event_panel(self, event: Event) -> Panel | None:
252252
border_style=_SYSTEM_COLOR,
253253
expand=True,
254254
)
255+
256+
elif isinstance(event, CondensationRequest):
257+
title = f"[bold {_SYSTEM_COLOR}]"
258+
if self._name:
259+
title += f"{self._name} "
260+
title += f"Condensation Request[/bold {_SYSTEM_COLOR}]"
261+
return Panel(
262+
content,
263+
title=title,
264+
border_style=_SYSTEM_COLOR,
265+
padding=_PANEL_PADDING,
266+
expand=True,
267+
)
255268
else:
256269
# Fallback panel for unknown event types
257270
title = f"[bold {_ERROR_COLOR}]"

openhands-sdk/openhands/sdk/event/condenser.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ class CondensationRequest(Event):
5555

5656
source: SourceType = "environment"
5757

58+
@property
59+
def visualize(self) -> Text:
60+
text = Text()
61+
text.append("Conversation Condensation Requested\n", style="bold")
62+
message = (
63+
"A condensation of the conversation history has been requested to "
64+
"manage context window usage.\n"
65+
)
66+
text.append(message)
67+
return text
68+
5869

5970
class CondensationSummaryEvent(LLMConvertibleEvent):
6071
"""This event represents a summary generated by a condenser."""

tests/sdk/conversation/test_visualizer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from openhands.sdk.event import (
1212
ActionEvent,
1313
AgentErrorEvent,
14+
CondensationRequest,
1415
MessageEvent,
1516
ObservationEvent,
1617
PauseEvent,
@@ -291,6 +292,24 @@ def test_visualizer_user_reject_observation_panel():
291292
assert "User rejected the proposed action." in renderable.plain
292293

293294

295+
def test_visualizer_condensation_request_panel():
296+
"""CondensationRequest should render a system-styled panel with friendly text."""
297+
visualizer = DefaultConversationVisualizer()
298+
event = CondensationRequest()
299+
panel = visualizer._create_event_panel(event)
300+
assert panel is not None
301+
# Should not fall back to UNKNOWN
302+
assert "UNKNOWN Event" not in str(panel.title)
303+
# Title should indicate condensation request (case-insensitive check on substring)
304+
assert "Condensation Request" in str(panel.title)
305+
# Body should be the friendly visualize text
306+
renderable = panel.renderable
307+
assert isinstance(renderable, Text)
308+
body = renderable.plain
309+
assert "Conversation Condensation Requested" in body
310+
assert "condensation of the conversation history" in body
311+
312+
294313
def test_metrics_formatting():
295314
"""Test metrics subtitle formatting."""
296315
from unittest.mock import MagicMock

0 commit comments

Comments
 (0)