Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/salty-moles-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

add pageurl & timestamp to agent actions
5 changes: 5 additions & 0 deletions .changeset/upset-ideas-fall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

Add pageUrl & timestamp to agent actions
6 changes: 6 additions & 0 deletions lib/handlers/cuaAgentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class CuaAgentHandler {

// Set up action handler for any client type
this.agentClient.setActionHandler(async (action) => {
action.pageUrl = this.page.url();

// Default delay between actions (1 second if not specified)
const defaultDelay = 1000;
// Use specified delay or default
Expand All @@ -80,6 +82,8 @@ export class CuaAgentHandler {
defaultDelay;

try {
this.updateClientUrl();

// Try to inject cursor before each action if enabled
if (this.highlightCursor) {
try {
Expand All @@ -95,6 +99,8 @@ export class CuaAgentHandler {
// Execute the action
await this.executeAction(action);

action.timestamp = Date.now();

// Add a delay after the action for better visibility
await new Promise((resolve) => setTimeout(resolve, waitBetweenActions));

Expand Down
5 changes: 5 additions & 0 deletions lib/handlers/stagehandAgentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class StagehandAgentHandler {
let completed = false;
const collectedReasoning: string[] = [];

let currentPageUrl = this.stagehand.page.url();

this.logger({
category: "agent",
message: `Executing agent task: ${options.instruction}`,
Expand Down Expand Up @@ -184,16 +186,19 @@ export class StagehandAgentHandler {
const action: AgentAction = {
type: toolCall.toolName,
reasoning: event.text || undefined,
pageUrl: currentPageUrl,
taskCompleted:
toolCall.toolName === "close"
? (args?.success as boolean)
: false,
timestamp: Date.now(),
...args,
...getPlaywrightArguments(),
};

actions.push(action);
}
currentPageUrl = this.stagehand.page.url();
}
},
});
Expand Down
1 change: 1 addition & 0 deletions types/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface AgentAction {
// Tool-specific fields
timeMs?: number; // wait tool
pageText?: string; // ariaTree tool
timestamp?: number;
pageUrl?: string; // ariaTree tool
instruction?: string; // various tools
playwrightArguments?: ObserveResult | null; // act tool
Expand Down