@langchain/openai 1.1.3 → 1.2.0-dev-1765432861398
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +583 -2
- package/dist/azure/chat_models/common.d.cts.map +1 -0
- package/dist/azure/chat_models/common.d.ts.map +1 -0
- package/dist/azure/chat_models/completions.d.cts.map +1 -0
- package/dist/azure/chat_models/completions.d.ts.map +1 -0
- package/dist/azure/chat_models/index.d.cts +1 -1
- package/dist/azure/chat_models/index.d.cts.map +1 -0
- package/dist/azure/chat_models/index.d.ts.map +1 -0
- package/dist/azure/chat_models/responses.d.cts.map +1 -0
- package/dist/azure/chat_models/responses.d.ts.map +1 -0
- package/dist/azure/embeddings.d.cts.map +1 -0
- package/dist/azure/embeddings.d.ts.map +1 -0
- package/dist/azure/llms.d.cts +0 -1
- package/dist/azure/llms.d.cts.map +1 -0
- package/dist/azure/llms.d.ts +0 -1
- package/dist/azure/llms.d.ts.map +1 -0
- package/dist/chat_models/base.cjs +5 -1
- package/dist/chat_models/base.cjs.map +1 -1
- package/dist/chat_models/base.d.cts +8 -22
- package/dist/chat_models/base.d.cts.map +1 -0
- package/dist/chat_models/base.d.ts +6 -20
- package/dist/chat_models/base.d.ts.map +1 -0
- package/dist/chat_models/base.js +6 -2
- package/dist/chat_models/base.js.map +1 -1
- package/dist/chat_models/completions.cjs.map +1 -1
- package/dist/chat_models/completions.d.cts +1 -3
- package/dist/chat_models/completions.d.cts.map +1 -0
- package/dist/chat_models/completions.d.ts +1 -3
- package/dist/chat_models/completions.d.ts.map +1 -0
- package/dist/chat_models/completions.js.map +1 -1
- package/dist/chat_models/index.d.cts +42 -4
- package/dist/chat_models/index.d.cts.map +1 -0
- package/dist/chat_models/index.d.ts +42 -4
- package/dist/chat_models/index.d.ts.map +1 -0
- package/dist/chat_models/responses.d.cts +2 -2
- package/dist/chat_models/responses.d.cts.map +1 -0
- package/dist/chat_models/responses.d.ts +2 -2
- package/dist/chat_models/responses.d.ts.map +1 -0
- package/dist/converters/completions.cjs +22 -12
- package/dist/converters/completions.cjs.map +1 -1
- package/dist/converters/completions.d.cts +0 -1
- package/dist/converters/completions.d.cts.map +1 -0
- package/dist/converters/completions.d.ts +0 -1
- package/dist/converters/completions.d.ts.map +1 -0
- package/dist/converters/completions.js +23 -13
- package/dist/converters/completions.js.map +1 -1
- package/dist/converters/responses.cjs +37 -4
- package/dist/converters/responses.cjs.map +1 -1
- package/dist/converters/responses.d.cts.map +1 -0
- package/dist/converters/responses.d.ts.map +1 -0
- package/dist/converters/responses.js +39 -6
- package/dist/converters/responses.js.map +1 -1
- package/dist/embeddings.d.cts +0 -1
- package/dist/embeddings.d.cts.map +1 -0
- package/dist/embeddings.d.ts +0 -1
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -3
- package/dist/index.js +2 -2
- package/dist/llms.d.cts +0 -1
- package/dist/llms.d.cts.map +1 -0
- package/dist/llms.d.ts +0 -1
- package/dist/llms.d.ts.map +1 -0
- package/dist/tools/applyPatch.cjs +116 -0
- package/dist/tools/applyPatch.cjs.map +1 -0
- package/dist/tools/applyPatch.d.cts +148 -0
- package/dist/tools/applyPatch.d.cts.map +1 -0
- package/dist/tools/applyPatch.d.ts +148 -0
- package/dist/tools/applyPatch.d.ts.map +1 -0
- package/dist/tools/applyPatch.js +115 -0
- package/dist/tools/applyPatch.js.map +1 -0
- package/dist/tools/codeInterpreter.cjs +95 -0
- package/dist/tools/codeInterpreter.cjs.map +1 -0
- package/dist/tools/codeInterpreter.d.cts +125 -0
- package/dist/tools/codeInterpreter.d.cts.map +1 -0
- package/dist/tools/codeInterpreter.d.ts +125 -0
- package/dist/tools/codeInterpreter.d.ts.map +1 -0
- package/dist/tools/codeInterpreter.js +94 -0
- package/dist/tools/codeInterpreter.js.map +1 -0
- package/dist/tools/computerUse.cjs +240 -0
- package/dist/tools/computerUse.cjs.map +1 -0
- package/dist/tools/computerUse.d.cts +234 -0
- package/dist/tools/computerUse.d.cts.map +1 -0
- package/dist/tools/computerUse.d.ts +234 -0
- package/dist/tools/computerUse.d.ts.map +1 -0
- package/dist/tools/computerUse.js +239 -0
- package/dist/tools/computerUse.js.map +1 -0
- package/dist/tools/custom.d.cts +1 -1
- package/dist/tools/custom.d.cts.map +1 -0
- package/dist/tools/custom.d.ts.map +1 -0
- package/dist/tools/dalle.d.cts +1 -2
- package/dist/tools/dalle.d.cts.map +1 -0
- package/dist/tools/dalle.d.ts +1 -2
- package/dist/tools/dalle.d.ts.map +1 -0
- package/dist/tools/fileSearch.cjs +137 -0
- package/dist/tools/fileSearch.cjs.map +1 -0
- package/dist/tools/fileSearch.d.cts +224 -0
- package/dist/tools/fileSearch.d.cts.map +1 -0
- package/dist/tools/fileSearch.d.ts +224 -0
- package/dist/tools/fileSearch.d.ts.map +1 -0
- package/dist/tools/fileSearch.js +136 -0
- package/dist/tools/fileSearch.js.map +1 -0
- package/dist/tools/imageGeneration.cjs +128 -0
- package/dist/tools/imageGeneration.cjs.map +1 -0
- package/dist/tools/imageGeneration.d.cts +199 -0
- package/dist/tools/imageGeneration.d.cts.map +1 -0
- package/dist/tools/imageGeneration.d.ts +199 -0
- package/dist/tools/imageGeneration.d.ts.map +1 -0
- package/dist/tools/imageGeneration.js +127 -0
- package/dist/tools/imageGeneration.js.map +1 -0
- package/dist/tools/index.cjs +26 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.d.cts +27 -0
- package/dist/tools/index.d.cts.map +1 -0
- package/dist/tools/index.d.ts +27 -1
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +26 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/localShell.cjs +145 -0
- package/dist/tools/localShell.cjs.map +1 -0
- package/dist/tools/localShell.d.cts +167 -0
- package/dist/tools/localShell.d.cts.map +1 -0
- package/dist/tools/localShell.d.ts +167 -0
- package/dist/tools/localShell.d.ts.map +1 -0
- package/dist/tools/localShell.js +144 -0
- package/dist/tools/localShell.js.map +1 -0
- package/dist/tools/mcp.cjs +53 -0
- package/dist/tools/mcp.cjs.map +1 -0
- package/dist/tools/mcp.d.cts +177 -0
- package/dist/tools/mcp.d.cts.map +1 -0
- package/dist/tools/mcp.d.ts +177 -0
- package/dist/tools/mcp.d.ts.map +1 -0
- package/dist/tools/mcp.js +52 -0
- package/dist/tools/mcp.js.map +1 -0
- package/dist/tools/shell.cjs +163 -0
- package/dist/tools/shell.cjs.map +1 -0
- package/dist/tools/shell.d.cts +221 -0
- package/dist/tools/shell.d.cts.map +1 -0
- package/dist/tools/shell.d.ts +221 -0
- package/dist/tools/shell.d.ts.map +1 -0
- package/dist/tools/shell.js +162 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/tools/webSearch.cjs +73 -0
- package/dist/tools/webSearch.cjs.map +1 -0
- package/dist/tools/webSearch.d.cts +130 -0
- package/dist/tools/webSearch.d.cts.map +1 -0
- package/dist/tools/webSearch.d.ts +130 -0
- package/dist/tools/webSearch.d.ts.map +1 -0
- package/dist/tools/webSearch.js +72 -0
- package/dist/tools/webSearch.js.map +1 -0
- package/dist/types.d.cts +2 -4
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +1 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/azure.d.cts +1 -5
- package/dist/utils/azure.d.cts.map +1 -0
- package/dist/utils/azure.d.ts +1 -5
- package/dist/utils/azure.d.ts.map +1 -0
- package/dist/utils/client.d.cts.map +1 -0
- package/dist/utils/client.d.ts.map +1 -0
- package/dist/utils/misc.cjs +6 -0
- package/dist/utils/misc.cjs.map +1 -1
- package/dist/utils/misc.d.cts +1 -1
- package/dist/utils/misc.d.cts.map +1 -0
- package/dist/utils/misc.d.ts +1 -1
- package/dist/utils/misc.d.ts.map +1 -0
- package/dist/utils/misc.js +6 -1
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/prompts.d.cts +0 -1
- package/dist/utils/prompts.d.cts.map +1 -0
- package/dist/utils/prompts.d.ts +0 -1
- package/dist/utils/prompts.d.ts.map +1 -0
- package/dist/utils/tools.cjs +39 -1
- package/dist/utils/tools.cjs.map +1 -1
- package/dist/utils/tools.d.cts.map +1 -0
- package/dist/utils/tools.d.ts.map +1 -0
- package/dist/utils/tools.js +37 -2
- package/dist/utils/tools.js.map +1 -1
- package/package.json +8 -6
- package/dist/langchain-core/dist/callbacks/base.d.ts +0 -1
- package/dist/langchain-core/dist/callbacks/manager.d.ts +0 -2
- package/dist/langchain-core/dist/documents/transformers.d.ts +0 -2
- package/dist/langchain-core/dist/language_models/base.d.ts +0 -7
- package/dist/langchain-core/dist/language_models/chat_models.d.cts +0 -13
- package/dist/langchain-core/dist/language_models/chat_models.d.ts +0 -23
- package/dist/langchain-core/dist/messages/index.d.ts +0 -1
- package/dist/langchain-core/dist/messages/transformers.d.ts +0 -3
- package/dist/langchain-core/dist/runnables/base.d.ts +0 -7
- package/dist/langchain-core/dist/runnables/config.d.ts +0 -2
- package/dist/langchain-core/dist/runnables/graph.d.ts +0 -1
- package/dist/langchain-core/dist/runnables/types.d.ts +0 -2
- package/dist/langchain-core/dist/tools/index.d.ts +0 -8
- package/dist/langchain-core/dist/tools/types.d.ts +0 -7
- package/dist/langchain-core/dist/tracers/base.d.ts +0 -2
- package/dist/langchain-core/dist/tracers/event_stream.d.ts +0 -2
- package/dist/langchain-core/dist/tracers/log_stream.d.ts +0 -3
- package/dist/langchain-core/dist/types/_internal.d.cts +0 -11
- package/dist/langchain-core/dist/types/_internal.d.ts +0 -11
- package/dist/langchain-core/dist/utils/json_schema.d.ts +0 -1
- package/dist/langchain-core/dist/utils/stream.d.cts +0 -26
- package/dist/langchain-core/dist/utils/stream.d.ts +0 -26
- package/dist/langchain-core/dist/utils/types/index.d.ts +0 -1
- package/dist/langchain-core/dist/utils/types/zod.d.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","names":["z","OpenAI","OpenAIClient","DynamicStructuredTool","ShellAction","Responses","ResponseFunctionShellToolCall","Action","ShellActionSchema","ZodString","ZodArray","ZodNumber","ZodOptional","core","$strip","ZodObject","ShellCommandOutput","ResponseFunctionShellCallOutputContent","ShellCallOutcome","ShellResult","ShellOptions","Promise","ShellTool","FunctionShellTool","shell"],"sources":["../../src/tools/shell.d.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { type DynamicStructuredTool } from \"@langchain/core/tools\";\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like commands array, timeout, and max output length.\n */\nexport type ShellAction = OpenAIClient.Responses.ResponseFunctionShellToolCall.Action;\nexport declare const ShellActionSchema: z.ZodObject<{\n commands: z.ZodArray<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n max_output_length: z.ZodOptional<z.ZodNumber>;\n}, z.core.$strip>;\n/**\n * Result of a single shell command execution.\n * Contains stdout, stderr, and the outcome (exit code or timeout).\n */\nexport type ShellCommandOutput = OpenAIClient.Responses.ResponseFunctionShellCallOutputContent;\n/**\n * Outcome type for shell command execution - either exit with code or timeout.\n */\nexport type ShellCallOutcome = ShellCommandOutput[\"outcome\"];\n/**\n * Result of executing shell commands.\n * Contains an array of outputs (one per command) and the max_output_length parameter.\n */\nexport interface ShellResult {\n /**\n * Array of command outputs. Each entry corresponds to a command from the action.\n * The order should match the order of commands in the action.\n */\n output: ShellCommandOutput[];\n /**\n * The max_output_length from the action, which must be passed back to the API.\n * If not provided in the action, can be omitted.\n */\n maxOutputLength?: number | null;\n}\n/**\n * Options for the Shell tool.\n */\nexport interface ShellOptions {\n /**\n * Execute function that handles shell command execution.\n * This function receives the action input containing the commands and limits,\n * and should return a ShellResult with stdout, stderr, and outcome for each command.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const outputs = await Promise.all(\n * action.commands.map(async (cmd) => {\n * try {\n * const { stdout, stderr } = await exec(cmd, {\n * timeout: action.timeout_ms ?? undefined,\n * });\n * return {\n * stdout,\n * stderr,\n * outcome: { type: \"exit\" as const, exit_code: 0 },\n * };\n * } catch (error) {\n * const timedOut = error.killed && error.signal === \"SIGTERM\";\n * return {\n * stdout: error.stdout ?? \"\",\n * stderr: error.stderr ?? String(error),\n * outcome: timedOut\n * ? { type: \"timeout\" as const }\n * : { type: \"exit\" as const, exit_code: error.code ?? 1 },\n * };\n * }\n * })\n * );\n * return {\n * output: outputs,\n * maxOutputLength: action.max_output_length,\n * };\n * }\n * ```\n */\n execute: (action: ShellAction) => ShellResult | Promise<ShellResult>;\n}\n/**\n * OpenAI Shell tool type for the Responses API.\n */\nexport type ShellTool = OpenAIClient.Responses.FunctionShellTool;\n/**\n * Creates a Shell tool that allows models to run shell commands through your integration.\n *\n * The shell tool allows the model to interact with your local computer through a controlled\n * command-line interface. The model proposes shell commands; your integration executes them\n * and returns the outputs. This creates a simple plan-execute loop that lets models inspect\n * the system, run utilities, and gather data until they can finish the task.\n *\n * **Important**: The shell tool is available through the Responses API for use with `GPT-5.1`.\n * It is not available on other models, or via the Chat Completions API.\n *\n * **When to use**:\n * - **Automating filesystem or process diagnostics** – For example, \"find the largest PDF\n * under ~/Documents\" or \"show running gunicorn processes.\"\n * - **Extending the model's capabilities** – Using built-in UNIX utilities, python runtime\n * and other CLIs in your environment.\n * - **Running multi-step build and test flows** – Chaining commands like `pip install` and `pytest`.\n * - **Complex agentic coding workflows** – Using other tools like `apply_patch` to complete\n * workflows that involve complex file operations.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`shell_call` with `commands` array)\n * 2. Your code executes the commands (can be concurrent)\n * 3. You return stdout, stderr, and outcome for each command\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-shell | OpenAI Shell Documentation}\n * @see {@link https://github.com/openai/codex | Codex CLI} for reference implementation.\n *\n * @param options - Configuration for the Shell tool\n * @returns A Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process/promises\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-5.1\" });\n *\n * // With execute callback for automatic command handling\n * const shellTool = tools.shell({\n * execute: async (action) => {\n * const outputs = await Promise.all(\n * action.commands.map(async (cmd) => {\n * try {\n * const { stdout, stderr } = await exec(cmd, {\n * timeout: action.timeout_ms ?? undefined,\n * });\n * return {\n * stdout,\n * stderr,\n * outcome: { type: \"exit\" as const, exit_code: 0 },\n * };\n * } catch (error) {\n * const timedOut = error.killed && error.signal === \"SIGTERM\";\n * return {\n * stdout: error.stdout ?? \"\",\n * stderr: error.stderr ?? String(error),\n * outcome: timedOut\n * ? { type: \"timeout\" as const }\n * : { type: \"exit\" as const, exit_code: error.code ?? 1 },\n * };\n * }\n * })\n * );\n * return {\n * output: outputs,\n * maxOutputLength: action.max_output_length,\n * };\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shellTool]);\n * const response = await llmWithShell.invoke(\n * \"Find the largest PDF file in ~/Documents\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.shell({ execute: myExecutor })],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute commands (with proper sandboxing!)\n * const result = await executeCommands(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"shell_call_output\",\n * call_id: shellCall.call_id,\n * output: result.output,\n * max_output_length: result.maxOutputLength,\n * },\n * ], {\n * tools: [tools.shell({ execute: myExecutor })],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `gpt-5.1` model\n * - Commands are provided as an array of strings that can be executed concurrently\n * - Action includes: `commands`, `timeout_ms`, `max_output_length`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n * - If `max_output_length` exists in the action, always pass it back in the output\n * - Many CLI tools return non-zero exit codes for warnings; still capture stdout/stderr\n */\nexport declare function shell(options: ShellOptions): DynamicStructuredTool<z.ZodObject<{\n commands: z.ZodArray<z.ZodString>;\n timeout_ms: z.ZodOptional<z.ZodNumber>;\n max_output_length: z.ZodOptional<z.ZodNumber>;\n}, z.core.$strip>, OpenAIClient.Responses.ResponseFunctionShellToolCall.Action, unknown, string>;\n//# sourceMappingURL=shell.d.ts.map"],"mappings":";;;;;;;;AAOA;AAUA;AAIYkB,KAdAd,WAAAA,GAAcF,QAAAA,CAAaG,SAAAA,CAAUC,6BAAAA,CAA8BC,MAc9B;;AA2DU;AAK3D;AAkIA;AAAuCa,KAtM3BJ,kBAAAA,GAAqBd,QAAAA,CAAaG,SAAAA,CAAUY,sCAsMjBG;;;;AAErBR,KApMNM,gBAAAA,GAAmBF,kBAoMbJ,CAAAA,SAAAA,CAAAA;;;;;AAECV,UAjMFiB,WAAAA,CAiMyBb;EAJYH;AAAqB;;;UAxL/Da;;;;;;;;;;UAUKI,YAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAuCKhB,gBAAgBe,cAAcE,QAAQF;;;;;KAKhDG,SAAAA,GAAYpB,QAAAA,CAAaG,SAAAA,CAAUkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkIvBC,KAAAA,UAAeJ,eAAejB,sBAAsBH,CAAAA,CAAEe;YAChEf,CAAAA,CAAEU,SAASV,CAAAA,CAAES;cACXT,CAAAA,CAAEY,YAAYZ,CAAAA,CAAEW;qBACTX,CAAAA,CAAEY,YAAYZ,CAAAA,CAAEW;GACpCX,CAAAA,CAAEa,IAAAA,CAAKC,SAASZ,QAAAA,CAAaG,SAAAA,CAAUC,6BAAAA,CAA8BC"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { tool } from "@langchain/core/tools";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/shell.ts
|
|
5
|
+
const ShellActionSchema = z.object({
|
|
6
|
+
commands: z.array(z.string()).describe("Array of shell commands to execute"),
|
|
7
|
+
timeout_ms: z.number().optional().describe("Optional timeout in milliseconds for the commands"),
|
|
8
|
+
max_output_length: z.number().optional().describe("Optional maximum number of characters to return from each command")
|
|
9
|
+
});
|
|
10
|
+
const TOOL_NAME = "shell";
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Shell tool that allows models to run shell commands through your integration.
|
|
13
|
+
*
|
|
14
|
+
* The shell tool allows the model to interact with your local computer through a controlled
|
|
15
|
+
* command-line interface. The model proposes shell commands; your integration executes them
|
|
16
|
+
* and returns the outputs. This creates a simple plan-execute loop that lets models inspect
|
|
17
|
+
* the system, run utilities, and gather data until they can finish the task.
|
|
18
|
+
*
|
|
19
|
+
* **Important**: The shell tool is available through the Responses API for use with `GPT-5.1`.
|
|
20
|
+
* It is not available on other models, or via the Chat Completions API.
|
|
21
|
+
*
|
|
22
|
+
* **When to use**:
|
|
23
|
+
* - **Automating filesystem or process diagnostics** – For example, "find the largest PDF
|
|
24
|
+
* under ~/Documents" or "show running gunicorn processes."
|
|
25
|
+
* - **Extending the model's capabilities** – Using built-in UNIX utilities, python runtime
|
|
26
|
+
* and other CLIs in your environment.
|
|
27
|
+
* - **Running multi-step build and test flows** – Chaining commands like `pip install` and `pytest`.
|
|
28
|
+
* - **Complex agentic coding workflows** – Using other tools like `apply_patch` to complete
|
|
29
|
+
* workflows that involve complex file operations.
|
|
30
|
+
*
|
|
31
|
+
* **How it works**:
|
|
32
|
+
* The tool operates in a continuous loop:
|
|
33
|
+
* 1. Model sends shell commands (`shell_call` with `commands` array)
|
|
34
|
+
* 2. Your code executes the commands (can be concurrent)
|
|
35
|
+
* 3. You return stdout, stderr, and outcome for each command
|
|
36
|
+
* 4. Repeat until the task is complete
|
|
37
|
+
*
|
|
38
|
+
* **Security Warning**: Running arbitrary shell commands can be dangerous.
|
|
39
|
+
* Always sandbox execution or add strict allow/deny-lists before forwarding
|
|
40
|
+
* a command to the system shell.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-shell | OpenAI Shell Documentation}
|
|
43
|
+
* @see {@link https://github.com/openai/codex | Codex CLI} for reference implementation.
|
|
44
|
+
*
|
|
45
|
+
* @param options - Configuration for the Shell tool
|
|
46
|
+
* @returns A Shell tool that can be passed to `bindTools`
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
51
|
+
* import { exec } from "child_process/promises";
|
|
52
|
+
*
|
|
53
|
+
* const model = new ChatOpenAI({ model: "gpt-5.1" });
|
|
54
|
+
*
|
|
55
|
+
* // With execute callback for automatic command handling
|
|
56
|
+
* const shellTool = tools.shell({
|
|
57
|
+
* execute: async (action) => {
|
|
58
|
+
* const outputs = await Promise.all(
|
|
59
|
+
* action.commands.map(async (cmd) => {
|
|
60
|
+
* try {
|
|
61
|
+
* const { stdout, stderr } = await exec(cmd, {
|
|
62
|
+
* timeout: action.timeout_ms ?? undefined,
|
|
63
|
+
* });
|
|
64
|
+
* return {
|
|
65
|
+
* stdout,
|
|
66
|
+
* stderr,
|
|
67
|
+
* outcome: { type: "exit" as const, exit_code: 0 },
|
|
68
|
+
* };
|
|
69
|
+
* } catch (error) {
|
|
70
|
+
* const timedOut = error.killed && error.signal === "SIGTERM";
|
|
71
|
+
* return {
|
|
72
|
+
* stdout: error.stdout ?? "",
|
|
73
|
+
* stderr: error.stderr ?? String(error),
|
|
74
|
+
* outcome: timedOut
|
|
75
|
+
* ? { type: "timeout" as const }
|
|
76
|
+
* : { type: "exit" as const, exit_code: error.code ?? 1 },
|
|
77
|
+
* };
|
|
78
|
+
* }
|
|
79
|
+
* })
|
|
80
|
+
* );
|
|
81
|
+
* return {
|
|
82
|
+
* output: outputs,
|
|
83
|
+
* maxOutputLength: action.max_output_length,
|
|
84
|
+
* };
|
|
85
|
+
* },
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* const llmWithShell = model.bindTools([shellTool]);
|
|
89
|
+
* const response = await llmWithShell.invoke(
|
|
90
|
+
* "Find the largest PDF file in ~/Documents"
|
|
91
|
+
* );
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // Full shell loop example
|
|
97
|
+
* async function shellLoop(model, task) {
|
|
98
|
+
* let response = await model.invoke(task, {
|
|
99
|
+
* tools: [tools.shell({ execute: myExecutor })],
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* while (true) {
|
|
103
|
+
* const shellCall = response.additional_kwargs.tool_outputs?.find(
|
|
104
|
+
* (output) => output.type === "shell_call"
|
|
105
|
+
* );
|
|
106
|
+
*
|
|
107
|
+
* if (!shellCall) break;
|
|
108
|
+
*
|
|
109
|
+
* // Execute commands (with proper sandboxing!)
|
|
110
|
+
* const result = await executeCommands(shellCall.action);
|
|
111
|
+
*
|
|
112
|
+
* // Send output back to model
|
|
113
|
+
* response = await model.invoke([
|
|
114
|
+
* response,
|
|
115
|
+
* {
|
|
116
|
+
* type: "shell_call_output",
|
|
117
|
+
* call_id: shellCall.call_id,
|
|
118
|
+
* output: result.output,
|
|
119
|
+
* max_output_length: result.maxOutputLength,
|
|
120
|
+
* },
|
|
121
|
+
* ], {
|
|
122
|
+
* tools: [tools.shell({ execute: myExecutor })],
|
|
123
|
+
* });
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* return response;
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* - Only available through the Responses API (not Chat Completions)
|
|
132
|
+
* - Designed for use with `gpt-5.1` model
|
|
133
|
+
* - Commands are provided as an array of strings that can be executed concurrently
|
|
134
|
+
* - Action includes: `commands`, `timeout_ms`, `max_output_length`
|
|
135
|
+
* - Always sandbox or validate commands before execution
|
|
136
|
+
* - The `timeout_ms` from the model is only a hint—enforce your own limits
|
|
137
|
+
* - If `max_output_length` exists in the action, always pass it back in the output
|
|
138
|
+
* - Many CLI tools return non-zero exit codes for warnings; still capture stdout/stderr
|
|
139
|
+
*/
|
|
140
|
+
function shell(options) {
|
|
141
|
+
const executeWrapper = async (action) => {
|
|
142
|
+
const result = await options.execute(action);
|
|
143
|
+
return JSON.stringify({
|
|
144
|
+
output: result.output,
|
|
145
|
+
max_output_length: result.maxOutputLength
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const shellTool = tool(executeWrapper, {
|
|
149
|
+
name: TOOL_NAME,
|
|
150
|
+
description: "Execute shell commands in a managed environment. Commands can be run concurrently.",
|
|
151
|
+
schema: ShellActionSchema
|
|
152
|
+
});
|
|
153
|
+
shellTool.extras = {
|
|
154
|
+
...shellTool.extras ?? {},
|
|
155
|
+
providerToolDefinition: { type: "shell" }
|
|
156
|
+
};
|
|
157
|
+
return shellTool;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
export { shell };
|
|
162
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","names":["options: ShellOptions","action: ShellAction"],"sources":["../../src/tools/shell.ts"],"sourcesContent":["import { z } from \"zod/v4\";\nimport { OpenAI as OpenAIClient } from \"openai\";\nimport { tool, type DynamicStructuredTool } from \"@langchain/core/tools\";\n\n/**\n * Re-export action type from OpenAI SDK for convenience.\n * The action contains command details like commands array, timeout, and max output length.\n */\nexport type ShellAction =\n OpenAIClient.Responses.ResponseFunctionShellToolCall.Action;\n\n// Zod schema for shell action\nexport const ShellActionSchema = z.object({\n commands: z.array(z.string()).describe(\"Array of shell commands to execute\"),\n timeout_ms: z\n .number()\n .optional()\n .describe(\"Optional timeout in milliseconds for the commands\"),\n max_output_length: z\n .number()\n .optional()\n .describe(\n \"Optional maximum number of characters to return from each command\"\n ),\n});\n\n/**\n * Result of a single shell command execution.\n * Contains stdout, stderr, and the outcome (exit code or timeout).\n */\nexport type ShellCommandOutput =\n OpenAIClient.Responses.ResponseFunctionShellCallOutputContent;\n\n/**\n * Outcome type for shell command execution - either exit with code or timeout.\n */\nexport type ShellCallOutcome = ShellCommandOutput[\"outcome\"];\n\n/**\n * Result of executing shell commands.\n * Contains an array of outputs (one per command) and the max_output_length parameter.\n */\nexport interface ShellResult {\n /**\n * Array of command outputs. Each entry corresponds to a command from the action.\n * The order should match the order of commands in the action.\n */\n output: ShellCommandOutput[];\n /**\n * The max_output_length from the action, which must be passed back to the API.\n * If not provided in the action, can be omitted.\n */\n maxOutputLength?: number | null;\n}\n\n/**\n * Options for the Shell tool.\n */\nexport interface ShellOptions {\n /**\n * Execute function that handles shell command execution.\n * This function receives the action input containing the commands and limits,\n * and should return a ShellResult with stdout, stderr, and outcome for each command.\n *\n * @example\n * ```typescript\n * execute: async (action) => {\n * const outputs = await Promise.all(\n * action.commands.map(async (cmd) => {\n * try {\n * const { stdout, stderr } = await exec(cmd, {\n * timeout: action.timeout_ms ?? undefined,\n * });\n * return {\n * stdout,\n * stderr,\n * outcome: { type: \"exit\" as const, exit_code: 0 },\n * };\n * } catch (error) {\n * const timedOut = error.killed && error.signal === \"SIGTERM\";\n * return {\n * stdout: error.stdout ?? \"\",\n * stderr: error.stderr ?? String(error),\n * outcome: timedOut\n * ? { type: \"timeout\" as const }\n * : { type: \"exit\" as const, exit_code: error.code ?? 1 },\n * };\n * }\n * })\n * );\n * return {\n * output: outputs,\n * maxOutputLength: action.max_output_length,\n * };\n * }\n * ```\n */\n execute: (action: ShellAction) => ShellResult | Promise<ShellResult>;\n}\n\n/**\n * OpenAI Shell tool type for the Responses API.\n */\nexport type ShellTool = OpenAIClient.Responses.FunctionShellTool;\n\nconst TOOL_NAME = \"shell\";\n\n/**\n * Creates a Shell tool that allows models to run shell commands through your integration.\n *\n * The shell tool allows the model to interact with your local computer through a controlled\n * command-line interface. The model proposes shell commands; your integration executes them\n * and returns the outputs. This creates a simple plan-execute loop that lets models inspect\n * the system, run utilities, and gather data until they can finish the task.\n *\n * **Important**: The shell tool is available through the Responses API for use with `GPT-5.1`.\n * It is not available on other models, or via the Chat Completions API.\n *\n * **When to use**:\n * - **Automating filesystem or process diagnostics** – For example, \"find the largest PDF\n * under ~/Documents\" or \"show running gunicorn processes.\"\n * - **Extending the model's capabilities** – Using built-in UNIX utilities, python runtime\n * and other CLIs in your environment.\n * - **Running multi-step build and test flows** – Chaining commands like `pip install` and `pytest`.\n * - **Complex agentic coding workflows** – Using other tools like `apply_patch` to complete\n * workflows that involve complex file operations.\n *\n * **How it works**:\n * The tool operates in a continuous loop:\n * 1. Model sends shell commands (`shell_call` with `commands` array)\n * 2. Your code executes the commands (can be concurrent)\n * 3. You return stdout, stderr, and outcome for each command\n * 4. Repeat until the task is complete\n *\n * **Security Warning**: Running arbitrary shell commands can be dangerous.\n * Always sandbox execution or add strict allow/deny-lists before forwarding\n * a command to the system shell.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-shell | OpenAI Shell Documentation}\n * @see {@link https://github.com/openai/codex | Codex CLI} for reference implementation.\n *\n * @param options - Configuration for the Shell tool\n * @returns A Shell tool that can be passed to `bindTools`\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n * import { exec } from \"child_process/promises\";\n *\n * const model = new ChatOpenAI({ model: \"gpt-5.1\" });\n *\n * // With execute callback for automatic command handling\n * const shellTool = tools.shell({\n * execute: async (action) => {\n * const outputs = await Promise.all(\n * action.commands.map(async (cmd) => {\n * try {\n * const { stdout, stderr } = await exec(cmd, {\n * timeout: action.timeout_ms ?? undefined,\n * });\n * return {\n * stdout,\n * stderr,\n * outcome: { type: \"exit\" as const, exit_code: 0 },\n * };\n * } catch (error) {\n * const timedOut = error.killed && error.signal === \"SIGTERM\";\n * return {\n * stdout: error.stdout ?? \"\",\n * stderr: error.stderr ?? String(error),\n * outcome: timedOut\n * ? { type: \"timeout\" as const }\n * : { type: \"exit\" as const, exit_code: error.code ?? 1 },\n * };\n * }\n * })\n * );\n * return {\n * output: outputs,\n * maxOutputLength: action.max_output_length,\n * };\n * },\n * });\n *\n * const llmWithShell = model.bindTools([shellTool]);\n * const response = await llmWithShell.invoke(\n * \"Find the largest PDF file in ~/Documents\"\n * );\n * ```\n *\n * @example\n * ```typescript\n * // Full shell loop example\n * async function shellLoop(model, task) {\n * let response = await model.invoke(task, {\n * tools: [tools.shell({ execute: myExecutor })],\n * });\n *\n * while (true) {\n * const shellCall = response.additional_kwargs.tool_outputs?.find(\n * (output) => output.type === \"shell_call\"\n * );\n *\n * if (!shellCall) break;\n *\n * // Execute commands (with proper sandboxing!)\n * const result = await executeCommands(shellCall.action);\n *\n * // Send output back to model\n * response = await model.invoke([\n * response,\n * {\n * type: \"shell_call_output\",\n * call_id: shellCall.call_id,\n * output: result.output,\n * max_output_length: result.maxOutputLength,\n * },\n * ], {\n * tools: [tools.shell({ execute: myExecutor })],\n * });\n * }\n *\n * return response;\n * }\n * ```\n *\n * @remarks\n * - Only available through the Responses API (not Chat Completions)\n * - Designed for use with `gpt-5.1` model\n * - Commands are provided as an array of strings that can be executed concurrently\n * - Action includes: `commands`, `timeout_ms`, `max_output_length`\n * - Always sandbox or validate commands before execution\n * - The `timeout_ms` from the model is only a hint—enforce your own limits\n * - If `max_output_length` exists in the action, always pass it back in the output\n * - Many CLI tools return non-zero exit codes for warnings; still capture stdout/stderr\n */\nexport function shell(options: ShellOptions) {\n // Wrapper that converts ShellResult to string for LangChain tool compatibility\n const executeWrapper = async (action: ShellAction): Promise<string> => {\n const result = await options.execute(action);\n // Return a JSON string representation for the tool result\n return JSON.stringify({\n output: result.output,\n max_output_length: result.maxOutputLength,\n });\n };\n\n const shellTool = tool(executeWrapper, {\n name: TOOL_NAME,\n description:\n \"Execute shell commands in a managed environment. Commands can be run concurrently.\",\n schema: ShellActionSchema,\n });\n\n shellTool.extras = {\n ...(shellTool.extras ?? {}),\n providerToolDefinition: {\n type: \"shell\",\n } satisfies ShellTool,\n };\n\n return shellTool as DynamicStructuredTool<\n typeof ShellActionSchema,\n ShellAction,\n unknown,\n string\n >;\n}\n"],"mappings":";;;;AAYA,MAAa,oBAAoB,EAAE,OAAO;CACxC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,SAAS,qCAAqC;CAC5E,YAAY,EACT,QAAQ,CACR,UAAU,CACV,SAAS,oDAAoD;CAChE,mBAAmB,EAChB,QAAQ,CACR,UAAU,CACV,SACC,oEACD;AACJ,EAAC;AAiFF,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmIlB,SAAgB,MAAMA,SAAuB;CAE3C,MAAM,iBAAiB,OAAOC,WAAyC;EACrE,MAAM,SAAS,MAAM,QAAQ,QAAQ,OAAO;AAE5C,SAAO,KAAK,UAAU;GACpB,QAAQ,OAAO;GACf,mBAAmB,OAAO;EAC3B,EAAC;CACH;CAED,MAAM,YAAY,KAAK,gBAAgB;EACrC,MAAM;EACN,aACE;EACF,QAAQ;CACT,EAAC;CAEF,UAAU,SAAS;EACjB,GAAI,UAAU,UAAU,CAAE;EAC1B,wBAAwB,EACtB,MAAM,QACP;CACF;AAED,QAAO;AAMR"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/tools/webSearch.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a web search tool that allows OpenAI models to search the web
|
|
5
|
+
* for up-to-date information before generating a response.
|
|
6
|
+
*
|
|
7
|
+
* Web search supports three main types:
|
|
8
|
+
* 1. **Non-reasoning web search**: Quick lookups where the model passes queries
|
|
9
|
+
* directly to the search tool.
|
|
10
|
+
* 2. **Agentic search with reasoning models**: The model actively manages the
|
|
11
|
+
* search process, analyzing results and deciding whether to keep searching.
|
|
12
|
+
* 3. **Deep research**: Extended investigations using models like `o3-deep-research`
|
|
13
|
+
* or `gpt-5` with high reasoning effort.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-web-search | OpenAI Web Search Documentation}
|
|
16
|
+
* @param options - Configuration options for the web search tool
|
|
17
|
+
* @returns A web search tool definition to be passed to the OpenAI Responses API
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
22
|
+
*
|
|
23
|
+
* const model = new ChatOpenAI({
|
|
24
|
+
* model: "gpt-4o",
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Basic usage
|
|
28
|
+
* const response = await model.invoke("What was a positive news story from today?", {
|
|
29
|
+
* tools: [tools.webSearch()],
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // With domain filtering
|
|
33
|
+
* const filteredResponse = await model.invoke("Latest AI research news", {
|
|
34
|
+
* tools: [tools.webSearch({
|
|
35
|
+
* filters: {
|
|
36
|
+
* allowedDomains: ["arxiv.org", "nature.com", "science.org"],
|
|
37
|
+
* },
|
|
38
|
+
* })],
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // With user location for geographic relevance
|
|
42
|
+
* const localResponse = await model.invoke("What are the best restaurants near me?", {
|
|
43
|
+
* tools: [tools.webSearch({
|
|
44
|
+
* userLocation: {
|
|
45
|
+
* type: "approximate",
|
|
46
|
+
* country: "US",
|
|
47
|
+
* city: "San Francisco",
|
|
48
|
+
* region: "California",
|
|
49
|
+
* timezone: "America/Los_Angeles",
|
|
50
|
+
* },
|
|
51
|
+
* })],
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Cache-only mode (no live internet access)
|
|
55
|
+
* const cachedResponse = await model.invoke("Find information about OpenAI", {
|
|
56
|
+
* tools: [tools.webSearch({
|
|
57
|
+
* externalWebAccess: false,
|
|
58
|
+
* })],
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function webSearch(options) {
|
|
63
|
+
return {
|
|
64
|
+
type: "web_search",
|
|
65
|
+
filters: options?.filters?.allowedDomains ? { allowed_domains: options.filters.allowedDomains } : void 0,
|
|
66
|
+
user_location: options?.userLocation,
|
|
67
|
+
search_context_size: options?.search_context_size
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
exports.webSearch = webSearch;
|
|
73
|
+
//# sourceMappingURL=webSearch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webSearch.cjs","names":["options?: WebSearchOptions"],"sources":["../../src/tools/webSearch.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n\n/**\n * User location configuration for geographic search refinement.\n */\nexport interface WebSearchUserLocation {\n /**\n * The type of location. Currently only \"approximate\" is supported.\n */\n type: \"approximate\";\n /**\n * Two-letter ISO country code (e.g., \"US\", \"GB\").\n * @see https://en.wikipedia.org/wiki/ISO_3166-1\n */\n country?: string;\n /**\n * City name (e.g., \"San Francisco\", \"London\").\n */\n city?: string;\n /**\n * Region or state name (e.g., \"California\", \"London\").\n */\n region?: string;\n /**\n * IANA timezone (e.g., \"America/Los_Angeles\", \"Europe/London\").\n * @see https://timeapi.io/documentation/iana-timezones\n */\n timezone?: string;\n}\n\n/**\n * Domain filtering configuration for web search.\n */\nexport interface WebSearchFilters {\n /**\n * Allow-list of up to 100 domains to limit search results.\n * Omit the HTTP/HTTPS prefix (e.g., \"openai.com\" instead of \"https://openai.com/\").\n * Includes subdomains automatically.\n */\n allowedDomains?: string[];\n}\n\n/**\n * Options for the OpenAI web search tool.\n */\nexport interface WebSearchOptions {\n /**\n * Domain filtering configuration.\n * Limit results to a specific set of up to 100 domains.\n */\n filters?: WebSearchFilters;\n /**\n * Approximate user location for geographic search refinement.\n * Not supported for deep research models.\n */\n userLocation?: WebSearchUserLocation;\n /**\n * High level guidance for the amount of context window space to use for the\n * search. One of `low`, `medium`, or `high`. `medium` is the default.\n */\n search_context_size?: \"low\" | \"medium\" | \"high\";\n}\n\n/**\n * OpenAI web search tool type for the Responses API.\n */\nexport type WebSearchTool = OpenAIClient.Responses.WebSearchTool;\n\n/**\n * Creates a web search tool that allows OpenAI models to search the web\n * for up-to-date information before generating a response.\n *\n * Web search supports three main types:\n * 1. **Non-reasoning web search**: Quick lookups where the model passes queries\n * directly to the search tool.\n * 2. **Agentic search with reasoning models**: The model actively manages the\n * search process, analyzing results and deciding whether to keep searching.\n * 3. **Deep research**: Extended investigations using models like `o3-deep-research`\n * or `gpt-5` with high reasoning effort.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-web-search | OpenAI Web Search Documentation}\n * @param options - Configuration options for the web search tool\n * @returns A web search tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * // Basic usage\n * const response = await model.invoke(\"What was a positive news story from today?\", {\n * tools: [tools.webSearch()],\n * });\n *\n * // With domain filtering\n * const filteredResponse = await model.invoke(\"Latest AI research news\", {\n * tools: [tools.webSearch({\n * filters: {\n * allowedDomains: [\"arxiv.org\", \"nature.com\", \"science.org\"],\n * },\n * })],\n * });\n *\n * // With user location for geographic relevance\n * const localResponse = await model.invoke(\"What are the best restaurants near me?\", {\n * tools: [tools.webSearch({\n * userLocation: {\n * type: \"approximate\",\n * country: \"US\",\n * city: \"San Francisco\",\n * region: \"California\",\n * timezone: \"America/Los_Angeles\",\n * },\n * })],\n * });\n *\n * // Cache-only mode (no live internet access)\n * const cachedResponse = await model.invoke(\"Find information about OpenAI\", {\n * tools: [tools.webSearch({\n * externalWebAccess: false,\n * })],\n * });\n * ```\n */\nexport function webSearch(options?: WebSearchOptions): ServerTool {\n return {\n type: \"web_search\",\n filters: options?.filters?.allowedDomains\n ? { allowed_domains: options.filters.allowedDomains }\n : undefined,\n user_location: options?.userLocation,\n search_context_size: options?.search_context_size,\n } satisfies WebSearchTool;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIA,SAAgB,UAAUA,SAAwC;AAChE,QAAO;EACL,MAAM;EACN,SAAS,SAAS,SAAS,iBACvB,EAAE,iBAAiB,QAAQ,QAAQ,eAAgB,IACnD;EACJ,eAAe,SAAS;EACxB,qBAAqB,SAAS;CAC/B;AACF"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { OpenAI as OpenAI$1 } from "openai";
|
|
2
|
+
import { ServerTool } from "@langchain/core/tools";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/webSearch.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* User location configuration for geographic search refinement.
|
|
8
|
+
*/
|
|
9
|
+
interface WebSearchUserLocation {
|
|
10
|
+
/**
|
|
11
|
+
* The type of location. Currently only "approximate" is supported.
|
|
12
|
+
*/
|
|
13
|
+
type: "approximate";
|
|
14
|
+
/**
|
|
15
|
+
* Two-letter ISO country code (e.g., "US", "GB").
|
|
16
|
+
* @see https://en.wikipedia.org/wiki/ISO_3166-1
|
|
17
|
+
*/
|
|
18
|
+
country?: string;
|
|
19
|
+
/**
|
|
20
|
+
* City name (e.g., "San Francisco", "London").
|
|
21
|
+
*/
|
|
22
|
+
city?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Region or state name (e.g., "California", "London").
|
|
25
|
+
*/
|
|
26
|
+
region?: string;
|
|
27
|
+
/**
|
|
28
|
+
* IANA timezone (e.g., "America/Los_Angeles", "Europe/London").
|
|
29
|
+
* @see https://timeapi.io/documentation/iana-timezones
|
|
30
|
+
*/
|
|
31
|
+
timezone?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Domain filtering configuration for web search.
|
|
35
|
+
*/
|
|
36
|
+
interface WebSearchFilters {
|
|
37
|
+
/**
|
|
38
|
+
* Allow-list of up to 100 domains to limit search results.
|
|
39
|
+
* Omit the HTTP/HTTPS prefix (e.g., "openai.com" instead of "https://openai.com/").
|
|
40
|
+
* Includes subdomains automatically.
|
|
41
|
+
*/
|
|
42
|
+
allowedDomains?: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Options for the OpenAI web search tool.
|
|
46
|
+
*/
|
|
47
|
+
interface WebSearchOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Domain filtering configuration.
|
|
50
|
+
* Limit results to a specific set of up to 100 domains.
|
|
51
|
+
*/
|
|
52
|
+
filters?: WebSearchFilters;
|
|
53
|
+
/**
|
|
54
|
+
* Approximate user location for geographic search refinement.
|
|
55
|
+
* Not supported for deep research models.
|
|
56
|
+
*/
|
|
57
|
+
userLocation?: WebSearchUserLocation;
|
|
58
|
+
/**
|
|
59
|
+
* High level guidance for the amount of context window space to use for the
|
|
60
|
+
* search. One of `low`, `medium`, or `high`. `medium` is the default.
|
|
61
|
+
*/
|
|
62
|
+
search_context_size?: "low" | "medium" | "high";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* OpenAI web search tool type for the Responses API.
|
|
66
|
+
*/
|
|
67
|
+
type WebSearchTool = OpenAI$1.Responses.WebSearchTool;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a web search tool that allows OpenAI models to search the web
|
|
70
|
+
* for up-to-date information before generating a response.
|
|
71
|
+
*
|
|
72
|
+
* Web search supports three main types:
|
|
73
|
+
* 1. **Non-reasoning web search**: Quick lookups where the model passes queries
|
|
74
|
+
* directly to the search tool.
|
|
75
|
+
* 2. **Agentic search with reasoning models**: The model actively manages the
|
|
76
|
+
* search process, analyzing results and deciding whether to keep searching.
|
|
77
|
+
* 3. **Deep research**: Extended investigations using models like `o3-deep-research`
|
|
78
|
+
* or `gpt-5` with high reasoning effort.
|
|
79
|
+
*
|
|
80
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-web-search | OpenAI Web Search Documentation}
|
|
81
|
+
* @param options - Configuration options for the web search tool
|
|
82
|
+
* @returns A web search tool definition to be passed to the OpenAI Responses API
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
87
|
+
*
|
|
88
|
+
* const model = new ChatOpenAI({
|
|
89
|
+
* model: "gpt-4o",
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // Basic usage
|
|
93
|
+
* const response = await model.invoke("What was a positive news story from today?", {
|
|
94
|
+
* tools: [tools.webSearch()],
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // With domain filtering
|
|
98
|
+
* const filteredResponse = await model.invoke("Latest AI research news", {
|
|
99
|
+
* tools: [tools.webSearch({
|
|
100
|
+
* filters: {
|
|
101
|
+
* allowedDomains: ["arxiv.org", "nature.com", "science.org"],
|
|
102
|
+
* },
|
|
103
|
+
* })],
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // With user location for geographic relevance
|
|
107
|
+
* const localResponse = await model.invoke("What are the best restaurants near me?", {
|
|
108
|
+
* tools: [tools.webSearch({
|
|
109
|
+
* userLocation: {
|
|
110
|
+
* type: "approximate",
|
|
111
|
+
* country: "US",
|
|
112
|
+
* city: "San Francisco",
|
|
113
|
+
* region: "California",
|
|
114
|
+
* timezone: "America/Los_Angeles",
|
|
115
|
+
* },
|
|
116
|
+
* })],
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* // Cache-only mode (no live internet access)
|
|
120
|
+
* const cachedResponse = await model.invoke("Find information about OpenAI", {
|
|
121
|
+
* tools: [tools.webSearch({
|
|
122
|
+
* externalWebAccess: false,
|
|
123
|
+
* })],
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
declare function webSearch(options?: WebSearchOptions): ServerTool;
|
|
128
|
+
//#endregion
|
|
129
|
+
export { WebSearchFilters, WebSearchOptions, WebSearchTool, webSearch };
|
|
130
|
+
//# sourceMappingURL=webSearch.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webSearch.d.cts","names":["OpenAI","OpenAIClient","ServerTool","WebSearchUserLocation","WebSearchFilters","WebSearchOptions","WebSearchTool","Responses","webSearch"],"sources":["../../src/tools/webSearch.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * User location configuration for geographic search refinement.\n */\nexport interface WebSearchUserLocation {\n /**\n * The type of location. Currently only \"approximate\" is supported.\n */\n type: \"approximate\";\n /**\n * Two-letter ISO country code (e.g., \"US\", \"GB\").\n * @see https://en.wikipedia.org/wiki/ISO_3166-1\n */\n country?: string;\n /**\n * City name (e.g., \"San Francisco\", \"London\").\n */\n city?: string;\n /**\n * Region or state name (e.g., \"California\", \"London\").\n */\n region?: string;\n /**\n * IANA timezone (e.g., \"America/Los_Angeles\", \"Europe/London\").\n * @see https://timeapi.io/documentation/iana-timezones\n */\n timezone?: string;\n}\n/**\n * Domain filtering configuration for web search.\n */\nexport interface WebSearchFilters {\n /**\n * Allow-list of up to 100 domains to limit search results.\n * Omit the HTTP/HTTPS prefix (e.g., \"openai.com\" instead of \"https://openai.com/\").\n * Includes subdomains automatically.\n */\n allowedDomains?: string[];\n}\n/**\n * Options for the OpenAI web search tool.\n */\nexport interface WebSearchOptions {\n /**\n * Domain filtering configuration.\n * Limit results to a specific set of up to 100 domains.\n */\n filters?: WebSearchFilters;\n /**\n * Approximate user location for geographic search refinement.\n * Not supported for deep research models.\n */\n userLocation?: WebSearchUserLocation;\n /**\n * High level guidance for the amount of context window space to use for the\n * search. One of `low`, `medium`, or `high`. `medium` is the default.\n */\n search_context_size?: \"low\" | \"medium\" | \"high\";\n}\n/**\n * OpenAI web search tool type for the Responses API.\n */\nexport type WebSearchTool = OpenAIClient.Responses.WebSearchTool;\n/**\n * Creates a web search tool that allows OpenAI models to search the web\n * for up-to-date information before generating a response.\n *\n * Web search supports three main types:\n * 1. **Non-reasoning web search**: Quick lookups where the model passes queries\n * directly to the search tool.\n * 2. **Agentic search with reasoning models**: The model actively manages the\n * search process, analyzing results and deciding whether to keep searching.\n * 3. **Deep research**: Extended investigations using models like `o3-deep-research`\n * or `gpt-5` with high reasoning effort.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-web-search | OpenAI Web Search Documentation}\n * @param options - Configuration options for the web search tool\n * @returns A web search tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * // Basic usage\n * const response = await model.invoke(\"What was a positive news story from today?\", {\n * tools: [tools.webSearch()],\n * });\n *\n * // With domain filtering\n * const filteredResponse = await model.invoke(\"Latest AI research news\", {\n * tools: [tools.webSearch({\n * filters: {\n * allowedDomains: [\"arxiv.org\", \"nature.com\", \"science.org\"],\n * },\n * })],\n * });\n *\n * // With user location for geographic relevance\n * const localResponse = await model.invoke(\"What are the best restaurants near me?\", {\n * tools: [tools.webSearch({\n * userLocation: {\n * type: \"approximate\",\n * country: \"US\",\n * city: \"San Francisco\",\n * region: \"California\",\n * timezone: \"America/Los_Angeles\",\n * },\n * })],\n * });\n *\n * // Cache-only mode (no live internet access)\n * const cachedResponse = await model.invoke(\"Find information about OpenAI\", {\n * tools: [tools.webSearch({\n * externalWebAccess: false,\n * })],\n * });\n * ```\n */\nexport declare function webSearch(options?: WebSearchOptions): ServerTool;\n//# sourceMappingURL=webSearch.d.ts.map"],"mappings":";;;;;;;AAKA;AA2BiBI,UA3BAD,qBAAAA,CA2BgB;EAWhBE;AAoBjB;AA4DA;;;;;;;;;;;;;;;;;;;;;;;;UA3FiBD,gBAAAA;;;;;;;;;;;UAWAC,gBAAAA;;;;;YAKHD;;;;;iBAKKD;;;;;;;;;;KAUPG,aAAAA,GAAgBL,QAAAA,CAAaM,SAAAA,CAAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4D3BE,SAAAA,WAAoBH,mBAAmBH"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { OpenAI as OpenAI$1 } from "openai";
|
|
2
|
+
import { ServerTool } from "@langchain/core/tools";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/webSearch.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* User location configuration for geographic search refinement.
|
|
8
|
+
*/
|
|
9
|
+
interface WebSearchUserLocation {
|
|
10
|
+
/**
|
|
11
|
+
* The type of location. Currently only "approximate" is supported.
|
|
12
|
+
*/
|
|
13
|
+
type: "approximate";
|
|
14
|
+
/**
|
|
15
|
+
* Two-letter ISO country code (e.g., "US", "GB").
|
|
16
|
+
* @see https://en.wikipedia.org/wiki/ISO_3166-1
|
|
17
|
+
*/
|
|
18
|
+
country?: string;
|
|
19
|
+
/**
|
|
20
|
+
* City name (e.g., "San Francisco", "London").
|
|
21
|
+
*/
|
|
22
|
+
city?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Region or state name (e.g., "California", "London").
|
|
25
|
+
*/
|
|
26
|
+
region?: string;
|
|
27
|
+
/**
|
|
28
|
+
* IANA timezone (e.g., "America/Los_Angeles", "Europe/London").
|
|
29
|
+
* @see https://timeapi.io/documentation/iana-timezones
|
|
30
|
+
*/
|
|
31
|
+
timezone?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Domain filtering configuration for web search.
|
|
35
|
+
*/
|
|
36
|
+
interface WebSearchFilters {
|
|
37
|
+
/**
|
|
38
|
+
* Allow-list of up to 100 domains to limit search results.
|
|
39
|
+
* Omit the HTTP/HTTPS prefix (e.g., "openai.com" instead of "https://openai.com/").
|
|
40
|
+
* Includes subdomains automatically.
|
|
41
|
+
*/
|
|
42
|
+
allowedDomains?: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Options for the OpenAI web search tool.
|
|
46
|
+
*/
|
|
47
|
+
interface WebSearchOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Domain filtering configuration.
|
|
50
|
+
* Limit results to a specific set of up to 100 domains.
|
|
51
|
+
*/
|
|
52
|
+
filters?: WebSearchFilters;
|
|
53
|
+
/**
|
|
54
|
+
* Approximate user location for geographic search refinement.
|
|
55
|
+
* Not supported for deep research models.
|
|
56
|
+
*/
|
|
57
|
+
userLocation?: WebSearchUserLocation;
|
|
58
|
+
/**
|
|
59
|
+
* High level guidance for the amount of context window space to use for the
|
|
60
|
+
* search. One of `low`, `medium`, or `high`. `medium` is the default.
|
|
61
|
+
*/
|
|
62
|
+
search_context_size?: "low" | "medium" | "high";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* OpenAI web search tool type for the Responses API.
|
|
66
|
+
*/
|
|
67
|
+
type WebSearchTool = OpenAI$1.Responses.WebSearchTool;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a web search tool that allows OpenAI models to search the web
|
|
70
|
+
* for up-to-date information before generating a response.
|
|
71
|
+
*
|
|
72
|
+
* Web search supports three main types:
|
|
73
|
+
* 1. **Non-reasoning web search**: Quick lookups where the model passes queries
|
|
74
|
+
* directly to the search tool.
|
|
75
|
+
* 2. **Agentic search with reasoning models**: The model actively manages the
|
|
76
|
+
* search process, analyzing results and deciding whether to keep searching.
|
|
77
|
+
* 3. **Deep research**: Extended investigations using models like `o3-deep-research`
|
|
78
|
+
* or `gpt-5` with high reasoning effort.
|
|
79
|
+
*
|
|
80
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-web-search | OpenAI Web Search Documentation}
|
|
81
|
+
* @param options - Configuration options for the web search tool
|
|
82
|
+
* @returns A web search tool definition to be passed to the OpenAI Responses API
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
87
|
+
*
|
|
88
|
+
* const model = new ChatOpenAI({
|
|
89
|
+
* model: "gpt-4o",
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // Basic usage
|
|
93
|
+
* const response = await model.invoke("What was a positive news story from today?", {
|
|
94
|
+
* tools: [tools.webSearch()],
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // With domain filtering
|
|
98
|
+
* const filteredResponse = await model.invoke("Latest AI research news", {
|
|
99
|
+
* tools: [tools.webSearch({
|
|
100
|
+
* filters: {
|
|
101
|
+
* allowedDomains: ["arxiv.org", "nature.com", "science.org"],
|
|
102
|
+
* },
|
|
103
|
+
* })],
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // With user location for geographic relevance
|
|
107
|
+
* const localResponse = await model.invoke("What are the best restaurants near me?", {
|
|
108
|
+
* tools: [tools.webSearch({
|
|
109
|
+
* userLocation: {
|
|
110
|
+
* type: "approximate",
|
|
111
|
+
* country: "US",
|
|
112
|
+
* city: "San Francisco",
|
|
113
|
+
* region: "California",
|
|
114
|
+
* timezone: "America/Los_Angeles",
|
|
115
|
+
* },
|
|
116
|
+
* })],
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* // Cache-only mode (no live internet access)
|
|
120
|
+
* const cachedResponse = await model.invoke("Find information about OpenAI", {
|
|
121
|
+
* tools: [tools.webSearch({
|
|
122
|
+
* externalWebAccess: false,
|
|
123
|
+
* })],
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
declare function webSearch(options?: WebSearchOptions): ServerTool;
|
|
128
|
+
//#endregion
|
|
129
|
+
export { WebSearchFilters, WebSearchOptions, WebSearchTool, webSearch };
|
|
130
|
+
//# sourceMappingURL=webSearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webSearch.d.ts","names":["OpenAI","OpenAIClient","ServerTool","WebSearchUserLocation","WebSearchFilters","WebSearchOptions","WebSearchTool","Responses","webSearch"],"sources":["../../src/tools/webSearch.d.ts"],"sourcesContent":["import { OpenAI as OpenAIClient } from \"openai\";\nimport type { ServerTool } from \"@langchain/core/tools\";\n/**\n * User location configuration for geographic search refinement.\n */\nexport interface WebSearchUserLocation {\n /**\n * The type of location. Currently only \"approximate\" is supported.\n */\n type: \"approximate\";\n /**\n * Two-letter ISO country code (e.g., \"US\", \"GB\").\n * @see https://en.wikipedia.org/wiki/ISO_3166-1\n */\n country?: string;\n /**\n * City name (e.g., \"San Francisco\", \"London\").\n */\n city?: string;\n /**\n * Region or state name (e.g., \"California\", \"London\").\n */\n region?: string;\n /**\n * IANA timezone (e.g., \"America/Los_Angeles\", \"Europe/London\").\n * @see https://timeapi.io/documentation/iana-timezones\n */\n timezone?: string;\n}\n/**\n * Domain filtering configuration for web search.\n */\nexport interface WebSearchFilters {\n /**\n * Allow-list of up to 100 domains to limit search results.\n * Omit the HTTP/HTTPS prefix (e.g., \"openai.com\" instead of \"https://openai.com/\").\n * Includes subdomains automatically.\n */\n allowedDomains?: string[];\n}\n/**\n * Options for the OpenAI web search tool.\n */\nexport interface WebSearchOptions {\n /**\n * Domain filtering configuration.\n * Limit results to a specific set of up to 100 domains.\n */\n filters?: WebSearchFilters;\n /**\n * Approximate user location for geographic search refinement.\n * Not supported for deep research models.\n */\n userLocation?: WebSearchUserLocation;\n /**\n * High level guidance for the amount of context window space to use for the\n * search. One of `low`, `medium`, or `high`. `medium` is the default.\n */\n search_context_size?: \"low\" | \"medium\" | \"high\";\n}\n/**\n * OpenAI web search tool type for the Responses API.\n */\nexport type WebSearchTool = OpenAIClient.Responses.WebSearchTool;\n/**\n * Creates a web search tool that allows OpenAI models to search the web\n * for up-to-date information before generating a response.\n *\n * Web search supports three main types:\n * 1. **Non-reasoning web search**: Quick lookups where the model passes queries\n * directly to the search tool.\n * 2. **Agentic search with reasoning models**: The model actively manages the\n * search process, analyzing results and deciding whether to keep searching.\n * 3. **Deep research**: Extended investigations using models like `o3-deep-research`\n * or `gpt-5` with high reasoning effort.\n *\n * @see {@link https://platform.openai.com/docs/guides/tools-web-search | OpenAI Web Search Documentation}\n * @param options - Configuration options for the web search tool\n * @returns A web search tool definition to be passed to the OpenAI Responses API\n *\n * @example\n * ```typescript\n * import { ChatOpenAI, tools } from \"@langchain/openai\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * // Basic usage\n * const response = await model.invoke(\"What was a positive news story from today?\", {\n * tools: [tools.webSearch()],\n * });\n *\n * // With domain filtering\n * const filteredResponse = await model.invoke(\"Latest AI research news\", {\n * tools: [tools.webSearch({\n * filters: {\n * allowedDomains: [\"arxiv.org\", \"nature.com\", \"science.org\"],\n * },\n * })],\n * });\n *\n * // With user location for geographic relevance\n * const localResponse = await model.invoke(\"What are the best restaurants near me?\", {\n * tools: [tools.webSearch({\n * userLocation: {\n * type: \"approximate\",\n * country: \"US\",\n * city: \"San Francisco\",\n * region: \"California\",\n * timezone: \"America/Los_Angeles\",\n * },\n * })],\n * });\n *\n * // Cache-only mode (no live internet access)\n * const cachedResponse = await model.invoke(\"Find information about OpenAI\", {\n * tools: [tools.webSearch({\n * externalWebAccess: false,\n * })],\n * });\n * ```\n */\nexport declare function webSearch(options?: WebSearchOptions): ServerTool;\n//# sourceMappingURL=webSearch.d.ts.map"],"mappings":";;;;;;;AAKA;AA2BiBI,UA3BAD,qBAAAA,CA2BgB;EAWhBE;AAoBjB;AA4DA;;;;;;;;;;;;;;;;;;;;;;;;UA3FiBD,gBAAAA;;;;;;;;;;;UAWAC,gBAAAA;;;;;YAKHD;;;;;iBAKKD;;;;;;;;;;KAUPG,aAAAA,GAAgBL,QAAAA,CAAaM,SAAAA,CAAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4D3BE,SAAAA,WAAoBH,mBAAmBH"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//#region src/tools/webSearch.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a web search tool that allows OpenAI models to search the web
|
|
4
|
+
* for up-to-date information before generating a response.
|
|
5
|
+
*
|
|
6
|
+
* Web search supports three main types:
|
|
7
|
+
* 1. **Non-reasoning web search**: Quick lookups where the model passes queries
|
|
8
|
+
* directly to the search tool.
|
|
9
|
+
* 2. **Agentic search with reasoning models**: The model actively manages the
|
|
10
|
+
* search process, analyzing results and deciding whether to keep searching.
|
|
11
|
+
* 3. **Deep research**: Extended investigations using models like `o3-deep-research`
|
|
12
|
+
* or `gpt-5` with high reasoning effort.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://platform.openai.com/docs/guides/tools-web-search | OpenAI Web Search Documentation}
|
|
15
|
+
* @param options - Configuration options for the web search tool
|
|
16
|
+
* @returns A web search tool definition to be passed to the OpenAI Responses API
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { ChatOpenAI, tools } from "@langchain/openai";
|
|
21
|
+
*
|
|
22
|
+
* const model = new ChatOpenAI({
|
|
23
|
+
* model: "gpt-4o",
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Basic usage
|
|
27
|
+
* const response = await model.invoke("What was a positive news story from today?", {
|
|
28
|
+
* tools: [tools.webSearch()],
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // With domain filtering
|
|
32
|
+
* const filteredResponse = await model.invoke("Latest AI research news", {
|
|
33
|
+
* tools: [tools.webSearch({
|
|
34
|
+
* filters: {
|
|
35
|
+
* allowedDomains: ["arxiv.org", "nature.com", "science.org"],
|
|
36
|
+
* },
|
|
37
|
+
* })],
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // With user location for geographic relevance
|
|
41
|
+
* const localResponse = await model.invoke("What are the best restaurants near me?", {
|
|
42
|
+
* tools: [tools.webSearch({
|
|
43
|
+
* userLocation: {
|
|
44
|
+
* type: "approximate",
|
|
45
|
+
* country: "US",
|
|
46
|
+
* city: "San Francisco",
|
|
47
|
+
* region: "California",
|
|
48
|
+
* timezone: "America/Los_Angeles",
|
|
49
|
+
* },
|
|
50
|
+
* })],
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Cache-only mode (no live internet access)
|
|
54
|
+
* const cachedResponse = await model.invoke("Find information about OpenAI", {
|
|
55
|
+
* tools: [tools.webSearch({
|
|
56
|
+
* externalWebAccess: false,
|
|
57
|
+
* })],
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function webSearch(options) {
|
|
62
|
+
return {
|
|
63
|
+
type: "web_search",
|
|
64
|
+
filters: options?.filters?.allowedDomains ? { allowed_domains: options.filters.allowedDomains } : void 0,
|
|
65
|
+
user_location: options?.userLocation,
|
|
66
|
+
search_context_size: options?.search_context_size
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { webSearch };
|
|
72
|
+
//# sourceMappingURL=webSearch.js.map
|