@openai/agents-openai
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
165 lines • 6.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.webSearchTool = webSearchTool;
exports.fileSearchTool = fileSearchTool;
exports.codeInterpreterTool = codeInterpreterTool;
exports.programmaticToolCallingTool = programmaticToolCallingTool;
exports.toolSearchTool = toolSearchTool;
exports.imageGenerationTool = imageGenerationTool;
const agents_core_1 = require("@openai/agents-core");
const internal_1 = require("@openai/agents-core/utils/internal");
/**
* Adds web search abilities to your agent
* @param options Additional configuration for the web search like specifying the location of your agent
* @returns a web search tool definition
*/
function webSearchTool(options = {}) {
const providerData = {
type: 'web_search',
name: options.name ?? 'web_search',
user_location: options.userLocation,
filters: options.filters?.allowedDomains
? { allowed_domains: options.filters.allowedDomains }
: undefined,
search_context_size: options.searchContextSize ?? 'medium',
};
if (options.externalWebAccess !== undefined) {
providerData.external_web_access = options.externalWebAccess;
}
if (options.searchContentTypes !== undefined) {
providerData.search_content_types = options.searchContentTypes;
}
if (options.imageSettings !== undefined) {
providerData.image_settings = {
max_results: options.imageSettings.maxResults,
caption: options.imageSettings.caption,
};
}
return {
type: 'hosted_tool',
name: options.name ?? 'web_search',
providerData,
};
}
/**
* Adds file search abilities to your agent
* @param vectorStoreIds The IDs of the vector stores to search.
* @param options Additional configuration for the file search like specifying the maximum number of results to return.
* @returns a file search tool definition
*/
function fileSearchTool(vectorStoreIds, options = {}) {
const vectorIds = Array.isArray(vectorStoreIds)
? vectorStoreIds
: [vectorStoreIds];
const providerData = {
type: 'file_search',
name: options.name ?? 'file_search',
vector_store_ids: vectorIds,
max_num_results: options.maxNumResults,
include_search_results: options.includeSearchResults,
ranking_options: options.rankingOptions,
filters: options.filters,
};
return {
type: 'hosted_tool',
name: options.name ?? 'file_search',
providerData,
};
}
/**
* Adds code interpreter abilities to your agent
* @param options Additional configuration for the code interpreter
* @returns a code interpreter tool definition
*/
function codeInterpreterTool(options = {}) {
const allowedCallers = (0, internal_1.normalizeToolAllowedCallers)(options.allowedCallers, options.name ?? 'code_interpreter');
const providerData = {
type: 'code_interpreter',
name: options.name ?? 'code_interpreter',
container: options.container ?? { type: 'auto' },
include_outputs: options.includeOutputs,
allowed_callers: allowedCallers ? [...allowedCallers] : undefined,
};
return {
type: 'hosted_tool',
name: options.name ?? 'code_interpreter',
providerData,
};
}
/**
* Enables Programmatic Tool Calling for eligible Responses API tools.
*/
function programmaticToolCallingTool() {
return {
type: 'hosted_tool',
name: 'programmatic_tool_calling',
providerData: {
type: 'programmatic_tool_calling',
},
};
}
/**
* Adds tool_search capabilities to your agent.
*
* This lets the model search deferred function tools and load them into context on demand.
* By default, tool search is executed by OpenAI. Set `execution: 'client'` to
* use a custom loop that receives `tool_search_call` / `tool_search_output`
* items. The standard runner only supports the default built-in client schema
* (leave `parameters` unset) and auto-executes `{ paths: string[] }` searches
* over deferred top-level function tools and deferred namespace members.
*
* @returns a hosted tool_search definition.
*/
function toolSearchTool(options = {}) {
if (typeof options.name === 'string' && options.name !== 'tool_search') {
throw new agents_core_1.UserError('toolSearchTool() only supports the canonical built-in name "tool_search".');
}
if (typeof options.execute === 'function' && options.execution !== 'client') {
throw new agents_core_1.UserError('toolSearchTool() only supports execute when execution is "client".');
}
const providerData = {
type: 'tool_search',
name: 'tool_search',
execution: options.execution,
description: options.description,
parameters: options.parameters,
};
const hostedTool = {
type: 'hosted_tool',
name: 'tool_search',
providerData,
};
if (typeof options.execute === 'function') {
(0, agents_core_1.attachClientToolSearchExecutor)(hostedTool, options.execute);
}
return hostedTool;
}
/**
* Adds image generation abilities to your agent
* @param options Additional configuration for the image generation
* @returns an image generation tool definition
*/
function imageGenerationTool(options = {}) {
const providerData = {
type: 'image_generation',
name: options.name ?? 'image_generation',
action: options.action,
background: options.background,
input_fidelity: options.inputFidelity,
input_image_mask: options.inputImageMask,
model: options.model,
moderation: options.moderation,
output_compression: options.outputCompression,
output_format: options.outputFormat,
partial_images: options.partialImages,
quality: options.quality,
size: options.size,
};
return {
type: 'hosted_tool',
name: options.name ?? 'image_generation',
providerData,
};
}
// HostedMCPTool exists in agents-core package
//# sourceMappingURL=tools.js.map