forked from firecrawl/web-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-streaming.ts
More file actions
29 lines (24 loc) · 890 Bytes
/
Copy path5-streaming.ts
File metadata and controls
29 lines (24 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* 5. Streaming - real-time event stream of agent progress
*
* npx tsx examples/5-streaming.ts
*/
import { createAgent } from "../src";
if (!process.env.FIRECRAWL_API_KEY) { console.error("\n FIRECRAWL_API_KEY not set. Get one at https://firecrawl.dev/app/api-keys\n"); process.exit(1); }
const agent = createAgent({
firecrawlApiKey: process.env.FIRECRAWL_API_KEY,
model: { provider: "google", model: "gemini-3-flash-preview" },
});
let stepCount = 0;
for await (const event of agent.stream({
prompt: "Find the 5 most recent YC-backed AI startups and their founders",
})) {
if (event.type === "text") {
process.stdout.write(event.content ?? "");
} else if (event.type === "tool-call") {
console.log(`\n [${event.toolName}]`);
} else if (event.type === "done") {
stepCount = event.steps?.length ?? 0;
}
}
console.log("\n\nDone. Steps:", stepCount);