Files
api_health/agent/infra/tools/web/search.js
T
2026-10-28 11:15:29 +08:00

50 lines
1.3 KiB
JavaScript

import { TavilySearch } from "@langchain/tavily";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
import config from "../../../../config.js";
const webSearchTool = tool(
async ({
query,
maxResults = 5,
topic = "general",
includeRawContent = false,
}) => {
const tavilySearch = new TavilySearch({
maxResults,
tavilyApiKey: config.agent.tavily.apiKey,
includeRawContent,
topic,
});
return await tavilySearch._call({ query });
},
{
name: "web_search",
description:
"联网搜索公开网页信息,返回摘要与链接。适合查询医院公示、就医政策、停诊/号源公告等时效性信息。",
schema: z.object({
query: z.string().describe("搜索关键词或问题"),
maxResults: z
.number()
.int()
.min(1)
.max(10)
.optional()
.default(5)
.describe("返回结果数量(1-10),默认 5"),
topic: z
.enum(["general", "news", "finance"])
.optional()
.default("general")
.describe("搜索主题,政策/新闻类查询建议用 news"),
includeRawContent: z
.boolean()
.optional()
.default(false)
.describe("是否返回网页原文(内容较长,默认关闭)"),
}),
},
);
export { webSearchTool };