Skip to content

Commit ecffbb9

Browse files
add a simple prompting guide (#138)
* add a simple prompting guide * Update README.md --------- Co-authored-by: Paul Klein <paulleoklein@gmail.com>
1 parent 6e62fa7 commit ecffbb9

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [observe()](#observe)
2828
- [Model Support](#model-support)
2929
- [How It Works](#how-it-works)
30+
- [Prompting Tips](#prompting-tips)
3031
- [Roadmap](#roadmap)
3132
- [Contributing](#contributing)
3233
- [Acknowledgements](#acknowledgements)
@@ -318,6 +319,77 @@ In the case of action, we ask the LLM to write a playwright method in order to d
318319

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

322+
## Prompting Tips
323+
324+
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:
325+
326+
### Do:
327+
328+
- **Use specific and concise actions**
329+
330+
```javascript
331+
await stagehand.act({ action: "click the login button" });
332+
333+
const productInfo = await stagehand.extract({
334+
instruction: "find the red shoes",
335+
schema: z.object({
336+
productName: z.string(),
337+
price: z.number(),
338+
}),
339+
});
340+
```
341+
342+
- **Break down complex tasks into smaller, atomic steps**
343+
344+
Instead of combining actions:
345+
```javascript
346+
// Avoid this
347+
await stagehand.act({ action: "log in and purchase the first item" });
348+
```
349+
350+
Split them into individual steps:
351+
```javascript
352+
await stagehand.act({ action: "click the login button" });
353+
// ...additional steps to log in...
354+
await stagehand.act({ action: "click on the first item" });
355+
await stagehand.act({ action: "click the purchase button" });
356+
```
357+
358+
- **Use `observe()` to get actionable suggestions from the current page**
359+
360+
```javascript
361+
const actions = await stagehand.observe();
362+
console.log("Possible actions:", actions);
363+
```
364+
365+
### Don't:
366+
367+
- **Use broad or ambiguous instructions**
368+
369+
```javascript
370+
// Too vague
371+
await stagehand.act({ action: "find something interesting on the page" });
372+
```
373+
374+
- **Combine multiple actions into one instruction**
375+
376+
```javascript
377+
// Avoid combining actions
378+
await stagehand.act({ action: "fill out the form and submit it" });
379+
```
380+
381+
- **Expect Stagehand to perform high-level planning or reasoning**
382+
383+
```javascript
384+
// Outside Stagehand's scope
385+
await stagehand.act({ action: "book the cheapest flight available" });
386+
```
387+
388+
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.
389+
390+
We leave the agentic behaviour to higher-level agentic systems which can use Stagehand as a tool.
391+
392+
321393
## Roadmap
322394

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

0 commit comments

Comments
 (0)