Skip to content

@aeye/core — Tool

The Tool class represents a function that AI models can call.

Constructor

typescript
new Tool<TContext, TMetadata, TName, TParams, TOutput, TRefs>(input: ToolInput)

ToolInput

PropertyTypeRequiredDescription
namestringYesUnique tool name
descriptionstringYesDescription shown to AI model
schemaZodType | (ctx) => ZodTypeYesInput parameter schema
call(input, refs, ctx) => outputYesImplementation function
instructionsstringNoHandlebars template for usage guidance
instructionsFn(ctx) => stringNoDynamic instructions
input(ctx) => objectNoTemplate variables for instructions
strictbooleanNoStrict JSON schema (default: true)
refsComponent[]NoReferenced components
validate(input, ctx) => voidNoPost-parse validation
applicable(ctx) => booleanNoAvailability check
metadataobjectNoStatic metadata
metadataFn(input, ctx) => objectNoDynamic metadata
descriptionFn(ctx) => stringNoDynamic description

Properties

PropertyTypeDescription
kind'tool'Component kind
nameTNameTool name
descriptionstringTool description
refsTRefsReferenced components
inputToolInputFull configuration

Methods

run(input, ctx?)

Execute the tool directly.

typescript
const result = await tool.run({ city: 'Paris' }, ctx);

applicable(ctx?)

Check if the tool is available in the given context.

typescript
const available = await tool.applicable(ctx);

parse(ctx, args, schema?)

Parse and validate raw arguments against the schema.

typescript
const parsed = await tool.parse(ctx, '{"city": "Paris"}');

compile(ctx)

Compile instructions and schema for AI model consumption.

typescript
const [instructions, definition] = await tool.compile(ctx);
// instructions: rendered template string
// definition: { name, description, parameters, strict }

Returns undefined if applicable() returns false.

metadata(input?, ctx?)

Get tool metadata (static or dynamic).

Special Error Classes

ToolInterrupt

Interrupt tool execution to surface a message (e.g., for user confirmation):

typescript
import { ToolInterrupt } from '@aeye/core';

throw new ToolInterrupt('Are you sure you want to delete this?');

PromptSuspend

Suspend the entire prompt at this tool call point:

typescript
import { PromptSuspend } from '@aeye/core';

throw new PromptSuspend('Waiting for user input');

Released under the GPL-3.0 License.