import { HaiAgentsClient } from "hai-agents";
import { z } from "zod";
const Sources = z.object({
sources: z.array(z.object({ title: z.string(), url: z.string(), excerpt: z.string() })),
});
const Brief = z.object({
url: z.string(),
summary: z.string(),
keyFacts: z.array(z.string()),
});
const client = new HaiAgentsClient();
const scout = await client.runSession({
agent: "h/web-surfer-flash",
messages: "Find the 5 highest-value sources on EU AI Act enforcement",
answerSchema: Sources,
});
const readers = await Promise.all(
(scout.answer?.sources ?? []).map((source) =>
client.runSession({
agent: "h/web-surfer-flash",
messages: `Read this source and extract the key facts: ${source.url}`,
overrides: { "agent.environments[kind=web].start_url": source.url },
answerSchema: Brief,
}),
),
);
for (const reader of readers) {
console.log(reader.answer?.url, reader.answer?.keyFacts);
}