You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update custom visualizer documentation for new API
- Fix parameter name from 'visualize' to 'visualizer' throughout documentation
- Update visualization options to reflect simplified API:
* Default behavior (no parameter): Creates default visualizer automatically
* None: Disable visualization entirely
* ConversationVisualizer instance: Use custom visualizer
- Improve error handling example with more practical code
- Align all examples with the API simplification changes
Related to: OpenHands/software-agent-sdk#1025
Co-authored-by: openhands <[email protected]>
Copy file name to clipboardExpand all lines: sdk/guides/convo-custom-visualizer.mdx
+22-14Lines changed: 22 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ The comprehensive example below demonstrates a custom visualizer that tracks con
17
17
This example demonstrates how to create and use a custom visualizer by subclassing
18
18
ConversationVisualizer. This approach provides:
19
19
- Clean, testable code with class-based state management
20
-
- Direct configuration (just pass the visualizer instance to visualize parameter)
20
+
- Direct configuration (just pass the visualizer instance to visualizer parameter)
21
21
- Reusable visualizer that can be shared across conversations
22
22
- Better separation of concerns compared to callback functions
23
23
@@ -28,7 +28,7 @@ The MinimalProgressVisualizer produces concise output showing:
28
28
- Error messages
29
29
30
30
This demonstrates how you can pass a ConversationVisualizer instance directly
31
-
to the visualize parameter for clean, reusable visualization logic.
31
+
to the visualizer parameter for clean, reusable visualization logic.
32
32
"""
33
33
34
34
import logging
@@ -212,7 +212,7 @@ def main():
212
212
conversation = Conversation(
213
213
agent=agent,
214
214
workspace=cwd,
215
-
visualize=minimal_visualizer,
215
+
visualizer=minimal_visualizer,
216
216
)
217
217
218
218
# Send a message and let the agent run
@@ -328,10 +328,10 @@ class CustomVisualizer:
328
328
self.console.print(panel)
329
329
330
330
# Use it directly
331
-
conversation =LocalConversation(
331
+
conversation =Conversation(
332
332
agent=agent,
333
333
workspace=workspace,
334
-
visualize=CustomVisualizer() # Pass your custom object
334
+
visualizer=CustomVisualizer() # Pass your custom object
335
335
)
336
336
```
337
337
@@ -576,25 +576,33 @@ This pattern provides:
576
576
Always include error handling to prevent visualization issues from breaking conversations:
577
577
578
578
```python
579
+
import logging
580
+
579
581
defon_event(self, event):
580
582
try:
581
583
# Your visualization logic
582
-
self._handle_event(event)
584
+
ifisinstance(event, ActionEvent):
585
+
self._handle_action_event(event)
586
+
elifisinstance(event, ObservationEvent):
587
+
self._handle_observation_event(event)
588
+
# ... other event types
583
589
exceptExceptionas e:
584
590
# Fallback to prevent breaking the conversation
585
-
print(f"Visualization error: {e}")
591
+
print(f"⚠️ Visualization error: {e}", flush=True)
586
592
# Optionally log for debugging
587
-
logging.warning(f"Visualizer failed: {e}")
593
+
logging.warning(f"Visualizer failed for {event.__class__.__name__}: {e}")
588
594
```
589
595
596
+
This pattern ensures that visualization problems never interrupt the agent's work.
597
+
590
598
### 5. Performance Considerations
591
599
For high-frequency events, consider optimizing your visualization by filtering events or using efficient output methods like `flush=True` for immediate display.
592
600
593
601
## Using Your Custom Visualizer
594
602
595
603
### Direct Assignment (Recommended)
596
604
597
-
Pass your visualizer instance directly to the `visualize` parameter:
605
+
Pass your visualizer instance directly to the `visualizer` parameter:
0 commit comments