feat: add websearch tools

This commit is contained in:
Tim
2025-10-29 17:54:06 +08:00
parent bed72662b5
commit 784057207f

View File

@@ -1,4 +1,4 @@
import { Agent, Runner, hostedMcpTool, withTrace } from "@openai/agents";
import { Agent, Runner, hostedMcpTool, withTrace, webSearchTool } from "@openai/agents";
export type WorkflowInput = { input_as_text: string };
@@ -6,8 +6,9 @@ export abstract class BotFather {
protected readonly openisleToken = (process.env.OPENISLE_TOKEN ?? "").trim();
protected readonly weatherToken = (process.env.APIFY_API_TOKEN ?? "").trim();
protected readonly mcp = this.createHostedMcpTool();
protected readonly openisleMcp = this.createHostedMcpTool();
protected readonly weatherMcp = this.createWeatherMcpTool();
protected readonly webSearchPreview = this.createWebSearchPreviewTool();
protected readonly agent: Agent;
constructor(protected readonly name: string) {
@@ -27,7 +28,11 @@ export abstract class BotFather {
this.agent = new Agent({
name: this.name,
instructions: this.buildInstructions(),
tools: [this.mcp, this.weatherMcp],
tools: [
this.openisleMcp,
this.weatherMcp,
this.webSearchPreview
],
model: "gpt-4o",
modelSettings: {
temperature: 0.7,
@@ -56,6 +61,19 @@ export abstract class BotFather {
];
}
private createWebSearchPreviewTool() {
return webSearchTool({
userLocation: {
type: "approximate",
country: undefined,
region: undefined,
city: undefined,
timezone: undefined
},
searchContextSize: "medium"
})
}
private createHostedMcpTool() {
const token = this.openisleToken;
const authConfig = token