Skip to content

Commit

Permalink
add a simple prompting guide (#138)
Browse files Browse the repository at this point in the history
* add a simple prompting guide

* Update README.md

---------

Co-authored-by: Paul Klein <[email protected]>
  • Loading branch information
filip-michalsky and pkiv authored Oct 29, 2024
1 parent 6e62fa7 commit ecffbb9
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [observe()](#observe)
- [Model Support](#model-support)
- [How It Works](#how-it-works)
- [Prompting Tips](#prompting-tips)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [Acknowledgements](#acknowledgements)
Expand Down Expand Up @@ -318,6 +319,77 @@ In the case of action, we ask the LLM to write a playwright method in order to d

Lastly, we use the LLM to write future instructions to itself to help manage it's progress and goals when operating across chunks.

## Prompting Tips

Prompting Stagehand is more literal and atomic than other higher level frameworks, including agentic frameworks. Here are some guidelines to help you craft effective prompts:

### Do:

- **Use specific and concise actions**

```javascript
await stagehand.act({ action: "click the login button" });

const productInfo = await stagehand.extract({
instruction: "find the red shoes",
schema: z.object({
productName: z.string(),
price: z.number(),
}),
});
```

- **Break down complex tasks into smaller, atomic steps**

Instead of combining actions:
```javascript
// Avoid this
await stagehand.act({ action: "log in and purchase the first item" });
```

Split them into individual steps:
```javascript
await stagehand.act({ action: "click the login button" });
// ...additional steps to log in...
await stagehand.act({ action: "click on the first item" });
await stagehand.act({ action: "click the purchase button" });
```

- **Use `observe()` to get actionable suggestions from the current page**

```javascript
const actions = await stagehand.observe();
console.log("Possible actions:", actions);
```

### Don't:

- **Use broad or ambiguous instructions**

```javascript
// Too vague
await stagehand.act({ action: "find something interesting on the page" });
```

- **Combine multiple actions into one instruction**

```javascript
// Avoid combining actions
await stagehand.act({ action: "fill out the form and submit it" });
```

- **Expect Stagehand to perform high-level planning or reasoning**

```javascript
// Outside Stagehand's scope
await stagehand.act({ action: "book the cheapest flight available" });
```

By following these guidelines, you'll increase the reliability and effectiveness of your web automations with Stagehand. Remember, Stagehand excels at executing precise, well-defined actions so keeping your instructions atomic will lead to the best outcomes.

We leave the agentic behaviour to higher-level agentic systems which can use Stagehand as a tool.


## Roadmap

At a high level, we're focused on improving reliability, speed, and cost in that order of priority.
Expand Down

0 comments on commit ecffbb9

Please sign in to comment.