Skip to content

Conversation

@jpshackelford
Copy link
Contributor

@jpshackelford jpshackelford commented Nov 7, 2025

Our existing example for Conversation Visualizer demonstrates swapping in a new Visualizer but also doesn't orient the reader to the aspects of the SDK they are likely to need in order to produce a useful visualization. This PR updates the existing visualization with a more realistic if simple example and adds another which offers a glimpse into a more realistic scenario for working with metrics. (A reviewer of the example we previously merged had requested that we showcase that.)


Agent Server images for this PR

GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.12-nodejs22 Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:b140b1d-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-b140b1d-python \
  ghcr.io/openhands/agent-server:b140b1d-python

All tags pushed for this build

ghcr.io/openhands/agent-server:b140b1d-golang-amd64
ghcr.io/openhands/agent-server:v1.0.0_golang_tag_1.21-bookworm_binary-amd64
ghcr.io/openhands/agent-server:b140b1d-golang-arm64
ghcr.io/openhands/agent-server:v1.0.0_golang_tag_1.21-bookworm_binary-arm64
ghcr.io/openhands/agent-server:b140b1d-java-amd64
ghcr.io/openhands/agent-server:v1.0.0_eclipse-temurin_tag_17-jdk_binary-amd64
ghcr.io/openhands/agent-server:b140b1d-java-arm64
ghcr.io/openhands/agent-server:v1.0.0_eclipse-temurin_tag_17-jdk_binary-arm64
ghcr.io/openhands/agent-server:b140b1d-python-amd64
ghcr.io/openhands/agent-server:v1.0.0_nikolaik_s_python-nodejs_tag_python3.12-nodejs22_binary-amd64
ghcr.io/openhands/agent-server:b140b1d-python-arm64
ghcr.io/openhands/agent-server:v1.0.0_nikolaik_s_python-nodejs_tag_python3.12-nodejs22_binary-arm64
ghcr.io/openhands/agent-server:b140b1d-golang
ghcr.io/openhands/agent-server:b140b1d-java
ghcr.io/openhands/agent-server:b140b1d-python

About Multi-Architecture Support

  • Each variant tag (e.g., b140b1d-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., b140b1d-python-amd64) are also available if needed

… tracking

- Show how to build stateful visualizers with incremental metrics display
- Demonstrate tracking LLM costs and token usage from conversation stats
- Teach handling multiple event types (ActionEvent, MessageEvent, AgentErrorEvent)
- Example extracting command and path details from tool action events
…ples

Split the custom visualizer example into two files:
- 26_custom_visualizer.py: Simple visualizer showing only latency
- 27_detailed_llm_metrics.py: Advanced visualizer with latency, cost, and token tracking

Changes:
- Simplified 26 to only display latency (removed cost/token tracking)
- Created 27 with MetricsCache class for efficient metrics lookup
- Improved formatting with right-aligned step numbers and event type labels
- Renamed class in 27 from SimpleVisualizer to TokenCountingVisualizer
- Added documentation explaining SDK metrics structure and cost matching

The MetricsCache class demonstrates how to match costs to response_ids using
ResponseLatency index, since Cost objects don't have response_id fields.
@jpshackelford jpshackelford added the documentation Improvements or additions to documentation label Nov 7, 2025
@openhands-ai
Copy link

openhands-ai bot commented Nov 7, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Check Documented Examples

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #1091 at branch `jps/example-visualizer`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine both examples? Or we should mention both examples in the docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use just the 27 example if you don't think it is too complex. I split them only so that there would be a simpler example first but I did that largely because I assumed you'd want that : ) If we do have two examples we could have doc for each one that focusses on the specific stuff we showcased in each. For the second it's largely about working with metrics and including them in visualization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malhotra5 What is your opinion?

func._handles_event_type = event_type
return func

return decorator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like this pattern, do you want to directly integrate this syntax into the default visualizer and/or even base class?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, seems very nice! Could we name it "@visualize" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants