Skip to content

Commit a142e24

Browse files
committed
Update README
1 parent 9f328d3 commit a142e24

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

README.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,49 @@ npm install @lightfeed/browser-agent
3636

3737
## Example
3838

39-
Find YC companies in the B2B Legal industry that are hiring now. Navigation (filter the directory) is the expensive-but-stable part; extraction is the live-data part.
39+
Go to the Hacker News Show section, click through to the next page, and grab the top 3 posts. Navigation (open Show, paginate) is the expensive-but-stable part; extraction is the live-data part.
4040

4141
```typescript
4242
import { BrowserAgent } from "@lightfeed/browser-agent";
43-
import { ChatOpenAI } from "@langchain/openai";
43+
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
4444
import { z } from "zod";
4545

4646
const agent = new BrowserAgent({
4747
browserProvider: "Local",
48-
llm: new ChatOpenAI({ model: "gpt-4.1-mini" }),
48+
llm: new ChatGoogleGenerativeAI({ model: "gemini-2.5-flash" }),
4949
});
5050

5151
const page = await agent.newPage();
5252

5353
// 1. AI navigation — recordable, replayable.
5454
const nav = await page.ai(
55-
"Find YC companies in B2B legal industry that are hiring now"
55+
"Go to news.ycombinator.com, open the Show section, then click 'More' to go to the next page"
5656
);
57-
await agent.savePlan("yc b2b-legal hiring", nav, "./yc.plan.json");
57+
await agent.savePlan("hn show page 2", nav, "./hn.plan.json");
5858

5959
// 2. AI extraction — typed by a Zod schema, runs AI every call.
60-
const { companies } = await page.extract(
61-
"All companies currently shown",
60+
const { articles } = await page.extract(
61+
"The top 3 articles on this page",
6262
z.object({
63-
companies: z.array(z.object({
64-
name: z.string(),
65-
url: z.string(),
66-
batch: z.string(),
67-
})),
63+
articles: z
64+
.array(
65+
z.object({
66+
title: z.string(),
67+
url: z.string(),
68+
points: z.number(),
69+
commentsUrl: z.string(),
70+
})
71+
)
72+
.max(3),
6873
})
6974
);
7075
```
7176

7277
Every subsequent run — navigation is free:
7378

7479
```typescript
75-
await agent.replay("./yc.plan.json", { page }); // zero tokens
76-
const { companies } = await page.extract(/* ... */); // tokens only here
80+
await agent.replay("./hn.plan.json", { page }); // zero tokens
81+
const { articles } = await page.extract(/* ... */); // tokens only here
7782
```
7883

7984
## `page.ai` vs `agent.executeTask` vs `agent.executeTaskAsync`
@@ -102,17 +107,17 @@ Everything above is available without writing code:
102107

103108
```bash
104109
# Record while running
105-
browser-agent-cli run --save-plan ./yc.plan.json \
106-
-c "Find YC companies in B2B legal industry that are hiring now"
110+
browser-agent-cli run --save-plan ./hn.plan.json \
111+
-c "Go to news.ycombinator.com, open the Show section, then click 'More' to go to the next page"
107112

108113
# Replay (zero LLM calls)
109-
browser-agent-cli replay ./yc.plan.json
114+
browser-agent-cli replay ./hn.plan.json
110115

111116
# Self-heal drifted steps
112-
browser-agent-cli replay ./yc.plan.json --ai-fallback
117+
browser-agent-cli replay ./hn.plan.json --ai-fallback
113118

114-
# Retarget at a different URL
115-
browser-agent-cli replay ./yc.plan.json --url https://staging.example.com/
119+
# Retarget at a different URL (e.g. start from the Ask section instead)
120+
browser-agent-cli replay ./hn.plan.json --url https://news.ycombinator.com/ask
116121
```
117122

118123
LLM auto-detected from `GOOGLE_API_KEY` / `GEMINI_API_KEY``OPENAI_API_KEY``ANTHROPIC_API_KEY`. Override the model with `--llm-model` or `GEMINI_MODEL` / `OPENAI_MODEL` / `ANTHROPIC_MODEL`. `replay` only needs an LLM with `--ai-fallback`. Interactive: `ctrl+p` pause, `ctrl+r` resume.

0 commit comments

Comments
 (0)