Skip to content

add hooks to agent #615

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

sameelarif
Copy link
Member

@sameelarif sameelarif commented Mar 30, 2025

why

To extend the functionality of the execute function. This allows people to further build off of our agentic loop.

what changed

Added onStep, onSuccess, and onFailure hooks

test plan

Copy link

changeset-bot bot commented Mar 30, 2025

🦋 Changeset detected

Latest commit: df45905

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@browserbasehq/stagehand Minor

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

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Overall, the PR integrates new callback hooks into agent execution and refines type definitions to enforce stricter configuration. Key changes include:

• Updated lib/agent/AnthropicCUAClient.ts and lib/agent/OpenAICUAClient.ts to invoke onStep, onSuccess, and onFailure hooks during execution.
• Modified examples/cua-example.ts to use the updated "computer-use-preview" model.
• Enhanced hook propagation and error handling in lib/handlers/operatorHandler.ts and lib/handlers/agentHandler.ts.
• Revised types/agent.ts and types/stagehand.ts to introduce and enforce new hook and config definitions.

💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!

9 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@sameelarif sameelarif requested a review from kamath March 30, 2025 03:02
);
let playwrightArguments: ObserveResult | undefined;
if (result.method === "act") {
[playwrightArguments] = await this.stagehandPage.page.observe(
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't the stagehandPage object already have act/extract observe?

completed:
actions.length > 0
? (actions[actions.length - 1].taskCompleted as boolean)
: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was a good catch/suggestion, but I'm p sure we should throw an error here not return false. The previous code was kinda catching this without being informative

Copy link
Collaborator

Choose a reason for hiding this comment

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

just need to confirm cases where the agent sends a message without taking an action?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants