-
Notifications
You must be signed in to change notification settings - Fork 620
support telemetry for cua agent #694
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
support telemetry for cua agent #694
Conversation
🦋 Changeset detectedLatest commit: 822db17 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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.
PR Summary
Added telemetry tracking capabilities for Computer Use Assistant (CUA) agents, implementing token usage and inference time metrics across the Stagehand system.
- Added
usage
property inAgentResult
interface to track input/output tokens and inference time - Extended
StagehandMetrics
withagentPromptTokens
,agentCompletionTokens
, andagentInferenceTimeMs
- Implemented token tracking in
AnthropicCUAClient
andOpenAICUAClient
with proper error handling - Added
AGENT
toStagehandFunctionName
enum and updatedupdateMetrics
method inlib/index.ts
- Modified
StagehandAgentHandler
to pass Stagehand instance for metrics access
6 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
const startTime = Date.now(); | ||
// Create the message using the Anthropic Messages API | ||
// @ts-expect-error - The Anthropic SDK types are stricter than what we need | ||
const response = await this.client.beta.messages.create(requestParams); | ||
const endTime = Date.now(); |
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.
style: Consider wrapping API call in try/catch to ensure inference time is always measured correctly, even if API call fails
const startTime = Date.now(); | |
// Create the message using the Anthropic Messages API | |
// @ts-expect-error - The Anthropic SDK types are stricter than what we need | |
const response = await this.client.beta.messages.create(requestParams); | |
const endTime = Date.now(); | |
const startTime = Date.now(); | |
let response; | |
try { | |
// Create the message using the Anthropic Messages API | |
// @ts-expect-error - The Anthropic SDK types are stricter than what we need | |
response = await this.client.beta.messages.create(requestParams); | |
} finally { | |
const endTime = Date.now(); |
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.
Tested locally with a single agent and two agent instances
why
what changed
stagehand.metrics
for cua agenttest plan