研究问题往往没有单一来源。例如:今年哪些欧洲首都修改了短租规定,具体改了什么?这需要搜索、仔细阅读多篇网页、发现矛盾,并写出说明事实出处的总结。Gemini 4 Argon 适合这种深入工作。本教程会在本地智能体中接入网页搜索、页面抓取和文件写入工具。
创建研究智能体
智能体只获得所需工具:用搜索发现来源、用 `fetch` 阅读网页、用 `write` 保存备忘录、用 `todo_write` 制订计划。搜索和读取网页会消耗额度,因此设置预算和步骤上限。
import { IaGenify } from "iagenify";
const api = new IaGenify({ apiKey: process.env.IAGENIFY_API_KEY });
const pc = await api.storage.get();
const agent = api.agents.create({
runtime: "local",
machine: pc,
model: "gemini-4-argon",
tools: ["search", "fetch", "write", "todo_write"],
mode: "auto",
budget: 150,
maxSteps: 40,
system: "You are a careful researcher. Every factual sentence in your memo cites the URL you read it on. Say when sources disagree.",
});
const result = await agent.run({
message: "Research which European capitals changed their short-term rental rules in 2026. Read at least eight official or primary sources. Write the memo to Research/rentals-2026.md with a sources section.",
});
console.log(result.usage.credits, result.stopReason);把备忘录转换为结构化数据
备忘录供人阅读。第二次使用 Schema 的模型调用会将发现提取为 JSON:每座城市一个条目,并包含对应来源。
const memo = await pc.files.read("Research/rentals-2026.md");
const extractor = await api.models.create({
model: "gemini-4-argon",
memory: false,
schema: {
type: "object",
properties: {
cities: {
type: "array",
items: {
type: "object",
properties: {
city: { type: "string" },
change: { type: "string", description: "What changed, in one sentence" },
effective: { type: "string", description: "ISO 8601 date, or empty if unknown" },
source: { type: "string", description: "The URL this finding relies on" },
},
required: ["city", "change", "source"],
},
},
},
required: ["cities"],
},
});
const { outputs } = await extractor.generate({ inputs: [{ type: "text", content: memo.content }] });
console.log(outputs[0].content.cities);发布前核查
带引用的备忘录更容易核查,但这不代表内容已自动验证。请打开重要来源,并由人对结论负责。
参考资料
常见问题
为什么用智能体,而不是一个很长的提示词?
因为来源事先未知:智能体会搜索、阅读找到的内容,并判断下一步还要查什么。
一次运行最多会花多少?
不会超过预算;本例为 150 个额度。运行会在超出前停止,并通过 `stopReason` 报告原因。