Skip to content

Documentation / @agentick/core / createTool

Function: createTool() ​

Call Signature ​

createTool<TInput, TOutput, TDeps>(options): RunnableToolClass<TInput>

Defined in: core/src/tool/tool.ts:437

Creates a tool that can be passed to models, run directly, or used in JSX.

The returned class has static metadata and run properties making it a valid ExecutableTool, while also being instantiable as a Component.

Type Parameters ​

TInput ​

TInput = any

TOutput ​

TOutput extends ContentBlock[] = ContentBlock[]

TDeps ​

TDeps extends Record<string, any> = Record<string, any>

Parameters ​

options ​

Omit<CreateToolOptions<TInput, TOutput, TDeps>, "handler" | "use"> & object

Returns ​

RunnableToolClass<TInput>

Examples ​

typescript
const Calculator = createTool({
  name: 'calculator',
  description: 'Performs mathematical calculations',
  input: z.object({
    expression: z.string().describe('Math expression to evaluate')
  }),
  handler: async ({ expression }) => {
    const result = eval(expression);
    return [{ type: 'text', text: String(result) }];
  },
});

// Pattern 1: Pass to model
engine.execute({
  messages: [...],
  tools: [Calculator],
});

// Pattern 2: Run directly
const result = await Calculator.run({ expression: '2 + 2' });

// Pattern 3: Use in JSX (registers tool when component mounts)
function MyAgent() {
  return (
    <>
      <Calculator />
      <Model />
    </>
  );
}
typescript
const RenderChart = createTool({
  name: 'render_chart',
  description: 'Renders a chart in the UI',
  input: z.object({
    type: z.enum(['line', 'bar', 'pie']),
    data: z.array(z.object({ label: z.string(), value: z.number() })),
  }),
  type: ToolExecutionType.CLIENT,
  intent: ToolIntent.RENDER,
  requiresResponse: false,
  defaultResult: [{ type: 'text', text: '[Chart rendered]' }],
});

Call Signature ​

createTool<TInput, TOutput>(options): RunnableToolClass<TInput>

Defined in: core/src/tool/tool.ts:449

Creates a tool that can be passed to models, run directly, or used in JSX.

The returned class has static metadata and run properties making it a valid ExecutableTool, while also being instantiable as a Component.

Type Parameters ​

TInput ​

TInput = any

TOutput ​

TOutput extends ContentBlock[] = ContentBlock[]

Parameters ​

options ​

CreateToolOptions<TInput, TOutput, { }> & object

Returns ​

RunnableToolClass<TInput>

Examples ​

typescript
const Calculator = createTool({
  name: 'calculator',
  description: 'Performs mathematical calculations',
  input: z.object({
    expression: z.string().describe('Math expression to evaluate')
  }),
  handler: async ({ expression }) => {
    const result = eval(expression);
    return [{ type: 'text', text: String(result) }];
  },
});

// Pattern 1: Pass to model
engine.execute({
  messages: [...],
  tools: [Calculator],
});

// Pattern 2: Run directly
const result = await Calculator.run({ expression: '2 + 2' });

// Pattern 3: Use in JSX (registers tool when component mounts)
function MyAgent() {
  return (
    <>
      <Calculator />
      <Model />
    </>
  );
}
typescript
const RenderChart = createTool({
  name: 'render_chart',
  description: 'Renders a chart in the UI',
  input: z.object({
    type: z.enum(['line', 'bar', 'pie']),
    data: z.array(z.object({ label: z.string(), value: z.number() })),
  }),
  type: ToolExecutionType.CLIENT,
  intent: ToolIntent.RENDER,
  requiresResponse: false,
  defaultResult: [{ type: 'text', text: '[Chart rendered]' }],
});

Call Signature ​

createTool<TInput, TOutput>(options): ToolClass<TInput>

Defined in: core/src/tool/tool.ts:454

Creates a tool that can be passed to models, run directly, or used in JSX.

The returned class has static metadata and run properties making it a valid ExecutableTool, while also being instantiable as a Component.

Type Parameters ​

TInput ​

TInput = any

TOutput ​

TOutput extends ContentBlock[] = ContentBlock[]

Parameters ​

options ​

CreateToolOptions<TInput, TOutput, { }> & object

Returns ​

ToolClass<TInput>

Examples ​

typescript
const Calculator = createTool({
  name: 'calculator',
  description: 'Performs mathematical calculations',
  input: z.object({
    expression: z.string().describe('Math expression to evaluate')
  }),
  handler: async ({ expression }) => {
    const result = eval(expression);
    return [{ type: 'text', text: String(result) }];
  },
});

// Pattern 1: Pass to model
engine.execute({
  messages: [...],
  tools: [Calculator],
});

// Pattern 2: Run directly
const result = await Calculator.run({ expression: '2 + 2' });

// Pattern 3: Use in JSX (registers tool when component mounts)
function MyAgent() {
  return (
    <>
      <Calculator />
      <Model />
    </>
  );
}
typescript
const RenderChart = createTool({
  name: 'render_chart',
  description: 'Renders a chart in the UI',
  input: z.object({
    type: z.enum(['line', 'bar', 'pie']),
    data: z.array(z.object({ label: z.string(), value: z.number() })),
  }),
  type: ToolExecutionType.CLIENT,
  intent: ToolIntent.RENDER,
  requiresResponse: false,
  defaultResult: [{ type: 'text', text: '[Chart rendered]' }],
});

Released under the ISC License.