Skip to content

Commit 5fb9785

Browse files
github-actions[bot]Chromie Botclaudemiguelg719chromiebot
authored
[Claimed browserbase#1960] chore: update examples (browserbase#1964)
Mirrored from external contributor PR browserbase#1960 after approval by @miguelg719. Original author: @chromiebot Original PR: browserbase#1960 Approved source head SHA: `b013423199f609fc744a7f23127511929a1ec0fc` @chromiebot, please continue any follow-up discussion on this mirrored PR. When the external PR gets new commits, this same internal PR will be marked stale until the latest external commit is approved and refreshed here. ## Original description # why Examples were quite stale # what changed Overhaul of examples/ and minor cleanups # test plan <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Standardizes non-CUA examples to use model strings with built-in API key resolution. Updates the MCP demo to the current agent API, replaces deprecated OpenAI model names, and removes dead eval/client code to reduce boilerplate. - **Refactors** - Switched examples to model strings (e.g., `openai/gpt-5`) without inline API keys when `env: "BROWSERBASE"`; kept a LOCAL override in `parameterize-api-key.ts` using `gpt-4.1-mini`. - Updated `mcp.ts` to current agent API: `connectToMCPServer`, `mode: "hybrid"`, model `anthropic/claude-sonnet-4-6`, and a `systemPrompt`. - Replaced deprecated OpenAI models in custom-client examples: `gpt-4o` → `gpt-4.1`, `gpt-4o-mini` → `gpt-4.1-mini`; replaced `V3` with `Stagehand` in `v3-example.ts` and `v3-agent.ts`, and fixed imports to `../lib/v3/*`. - Removed dead code (examples `external_clients/*`, evals `llm_clients` and category, `examples/CHANGELOG.md`, `examples/tsconfig.json`) and added a patch changeset. <sup>Written for commit 959d706. Summary will update on new commits. <a href="https://cubic.dev/pr/browserbase/stagehand/pull/1964">Review in cubic</a></sup> <!-- End of auto-generated description by cubic. --> <!-- external-contributor-pr:owned source-pr=1960 source-sha=b013423199f609fc744a7f23127511929a1ec0fc claimer=miguelg719 --> --------- Co-authored-by: Chromie Bot <chromie@browserbase.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: miguel <miguelg71921@gmail.com> Co-authored-by: Chromie <miguel@browserbase.com>
1 parent 5c889df commit 5fb9785

37 files changed

Lines changed: 100 additions & 557 deletions

.changeset/pretty-windows-cut.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
chore: update examples

packages/core/examples/CHANGELOG.md

Lines changed: 0 additions & 64 deletions
This file was deleted.

packages/core/examples/actionable_observe_example.ts renamed to packages/core/examples/actionable-observe-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* - Hiding sensitive information from LLMs
1010
*
1111
* For more on caching, see: https://docs.stagehand.dev/examples/caching
12-
* Also check out the form_filling_sensible.ts example for a more complex example of using observe() to fill out a form.
12+
* Also check out the form-filling-sensible.ts example for a more complex example of using observe() to fill out a form.
1313
*/
1414

1515
import { Action, Stagehand } from "../lib/v3/index.js";
File renamed without changes.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Stagehand } from "../../lib/v3/index.js";
2-
import { v3Logger } from "../../lib/v3/logger.js";
1+
import { Stagehand } from "../lib/v3/index.js";
2+
import { v3Logger } from "../lib/v3/logger.js";
33

44
async function runDemo(runNumber: number) {
55
const startTime = Date.now();
@@ -12,7 +12,6 @@ async function runDemo(runNumber: number) {
1212

1313
const stagehand = new Stagehand({
1414
env: "BROWSERBASE",
15-
disableAPI: false,
1615
verbose: 1,
1716
cacheDir: "cua-agent-cache",
1817
});

packages/core/examples/custom_client_aisdk.ts renamed to packages/core/examples/custom-client-aisdk.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/**
22
* This example shows how to use the Vercel AI SDK to power the Stagehand LLM Client.
33
*
4-
* You will need to reference the AI SDK Client in /external_clients/aisdk.ts
5-
*
64
* To learn more about the Vercel AI SDK, see: https://sdk.vercel.ai/docs
75
*/
8-
import { Stagehand } from "../lib/v3/index.js";
9-
import { AISdkClient } from "./external_clients/aisdk.js";
6+
import { AISdkClient, Stagehand } from "../lib/v3/index.js";
107
import { z } from "zod";
118
import { openai } from "@ai-sdk/openai";
129

@@ -15,7 +12,7 @@ async function example() {
1512
env: "BROWSERBASE",
1613
verbose: 1,
1714
llmClient: new AISdkClient({
18-
model: openai("gpt-4o"),
15+
model: openai("gpt-4.1"),
1916
}),
2017
});
2118

packages/core/examples/custom_client_langchain.ts renamed to packages/core/examples/custom-client-langchain.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/**
22
* This example shows how to use the Langchain client with Stagehand.
33
*
4-
* You will need to reference the Langchain Client in /external_clients/langchain.ts
4+
* The LangchainClient is defined in ./langchain-client.ts as it is not
5+
* part of the core Stagehand package.
56
*/
67
import { z } from "zod";
78
import { Stagehand } from "../lib/v3/index.js";
8-
import { LangchainClient } from "./external_clients/langchain.js";
9+
import { LangchainClient } from "./langchain-client.js";
910
import { ChatOpenAI } from "@langchain/openai";
1011

1112
async function example() {
@@ -14,7 +15,7 @@ async function example() {
1415
verbose: 1,
1516
llmClient: new LangchainClient(
1617
new ChatOpenAI({
17-
model: "gpt-4o",
18+
model: "gpt-4.1",
1819
}),
1920
),
2021
});

packages/core/examples/custom_client_openai.ts renamed to packages/core/examples/custom-client-openai.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22
* This example shows how to use a custom OpenAI client with Stagehand.
33
*
44
* The OpenAI API provides a simple, type-safe, and composable way to build AI applications.
5-
*
6-
* You will need to reference the Custom OpenAI Client in /external_clients/customOpenAI.ts
75
*/
8-
import { Stagehand } from "../lib/v3/index.js";
6+
import { CustomOpenAIClient, Stagehand } from "../lib/v3/index.js";
97
import { z } from "zod";
10-
import { CustomOpenAIClient } from "./external_clients/customOpenAI.js";
118
import OpenAI from "openai";
129

1310
async function example() {
1411
const stagehand = new Stagehand({
1512
env: "BROWSERBASE",
1613
verbose: 1,
1714
llmClient: new CustomOpenAIClient({
18-
modelName: "gpt-4o-mini",
15+
modelName: "gpt-4.1-mini",
1916
client: new OpenAI({
2017
apiKey: process.env.OPENAI_API_KEY,
2118
}),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Stagehand } from "../../lib/v3/index.js";
1+
import { Stagehand } from "../lib/v3/index.js";
22

33
async function example(stagehand: Stagehand) {
44
const page = stagehand.context.pages()[0];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Stagehand } from "../../lib/v3/index.js";
1+
import { Stagehand } from "../lib/v3/index.js";
22

33
async function example(stagehand: Stagehand) {
44
const page = stagehand.context.pages()[0];

0 commit comments

Comments
 (0)