Skip to main content

What is Lua?

Lua is a platform for building AI agents with custom capabilities. Think of it like:
AI Agent (ChatGPT-like)
    └── Skills (Custom capabilities you build)
        └── Tools (Specific functions the AI can call)

Skills

A skill is a collection of related tools that give your AI agent specific capabilities.

Example: Coffee Shop Skill

import { LuaSkill } from "lua-cli";

const coffeeSkill = new LuaSkill({
  name: "coffee-shop-skill",
  description: "Coffee shop assistant with menu, ordering, and loyalty features",
  context: `
    This skill helps customers of Java Junction Coffee Shop.
    
    - Use show_menu to display available drinks and food
    - Use create_order to take customer orders
    - Use check_loyalty_points to show rewards balance
    - Use redeem_reward to apply loyalty discounts
    
    Always mention daily specials.
    Ask about size preferences for drinks.
  `,
  tools: [
    new ShowMenuTool(),
    new CreateOrderTool(),
    new CheckLoyaltyTool(),
    new RedeemRewardTool()
  ]
});

Skill Properties

name
string
required
Unique identifier for the skill (e.g., “coffee-shop-skill”)
description
string
required
Brief description (1-2 sentences) of what the skill does
context
string
required
Detailed instructions for the AI on when and how to use the tools. This is critical for proper tool selection!
tools
LuaTool[]
Array of tool instances to include in the skill

Writing Good Context

The context field guides the AI’s decision-making. Write it like instructions to a smart assistant:
context: `
  This skill manages customer orders for a coffee shop.

  Tool Usage:
  - show_menu: Use when customers ask what's available. Returns drinks and food items.
  - create_order: Use when taking an order. Confirm items and sizes first.
  - modify_order: Use to add/remove items. Ask which item to modify.
  - finalize_order: Use when order is confirmed. Returns total and wait time.

  Guidelines:
  - Always ask about size for drinks (small/medium/large)
  - Mention daily special when showing menu
  - Confirm total before finalizing
  - Ask about dietary restrictions for food items
`

Tools

A tool is a single function that the AI can call to accomplish a specific task.

Anatomy of a Tool

import { LuaTool } from 'lua-cli';
import { z } from 'zod';

export default class GetWeatherTool implements LuaTool {
  // Unique identifier (lowercase, alphanumeric, hyphens, underscores)
  name = "get_weather";
  
  // Clear description of what the tool does
  description = "Get current weather conditions for any city";
  
  // Zod schema defining valid inputs
  inputSchema = z.object({
    city: z.string().describe("City name (e.g., 'London', 'Tokyo')"),
    units: z.enum(['metric', 'imperial']).optional().default('metric')
  });

  // Async function that implements the logic
  async execute(input: z.infer<typeof this.inputSchema>) {
    // input is automatically validated and typed
    const { city, units } = input;
    
    // Call weather API
    const weather = await fetchWeather(city, units);
    
    // Return structured data
    return {
      temperature: weather.temp,
      condition: weather.condition,
      city: weather.location
    };
  }
}

Tool Properties

name
string
required
Unique identifier using only: a-z, A-Z, 0-9, -, _Examples: get_weather, create-product, sendEmail123
description
string
required
Clear, concise description (1 sentence) of what the tool doesHelps the AI understand when to use this tool
inputSchema
ZodType
required
Zod schema that validates inputs at runtimeProvides automatic validation and TypeScript types
execute
function
required
Async function that implements the tool’s logic
async execute(input: any): Promise<any>
condition
function
Optional async function that determines if the tool should be available
async condition(): Promise<boolean>
Use for premium features, feature flags, channel-specific tools, or user-specific availability.Access the current channel via Lua.request.channel and raw webhook data via Lua.request.webhook?.payload - see Lua API.

Skills vs Tools

Single Function
// One specific thing
class GetWeatherTool {
  // Gets weather for a city
}

How It Works

1

User Request

User asks the AI: “What’s the weather in London?”
2

Tool Selection

AI reads the skill’s context and determines get_weather tool is appropriate
3

Input Validation

AI provides input: { city: "London" }Input is validated against inputSchema
4

Tool Execution

The execute function runs with validated inputCalls weather API and returns structured data
5

AI Response

AI uses the tool’s output to form a natural language response“The weather in London is 15°C and cloudy.”

Tool Naming Best Practices

Good Names

  • search_products
  • create_order
  • cancel_booking
  • get_user_profile

Bad Names

  • do_search (too generic)
  • process (unclear)
  • tool1 (not descriptive)
  • get data (spaces not allowed)

Creating Your Agent (v3.0.0)

In v3.0.0, you configure your entire agent using LuaAgent:
import { LuaAgent, LuaSkill } from 'lua-cli';

// Create your skill
const coffeeSkill = new LuaSkill({
  name: "coffee-shop-skill",
  description: "Coffee shop assistant",
  tools: [/* your tools */]
});

// Create agent (v3.0.0 pattern)
export const agent = new LuaAgent({
  name: "coffee-assistant",
  
  persona: `You are a friendly barista at Java Junction Coffee Shop.
  
Your role:
- Help customers browse the menu
- Take and confirm orders
- Suggest popular items
- Answer questions about ingredients

Communication style:
- Warm and welcoming
- Enthusiastic about coffee
- Patient and helpful
- Always mention daily specials`,

  
  skills: [coffeeSkill]
});
New in v3.0.0: Use LuaAgent to configure persona, welcome message, and skills together in one unified configuration.

Why LuaAgent?

The new LuaAgent pattern provides:
  • Single source of truth - All agent config in one place (code, not YAML)
  • Better organization - Clear separation of persona, skills, webhooks, jobs
  • Auto-sync - CLI auto-manages lua.skill.yaml (do not edit manually)
  • More features - Support for webhooks, jobs, preprocessors, postprocessors

Multiple Skills in One Project

You can organize tools into multiple skills and add them all to your agent:
import { LuaAgent, LuaSkill } from 'lua-cli';

// Product browsing skill
const catalogSkill = new LuaSkill({
  name: "product-catalog-skill",
  description: "Product browsing and search",
  tools: [
    new SearchProductsTool(),
    new GetProductTool()
  ]
});

// Shopping skill
const shoppingSkill = new LuaSkill({
  name: "shopping-skill",
  description: "Shopping cart management",
  tools: [
    new CreateBasketTool(),
    new AddItemTool()
  ]
});

// Order fulfillment skill
const orderSkill = new LuaSkill({
  name: "order-skill",
  description: "Order creation and tracking",
  tools: [
    new CreateOrderTool(),
    new TrackOrderTool()
  ]
});

// Create agent with all skills (v3.0.0)
export const agent = new LuaAgent({
  name: "ecommerce-assistant",
  persona: "You are a helpful e-commerce shopping assistant...",
  skills: [catalogSkill, shoppingSkill, orderSkill]
});

When to Use Multiple Skills

  • ✅ Tools serve different purposes (e.g., “HR Skill” vs “Sales Skill”)
  • ✅ Different teams own different skills
  • ✅ Skills have different deployment schedules
  • ✅ Skills need different permissions

Example Patterns

Pattern: CRUD Skill

const dataSkill = new LuaSkill({
  name: "data-management-skill",
  description: "Complete CRUD operations",
  tools: [
    new CreateTool(),
    new ReadTool(),
    new UpdateTool(),
    new DeleteTool(),
    new SearchTool()
  ]
});

Pattern: Workflow Skill

const checkoutSkill = new LuaSkill({
  name: "checkout-skill",
  description: "Complete purchase workflow",
  tools: [
    new CreateBasketTool(),    // Step 1: Create cart
    new AddItemsTool(),        // Step 2: Add items
    new ReviewCartTool(),      // Step 3: Review
    new ApplyDiscountTool(),   // Step 4: Apply discounts
    new ProcessPaymentTool()   // Step 5: Complete
  ]
});

Pattern: Integration Skill

const integrationSkill = new LuaSkill({
  name: "external-integrations-skill",
  description: "Third-party service integrations",
  tools: [
    new SendEmailTool(),      // SendGrid
    new ProcessPaymentTool(), // Stripe
    new GetWeatherTool(),     // Weather API
    new TrackShipmentTool()   // Shipping API
  ]
});

Next Steps