Skip to main content

Choose a setup method

Start with one method for a call path. Combining SDK tracking with framework OpenTelemetry on the same call can create duplicate interactions.
Recommended. Choose this path when you want your coding agent to inspect the project, select a supported transport, make the smallest instrumentation change, send a test event, and verify that it reached Agnost AI.
Install the skill once in your coding-agent environment:
Run the framework-specific prompt below from the application root. Review the resulting diff before deploying it.

Manual setup: Agnost AI SDK

Wrap each act, extract, or observe call that you want to see as one interaction. Call await agnost.shutdown() once when the application exits, not after each request.

Manual setup: OpenTelemetry

Stagehand v4 can export its own traces with the telemetry.traces option, but those spans carry only stagehand.* operation and log attributes: no prompts, no model output, and no user or session. Agnost AI does not ingest them. Instead, route Stagehand’s model calls through a bring-your-own-LLM callback that calls the Vercel AI SDK with telemetry on. Every inference Stagehand makes for act, extract, and observe then arrives as GenAI spans with the full prompt and answer.

Install

Use @ai-sdk/openai or another AI SDK provider in place of @ai-sdk/anthropic if you prefer.

Setup

1. Register the exporter once at startup
2. Write a traced generate callback
3. Create one Stagehand instance per user session
The callback runs in your process, so it works the same with browserbase.launch() in place of localBrowser.launch(). Model Gateway is bypassed: the callback calls your provider with your own key.

What appears in Agnost AI

  • Conversations grouped by sessionId.
  • User-level analytics grouped by userId.
  • Events named stagehand (one per model call), with agent_step and chat children. The input is Stagehand’s instruction plus the page snapshot; the output is the JSON the model returned. extract makes a second call that checks whether the extraction finished.

Verify

Run one extract call, then open Events in Agnost AI. Confirm a stagehand event with the instruction as input and the extracted JSON as output, and that the conversation shows your sessionId and userId.

Troubleshooting

  • No events: confirm registerTelemetry(...) runs before Stagehand.create() and that the exporter has X-Agnost-Org-ID. Call await sdk.shutdown() before a short script exits.
  • model with a modelName (for example anthropic/claude-sonnet-5) runs the model inside Stagehand’s runtime, where your telemetry cannot reach it. Use the generate callback.
  • Do not point telemetry.traces at Agnost AI. Those spans have no GenAI attributes and are dropped.
  • Events split across conversations: create the callback with the right sessionId for each user session.

References

Next steps

  • Conversations: review the complete Stagehand session.
  • Events: inspect each model call Stagehand made.
  • Patterns: organize production conversations by what users wanted.