tools / Exports
tools
Table of contents
Classes
Interfaces
- ZodFunctionToolProviderOptions
- FunctionOptions
- ToolFunction
- ToolResult
- ToolParameter
- Tool
- CreateToolOptions
- MCPClient
- ToolProvider
- ToolInterface
- BaseToolOptions
- ZodToolOptions
- McpToolOptions
- OpenApiToolOptions
- FunctionSchema
- FunctionDefinition
- FunctionCall
- FunctionCallResult
- ZodFunctionTool
Type Aliases
Functions
- createZodFunctionToolProvider
- createFunction
- functionFromCallback
- createFunctionSchema
- createTool
- createMcpToolProvider
- createOpenAPIToolProvider
- zodToJsonSchema
- zodFunctionToSchema
Type Aliases
FunctionResult
Ƭ FunctionResult<TResult
>: Object
Function result type
Type parameters
Name | Type |
---|---|
TResult | unknown |
Type declaration
Name | Type |
---|---|
result | TResult |
Defined in
packages/tools/src/function.ts:16
FunctionHandler
Ƭ FunctionHandler: (args
: Record
<string
, any
>, context?
: any
) => Promise
<any
>
Function call handler type
Type declaration
▸ (args
, context?
): Promise
<any
>
Parameters
Name | Type |
---|---|
args | Record <string , any > |
context? | any |
Returns
Promise
<any
>
Defined in
packages/tools/src/function.ts:378
Functions
createZodFunctionToolProvider
▸ createZodFunctionToolProvider(options
): ToolProvider
Zod 스키마 기반 함수 도구 제공자를 생성합니다.
Parameters
Name | Type | Description |
---|---|---|
options | ZodFunctionToolProviderOptions | 함수 도구 제공자 옵션 |
Returns
도구 제공자 인스턴스 (ToolProvider 인터페이스 구현)
Example
const calculatorTool = {
name: 'add',
description: '두 숫자를 더합니다',
parameters: z.object({
a: z.number().describe('첫 번째 숫자'),
b: z.number().describe('두 번째 숫자')
}),
handler: async ({ a, b }) => ({ result: a + b })
};
const provider = createZodFunctionToolProvider({
tools: { add: calculatorTool }
});
const robota = new Robota({
aiClient: openaiProvider,
provider: provider,
systemPrompt: '당신은 도움이 되는 계산기입니다.'
});
Defined in
packages/tools/src/function-tool-provider.ts:50
createFunction
▸ createFunction<TParams
, TResult
>(options
): ToolFunction
<TParams
, TResult
>
Create a function
Type parameters
Name | Type | Description |
---|---|---|
TParams | unknown | function parameter type |
TResult | unknown | function return result type |
Parameters
Name | Type | Description |
---|---|---|
options | FunctionOptions <TParams , TResult > | Function options |
Returns
ToolFunction
<TParams
, TResult
>
Created function object
Function
createFunction
Description
Creates a function that AI can invoke. You can define function name, description, parameter schema, and execution logic.
Example
import { z } from 'zod';
import { createFunction } from '@robota-sdk/tools';
const getWeather = createFunction({
name: 'getWeather',
description: 'Get weather information for a specific location.',
parameters: z.object({
location: z.string().describe('Location to check weather (city name)'),
unit: z.enum(['celsius', 'fahrenheit']).optional().describe('Temperature unit')
}),
execute: async (params) => {
// Weather API call logic
return { temperature: 25, condition: 'sunny' };
}
});
Defined in
packages/tools/src/function.ts:240
functionFromCallback
▸ functionFromCallback(name
, fn
, description?
): ToolFunction
<Record
<string
, any
>, any
>
Convert callback function to Function object
Parameters
Name | Type | Description |
---|---|---|
name | string | Function name |
fn | (...args : any []) => any | Callback function to convert |
description? | string | Function description |
Returns
ToolFunction
<Record
<string
, any
>, any
>
Created function object
Function
functionFromCallback
Description
Converts a regular JavaScript function to a Function object that AI can invoke.
Example
import { functionFromCallback } from '@robota-sdk/tools';
const calculateSum = functionFromCallback(
'calculateSum',
(a: number, b: number) => a + b,
'Calculate the sum of two numbers.'
);
Defined in
packages/tools/src/function.ts:311
createFunctionSchema
▸ createFunctionSchema(definition
): ZodObject
<Record
<string
, ZodTypeAny
>, "strip"
, ZodTypeAny
, {}, {}>
Utility function to convert function schema to Zod schema
Parameters
Name | Type |
---|---|
definition | FunctionDefinition |
Returns
ZodObject
<Record
<string
, ZodTypeAny
>, "strip"
, ZodTypeAny
, {}, {}>
Defined in
packages/tools/src/function.ts:345
createTool
▸ createTool<TInput
, TOutput
>(options
): Tool
<TInput
, TOutput
>
Tool creation function
Type parameters
Name | Type |
---|---|
TInput | any |
TOutput | any |
Parameters
Name | Type | Description |
---|---|---|
options | CreateToolOptions <TInput , TOutput > | Tool creation options |
Returns
Tool
<TInput
, TOutput
>
Created tool
Example
const weatherTool = createTool({
name: 'getWeather',
description: 'Get weather information for a specific location',
parameters: [
{ name: 'location', type: 'string', description: 'Location (city name)', required: true }
],
execute: async ({ location }) => {
// Weather API call logic
return { temperature: 25, humidity: 60, conditions: 'sunny' };
}
});
Defined in
packages/tools/src/index.ts:132
createMcpToolProvider
▸ createMcpToolProvider(mcpClient
): ToolProvider
MCP(Model Context Protocol) based tool provider creation function
Parameters
Name | Type | Description |
---|---|---|
mcpClient | MCPClient | MCP client instance |
Returns
MCP-based tool provider object
Defined in
packages/tools/src/mcp-tool-provider.ts:22
createOpenAPIToolProvider
▸ createOpenAPIToolProvider(openApiSpec
, options?
): ToolProvider
Create tool provider based on OpenAPI specification
Parameters
Name | Type | Description |
---|---|---|
openApiSpec | any | OpenAPI specification object or URL |
options? | Object | Base URL configuration |
options.baseUrl? | string | - |
Returns
OpenAPI-based tool provider
Defined in
packages/tools/src/openapi-tool-provider.ts:11
zodToJsonSchema
▸ zodToJsonSchema(schema
): Object
Zod 객체 스키마를 JSON 스키마로 변환합니다.
Parameters
Name | Type | Description |
---|---|---|
schema | ZodObject <ZodRawShape , UnknownKeysParam , ZodTypeAny , {}, {}> | 변환할 Zod 객체 스키마 |
Returns
Object
JSON 스키마 객체
Name | Type |
---|---|
type | string |
properties | Record <string , unknown > |
required? | string [] |
Example
const userSchema = z.object({
name: z.string().describe('사용자 이름'),
age: z.number().min(0).describe('사용자 나이'),
email: z.string().email().optional().describe('이메일 주소')
});
const jsonSchema = zodToJsonSchema(userSchema);
// {
// type: 'object',
// properties: {
// name: { type: 'string', description: '사용자 이름' },
// age: { type: 'number', description: '사용자 나이' },
// email: { type: 'string', description: '이메일 주소' }
// },
// required: ['name', 'age']
// }
Defined in
packages/tools/src/zod-schema.ts:38
zodFunctionToSchema
▸ zodFunctionToSchema<T
>(tool
): Object
Zod 함수 도구를 Robota 호환 함수 스키마로 변환합니다.
Type parameters
Name | Type |
---|---|
T | extends ZodObject <ZodRawShape , UnknownKeysParam , ZodTypeAny , {}, {}> |
Parameters
Name | Type | Description |
---|---|---|
tool | ZodFunctionTool <T > | Zod 기반 함수 도구 정의 |
Returns
Object
Robota 호환 함수 스키마
Name | Type |
---|---|
name | string |
description | string |
parameters | { type : string ; properties : Record <string , unknown > ; required? : string [] } |
parameters.type | string |
parameters.properties | Record <string , unknown > |
parameters.required? | string [] |