Skip to main content

Use Cursor rules for better AI suggestions

Most of the Stagehand team uses Cursor to write code. Cursor has a feature called rules that allows you to customize the AI’s behavior. You can use these rules to make the AI more accurate when suggesting actions. For Stagehand’s Cursor rules, check out this file. If you’re using Windsurf, you can use the same rules by adding them to your .windsurfrules file.

Avoid sending sensitive information to LLMs

You can use variables in an act call to avoid sending sensitive information to LLMs.

Preview actions before running them

You can use observe() to get an action to run without running it. If you’re satisfied with the action, you can run it with act() without any LLM inference.
You can also use observe() with sensitive information, like below.
Use observe() to get actionable suggestions from the current page

Avoid broad or ambiguous instructions

Avoid instructions that aren’t specific to the current page or try to do multiple things at once.

Use observe() to get entire form values

This will return an array of objects with the following shape:
You can then use these actions directly in your code.
For a full example, check out the example in the Stagehand repo here.