Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
47 changes: 47 additions & 0 deletions packages/core/examples/agent_stream_example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Stagehand } from "../lib/v3";
import dotenv from "dotenv";
import chalk from "chalk";

// Load environment variables
dotenv.config();
async function main() {
console.log(`\n${chalk.bold("Stagehand 🤘 Agent Streaming Example")}\n`);
// Initialize Stagehand
const stagehand = new Stagehand({
env: "LOCAL",
verbose: 2,
cacheDir: "stagehand-agent-cache",
logInferenceToFile: false,
experimental: true,
});

await stagehand.init();

try {
const page = stagehand.context.pages()[0];
await page.goto("https://amazon.com");
const agent = stagehand.agent({
model: "anthropic/claude-sonnet-4-5-20250929",
executionModel: "google/gemini-2.5-flash",
});

const result = await agent.stream({
instruction: "go to amazon, and seach for shampoo, stop after searching",
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: typo: "seach" should be "search"

Suggested change
instruction: "go to amazon, and seach for shampoo, stop after searching",
instruction: "go to amazon, and search for shampoo, stop after searching",
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/examples/agent_stream_example.ts
Line: 29:29

Comment:
**syntax:** typo: "seach" should be "search"

```suggestion
      instruction: "go to amazon, and search for shampoo, stop after searching",
```

How can I resolve this? If you propose a fix, please make it concise.

maxSteps: 20,
});
// stream the text
for await (const delta of result.textStream) {
process.stdout.write(delta);
}
// stream everything ( toolcalls, messages, etc.)
// for await (const delta of result.fullStream) {
// console.log(delta);
// }

const finalResult = await result.result;
console.log("Final Result:", finalResult);
} catch (error) {
console.log(`${chalk.red("✗")} Error: ${error}`);
}
}
main();
Loading
Loading