Skip to content

tools / Exports / ZodTool

Class: ZodTool<TParams, TResult>

Zod schema-based tool class

ZodTool

Description

Tool that uses Zod schema for parameter validation.

Example

typescript
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

NameTypeDescription
TParamsanyTool parameter type
TResultanyTool result type

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new ZodTool<TParams, TResult>(options): ZodTool<TParams, TResult>

Constructor

Type parameters

NameType
TParamsany
TResultany

Parameters

NameTypeDescription
optionsZodToolOptions<TParams, TResult>Zod tool options

Returns

ZodTool<TParams, TResult>

Overrides

BaseTool.constructor

Defined in

packages/tools/src/tool/zod-tool.ts:61

Properties

name

Readonly name: string

Tool name

Inherited from

BaseTool.name

Defined in

packages/tools/src/tool/base-tool.ts:29


description

Readonly description: string

Tool description

Inherited from

BaseTool.description

Defined in

packages/tools/src/tool/base-tool.ts:34


category

Optional Readonly category: string

Tool category

Inherited from

BaseTool.category

Defined in

packages/tools/src/tool/base-tool.ts:39


version

Optional Readonly version: string

Tool version

Inherited from

BaseTool.version

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

NameTypeDescription
paramsTParamsTool parameters

Returns

Promise<ToolResult<TResult>>

Tool execution result

Inherited from

BaseTool.execute

Defined in

packages/tools/src/tool/base-tool.ts:108


toFunctionSchema

toFunctionSchema(): FunctionSchema

Convert to function schema

Returns

FunctionSchema

Function schema

Inherited from

BaseTool.toFunctionSchema

Defined in

packages/tools/src/tool/base-tool.ts:145


toFunctionDefinition

toFunctionDefinition(): FunctionDefinition

Convert to function definition

Returns

FunctionDefinition

Function definition

Inherited from

BaseTool.toFunctionDefinition

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

BaseTool.toString

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

NameType
TParamsany
TResultany

Parameters

NameTypeDescription
optionsZodToolOptions<TParams, TResult>Zod tool options

Returns

ZodTool<TParams, TResult>

ZodTool instance

Defined in

packages/tools/src/tool/zod-tool.ts:185

Released under the MIT License.