Class: ZodTool<TParams, TResult>
Zod schema-based tool class
ZodTool
Description
Tool that uses Zod schema for parameter validation.
Example
import { z } from 'zod';
import { ZodTool } from '@robota-sdk/tools';
const weatherTool = new ZodTool({
name: 'getWeather',
description: 'Get weather information for a specific location.',
category: 'data',
version: '1.0.0',
parameters: z.object({
location: z.string().describe('Location to get weather for (city name)'),
unit: z.enum(['celsius', 'fahrenheit']).optional().describe('Temperature unit')
}),
execute: async (params) => {
// Weather API call logic
const data = { temperature: 25, condition: 'sunny' };
return {
status: 'success',
data
};
}
});
Type parameters
Name | Type | Description |
---|---|---|
TParams | any | Tool parameter type |
TResult | any | Tool result type |
Hierarchy
BaseTool
<TParams
,TResult
>↳
ZodTool
Table of contents
Constructors
Properties
Accessors
Methods
Constructors
constructor
• new ZodTool<TParams
, TResult
>(options
): ZodTool
<TParams
, TResult
>
Constructor
Type parameters
Name | Type |
---|---|
TParams | any |
TResult | any |
Parameters
Name | Type | Description |
---|---|---|
options | ZodToolOptions <TParams , TResult > | Zod tool options |
Returns
ZodTool
<TParams
, TResult
>
Overrides
Defined in
packages/tools/src/tool/zod-tool.ts:61
Properties
name
• Readonly
name: string
Tool name
Inherited from
Defined in
packages/tools/src/tool/base-tool.ts:29
description
• Readonly
description: string
Tool description
Inherited from
Defined in
packages/tools/src/tool/base-tool.ts:34
category
• Optional
Readonly
category: string
Tool category
Inherited from
Defined in
packages/tools/src/tool/base-tool.ts:39
version
• Optional
Readonly
version: string
Tool version
Inherited from
Defined in
packages/tools/src/tool/base-tool.ts:44
Accessors
schema
• get
schema(): ZodObject
<any
, UnknownKeysParam
, ZodTypeAny
, {}, {}>
Tool schema (returns Zod schema)
Returns
ZodObject
<any
, UnknownKeysParam
, ZodTypeAny
, {}, {}>
Zod schema
Overrides
BaseTool.schema
Defined in
packages/tools/src/tool/zod-tool.ts:71
Methods
execute
▸ execute(params
): Promise
<ToolResult
<TResult
>>
Execute tool
Parameters
Name | Type | Description |
---|---|---|
params | TParams | Tool parameters |
Returns
Promise
<ToolResult
<TResult
>>
Tool execution result
Inherited from
Defined in
packages/tools/src/tool/base-tool.ts:108
toFunctionSchema
▸ toFunctionSchema(): FunctionSchema
Convert to function schema
Returns
Function schema
Inherited from
Defined in
packages/tools/src/tool/base-tool.ts:145
toFunctionDefinition
▸ toFunctionDefinition(): FunctionDefinition
Convert to function definition
Returns
Function definition
Inherited from
Defined in
packages/tools/src/tool/base-tool.ts:158
toString
▸ toString(): string
Generate string representation
Returns
string
String representation of the tool
Inherited from
Defined in
packages/tools/src/tool/base-tool.ts:171
create
▸ create<TParams
, TResult
>(options
): ZodTool
<TParams
, TResult
>
Zod tool creation helper method
Type parameters
Name | Type |
---|---|
TParams | any |
TResult | any |
Parameters
Name | Type | Description |
---|---|---|
options | ZodToolOptions <TParams , TResult > | Zod tool options |
Returns
ZodTool
<TParams
, TResult
>
ZodTool instance