import { ComparisonFilter, CompoundFilter } from 'openai/resources/shared'; import { FileSearchTool as file_search_tool, WebSearchTool as web_search_tool } from 'openai/resources/responses/responses'; import { MCPTool } from '../mcp/types'; import { RunItem } from '../items'; import { RunContextWrapper } from '../run-context'; import { Computer, AsyncComputer } from '../computer'; import { DocstringStyle } from '../function-schema'; /** * Types for different tool functions with and without context */ export type ToolFunctionWithoutContext = (...args: TParams) => TReturn | Promise; export type ToolFunctionWithContext = (context: RunContextWrapper, ...args: TParams) => TReturn | Promise; export type ToolFunction = ToolFunctionWithoutContext | ToolFunctionWithContext; /** * Constructor parameters for FunctionToolResult */ export interface FunctionToolResultProps { tool: FunctionTool; output: any; run_item: RunItem; } /** * Result of running a function tool */ export declare class FunctionToolResult { /** * The tool that was run */ tool: FunctionTool; /** * The output of the tool */ output: any; /** * The run item that was produced as a result of the tool call */ run_item: RunItem; constructor({ tool, output, run_item }: FunctionToolResultProps); } /** * Constructor parameters for FunctionTool */ export interface FunctionToolProps { name: string; description: string; params_json_schema: Record; on_invoke_tool: ({ context, input, }: { context: RunContextWrapper; input: string; }) => Promise; strict_json_schema?: boolean; } /** * A tool that wraps a function. In most cases, you should use the `functionTool` helpers to * create a FunctionTool, as they let you easily wrap a TypeScript function. */ export declare class FunctionTool { /** * The name of the tool, as shown to the LLM. Generally the name of the function. */ name: string; /** * A description of the tool, as shown to the LLM. */ description: string; /** * The JSON schema for the tool's parameters. */ params_json_schema: Record; /** * A function that invokes the tool with the given context and parameters. The params passed * are: * 1. The tool run context. * 2. The arguments from the LLM, as a JSON string. * * You must return a string representation of the tool output, or something we can call `String()` on. * In case of errors, you can either throw an Exception (which will cause the run to fail) or * return a string error message (which will be sent back to the LLM). */ on_invoke_tool: ({ context, input, }: { context: RunContextWrapper; input: string; }) => Promise; /** * Whether the JSON schema is in strict mode. We **strongly** recommend setting this to true, * as it increases the likelihood of correct JSON input. */ strict_json_schema: boolean; constructor({ name, description, params_json_schema, on_invoke_tool, strict_json_schema, }: FunctionToolProps); } /** * Constructor parameters for FileSearchTool */ export interface FileSearchToolProps { vector_store_ids: string[]; max_num_results?: number; include_search_results?: boolean; ranking_options?: file_search_tool.RankingOptions; filters?: ComparisonFilter | CompoundFilter; } /** * A hosted tool that lets the LLM search through a vector store. Currently only supported with * OpenAI models, using the Responses API. */ export declare class FileSearchTool { /** * The IDs of the vector stores to search. */ vector_store_ids: string[]; /** * The maximum number of results to return. */ max_num_results?: number; /** * Whether to include the search results in the output produced by the LLM. */ include_search_results: boolean; /** * Ranking options for search. */ ranking_options?: file_search_tool.RankingOptions; /** * A filter to apply based on file attributes. */ filters?: ComparisonFilter | CompoundFilter; /** * The name of the tool */ get name(): string; constructor({ vector_store_ids, max_num_results, include_search_results, ranking_options, filters, }: FileSearchToolProps); } /** * Constructor parameters for WebSearchTool */ export interface WebSearchToolProps { user_location?: web_search_tool.UserLocation; search_context_size?: 'low' | 'medium' | 'high'; } /** * A hosted tool that lets the LLM search the web. Currently only supported with OpenAI models, * using the Responses API. */ export declare class WebSearchTool { /** * Optional location for the search. Lets you customize results to be relevant to a location. */ user_location?: web_search_tool.UserLocation; /** * The amount of context to use for the search. */ search_context_size: 'low' | 'medium' | 'high'; /** * The name of the tool */ get name(): string; constructor({ user_location, search_context_size, }: WebSearchToolProps); } /** * Constructor parameters for ComputerTool */ export interface ComputerToolProps { computer: Computer | AsyncComputer; } /** * A hosted tool that lets the LLM control a computer. */ export declare class ComputerTool { /** * The computer implementation, which describes the environment and dimensions of the computer, * as well as implements the computer actions like click, screenshot, etc. */ computer: Computer | AsyncComputer; /** * The name of the tool */ get name(): string; constructor({ computer }: ComputerToolProps); } /** * A tool that can be used in an agent. */ export type Tool = FunctionTool | FileSearchTool | WebSearchTool | ComputerTool | MCPTool; /** * Function type for handling tool errors */ export type ToolErrorFunction = (ctx: RunContextWrapper, error: Error) => string | Promise; /** * The default tool error function, which just returns a generic error message. */ export declare const defaultToolErrorFunction: ToolErrorFunction; /** * Options for creating a function tool */ export interface FunctionToolOptions { /** * Override the name of the tool (defaults to function name) */ nameOverride?: string; /** * Override the description of the tool (defaults to function docstring) */ descriptionOverride?: string; /** * Style of the docstring */ docstringStyle?: DocstringStyle; /** * Whether to use the function's docstring for descriptions */ useDocstringInfo?: boolean; /** * Function to handle errors in the tool */ failureErrorFunction?: ToolErrorFunction | null; /** * Whether to use strict mode for JSON schema validation */ strictMode?: boolean; }