-
Notifications
You must be signed in to change notification settings - Fork 1.3k
expose reasoning tokens from metrics #1268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: e91d7c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Greptile OverviewGreptile SummaryThis PR adds comprehensive support for tracking reasoning tokens across all Stagehand operations (act, extract, observe, agent). Reasoning tokens are now exposed through the Key Changes:
Implementation approach:
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant V3
participant Handler as Act/Extract/Observe Handler
participant LLM as LLMClient (AISdkClient)
participant Model as AI Model
User->>V3: call act/extract/observe/agent
V3->>Handler: execute operation
Handler->>LLM: createChatCompletion()
LLM->>Model: API request
Model-->>LLM: response with usage (inputTokens, outputTokens, reasoningTokens)
LLM-->>Handler: {data, usage: {prompt_tokens, completion_tokens, reasoning_tokens}}
Handler->>Handler: extract reasoning_tokens from usage
Handler->>V3: onMetrics(functionName, promptTokens, completionTokens, reasoningTokens, inferenceTimeMs)
V3->>V3: updateMetrics() - add to operation-specific counters
V3->>V3: updateTotalMetrics() - add to total counters
V3-->>User: return result
User->>V3: stagehand.stagehandMetrics
V3-->>User: metrics object with reasoning tokens for all operations
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
19 files reviewed, no comments
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/[email protected] ### Patch Changes - [#1273](#1273) [`ab51232`](ab51232) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: trigger shadow root rerender in OOPIFs by cloning & replacing instead of reloading - [#1268](#1268) [`c76ade0`](c76ade0) Thanks [@tkattkat](https://github.com/tkattkat)! - Expose reasoning, and cached input tokens in stagehand metrics - [#1267](#1267) [`ffb5e5d`](ffb5e5d) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: file uploads failing on Browserbase - [#1269](#1269) [`772e735`](772e735) Thanks [@tkattkat](https://github.com/tkattkat)! - Add example using playwright screen recording ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`ab51232`](ab51232), [`c76ade0`](c76ade0), [`ffb5e5d`](ffb5e5d), [`772e735`](772e735)]: - @browserbasehq/[email protected] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/[email protected] ### Patch Changes - [#1273](browserbase/stagehand#1273) [`ab51232`](browserbase/stagehand@ab51232) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: trigger shadow root rerender in OOPIFs by cloning & replacing instead of reloading - [#1268](browserbase/stagehand#1268) [`c76ade0`](browserbase/stagehand@c76ade0) Thanks [@tkattkat](https://github.com/tkattkat)! - Expose reasoning, and cached input tokens in stagehand metrics - [#1267](browserbase/stagehand#1267) [`ffb5e5d`](browserbase/stagehand@ffb5e5d) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: file uploads failing on Browserbase - [#1269](browserbase/stagehand#1269) [`772e735`](browserbase/stagehand@772e735) Thanks [@tkattkat](https://github.com/tkattkat)! - Add example using playwright screen recording ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`ab51232`](browserbase/stagehand@ab51232), [`c76ade0`](browserbase/stagehand@c76ade0), [`ffb5e5d`](browserbase/stagehand@ffb5e5d), [`772e735`](browserbase/stagehand@772e735)]: - @browserbasehq/[email protected] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
currently we do not expose reasoning, and cache tokens in our usage metrics
what changed
Reasoning, and cache tokens, are now exposed through stagehand metrics
test plan
tested locally
tested on api