Skip to content

Commit 91f0bb9

Browse files
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]>
1 parent 2028886 commit 91f0bb9

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

sdk/guides/convo-custom-visualizer.mdx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The comprehensive example below demonstrates a custom visualizer that tracks con
1717
This example demonstrates how to create and use a custom visualizer by subclassing
1818
ConversationVisualizer. This approach provides:
1919
- 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)
2121
- Reusable visualizer that can be shared across conversations
2222
- Better separation of concerns compared to callback functions
2323
@@ -28,7 +28,7 @@ The MinimalProgressVisualizer produces concise output showing:
2828
- Error messages
2929
3030
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.
3232
"""
3333

3434
import logging
@@ -212,7 +212,7 @@ def main():
212212
conversation = Conversation(
213213
agent=agent,
214214
workspace=cwd,
215-
visualize=minimal_visualizer,
215+
visualizer=minimal_visualizer,
216216
)
217217

218218
# Send a message and let the agent run
@@ -328,10 +328,10 @@ class CustomVisualizer:
328328
self.console.print(panel)
329329

330330
# Use it directly
331-
conversation = LocalConversation(
331+
conversation = Conversation(
332332
agent=agent,
333333
workspace=workspace,
334-
visualize=CustomVisualizer() # Pass your custom object
334+
visualizer=CustomVisualizer() # Pass your custom object
335335
)
336336
```
337337

@@ -576,25 +576,33 @@ This pattern provides:
576576
Always include error handling to prevent visualization issues from breaking conversations:
577577

578578
```python
579+
import logging
580+
579581
def on_event(self, event):
580582
try:
581583
# Your visualization logic
582-
self._handle_event(event)
584+
if isinstance(event, ActionEvent):
585+
self._handle_action_event(event)
586+
elif isinstance(event, ObservationEvent):
587+
self._handle_observation_event(event)
588+
# ... other event types
583589
except Exception as e:
584590
# Fallback to prevent breaking the conversation
585-
print(f"Visualization error: {e}")
591+
print(f"⚠️ Visualization error: {e}", flush=True)
586592
# Optionally log for debugging
587-
logging.warning(f"Visualizer failed: {e}")
593+
logging.warning(f"Visualizer failed for {event.__class__.__name__}: {e}")
588594
```
589595

596+
This pattern ensures that visualization problems never interrupt the agent's work.
597+
590598
### 5. Performance Considerations
591599
For high-frequency events, consider optimizing your visualization by filtering events or using efficient output methods like `flush=True` for immediate display.
592600

593601
## Using Your Custom Visualizer
594602

595603
### Direct Assignment (Recommended)
596604

597-
Pass your visualizer instance directly to the `visualize` parameter:
605+
Pass your visualizer instance directly to the `visualizer` parameter:
598606

599607
```python
600608
# Create your custom visualizer
@@ -604,16 +612,16 @@ custom_visualizer = MinimalProgressVisualizer()
604612
conversation = Conversation(
605613
agent=agent,
606614
workspace="./workspace",
607-
visualize=custom_visualizer, # Direct assignment
615+
visualizer=custom_visualizer, # Direct assignment
608616
)
609617
```
610618

611619
### Visualization Options
612620

613-
The `visualize` parameter accepts three types:
621+
The `visualizer` parameter accepts three types:
614622

615-
- **`True`** (default): Use the default Rich panel visualizer
616-
- **`False` or `None`**: Disable visualization entirely
623+
- **Default behavior** (no parameter): Creates a default Rich panel visualizer automatically
624+
- **`None`**: Disable visualization entirely
617625
- **`ConversationVisualizer` instance**: Use your custom visualizer
618626

619627
### Combining with Additional Callbacks
@@ -629,7 +637,7 @@ def metrics_callback(event):
629637
conversation = Conversation(
630638
agent=agent,
631639
workspace="./workspace",
632-
visualize=custom_visualizer, # Handle visualization
640+
visualizer=custom_visualizer, # Handle visualization
633641
callbacks=[metrics_callback], # Handle other concerns
634642
)
635643
```

0 commit comments

Comments
 (0)