Skip to main content

Overview

LuaTool is the interface that all tools must implement. A tool is a single function that the AI can call to accomplish a specific task.

Interface Definition

Required Properties

name

Unique identifier for the tool.
string
required
Tool name using only: a-z, A-Z, 0-9, -, _Examples: "get_weather", "create-order", "sendEmail123"Invalid: "get weather", "tool.name", "send@email"

description

Clear, concise description of what the tool does.
string
required
One sentence describing the tool’s purposeHelps the AI understand when to use this tool

inputSchema

Zod schema that validates and types the input.
ZodType
required
Zod schema defining valid inputsProvides runtime validation and TypeScript types

execute

Async function that implements the tool’s logic.
function
required
  • Input is automatically validated
  • Must return a JSON-serializable value
  • Can throw errors for failures

Optional Properties

condition

Async function that determines if the tool should be available to the AI.
function
  • Runs before the tool is offered to the AI
  • Return true to enable the tool, false to hide it
  • If the function throws an error, the tool is disabled (fail-closed)
  • Has access to all Platform APIs (User, Data, Products, etc.)
Use conditions to dynamically enable/disable tools based on:
  • User subscription status (premium features)
  • User verification or account status
  • Feature flags or A/B testing
  • Region-specific functionality
  • Time-based access
Fail-closed behavior: If your condition function throws an error or times out (30s), the tool is automatically disabled. This ensures tools aren’t accidentally exposed when conditions can’t be evaluated.
A disabled tool is left out of the prompt’s tool list, but the skill’s name and context stay in the agent’s prompt — the agent can still say “that’s a premium feature, so I can’t do that”. To hide the capability entirely, put the same condition on the skill: see Skill condition vs tool condition.

Implementation Examples

Simple Tool

External API Tool

Platform API Tool

Environment Variables Tool

Multi-Step Tool

Conditional Tool (Premium Feature)

Reusing Tools Across Agents

When multiple agents share the same tool logic — same API, same auth, same shape — but differ on a couple of config values, declare the shared parts on an abstract base and have each agent’s tool extend it. The compiler walks the full extends chain, so a leaf class is detected as a tool whether it extends LuaTool directly or through any number of intermediate bases.
Register the leaf class on a skill — pass the class itself, not an instance:
Field initializers on the leaf run during construction, so this.searchPath inside the parent’s execute resolves to '/blk/search'. The leaf inherits inputSchema, description, and execute from the parent unless it overrides them.
Don’t pass constructor arguments at the reference site:
The compiler reports lua/constructor-args-dropped if it sees this. Use a subclass with a field override instead.

Input Schema Patterns

Optional Fields

Validation

Nested Objects

Arrays

Enums

Error Handling

Throwing Errors

Try-Catch Pattern

Return Value Patterns

Structured Data

Lists

Status Updates

Best Practices

Always return objects, not strings:
Provide helpful error messages:
One tool = one responsibility:

Next Steps

LuaSkill Class

Learn about skills

Platform APIs

Use built-in APIs

Tool Examples

See working examples

Build Your First Skill

Complete tutorial