Skip to main content

Purpose

This guide is specifically designed for AI Agents and AI Coding IDEs (Cursor, Windsurf, GitHub Copilot, etc.) to build agents on the Lua platform using non-interactive CLI commands. All commands in this guide use flags and arguments that work without interactive prompts, enabling full automation.

Prerequisites

  • Node.js 18+ installed
  • npm, yarn, or pnpm
  • Lua CLI installed: npm install -g lua-cli
  • Authentication configured (see below)

High-Level Workflow

After lua init, the CLI surfaces a suggested build loop: compile → test → chat (sandbox) → push and deploy. Treat that sequence as your default checklist before iterating on agent code. Once the agent has release history, prefer lua version create + lua version promote as your release step instead of lua deploy — see §7 for the full distinction.

1. Authentication (PREREQUISITE)

Must authenticate before running any other CLI command.

Option A: API Key (Fully Non-Interactive)

If the user already has an API key:
This validates and saves the API key immediately.

Option B: Email OTP (Semi Non-Interactive, 2 Steps)

If the user doesn’t have an API key yet: Step 1 - Request OTP:
This sends a 6-digit OTP to the email. Step 2 - Verify OTP (user provides the code they received):
This verifies the OTP and generates + saves an API key.

Workflow for AI Agents:

  1. Ask user if they have an API key
  2. If yes: lua auth configure --api-key <key>
  3. If no:
    • Get user’s email
    • Run lua auth configure --email <email>
    • Ask user for the OTP they received via email
    • Run lua auth configure --email <email> --otp <code>
  4. Continue with lua init once authenticated

2. Initialization (lua init)

Run lua init only ONCE per project. After initialization, you have your agent and codebase - work on it from there.

Two Modes

New Agent (--agent-name)

Creates a brand new agent from scratch:

Existing Agent (--agent-id)

Links to an agent that already exists:
Important limitation: Existing code/primitives on the server CANNOT be pulled down to local codebase. Bundling is one-way only (local → server). Use this mode to start fresh development on an existing agent.

Non-Interactive Flags

Project Structure Created


3. Debugging with lua logs (read this BEFORE you write tools)

This section is promoted to the top because every AI builder needs the post-deploy loop in their head before they write a single tool. All console.log, console.error, etc. output from your tool code shows up in lua logs. The CLI also prints a ✨ Tip: line at the end of every push/deploy/chat/sync/compile/test pointing at the right lua logs --type X --limit N command for what you just ran. Follow it.
The single canonical post-deploy loop is:
For the full canonical guide, see Debugging your agent — the post-deploy loop.

The “post-test-always-check” pattern

After every lua chat -m "test", immediately run:
If the count is zero, the test passed cleanly. If non-zero, fix the error before running another test message — most pipeline errors (billing, validation, LLM provider failures) don’t surface in the chat response itself. The CLI helps by running a quiet agent_error probe automatically after every lua chat turn — when new errors fire, you’ll see:
Set LUA_NO_HINTS=1 to silence all post-action hints.

Post-deploy verification recipe

After deploying, always run this 3-line check:
If step 3 returns entries timestamped after your deploy, don’t walk away — read them and decide whether to roll back.
Important: lua logs returns zero results right after deploy until something executes. Generate traffic first, for example:
Then inspect:

lua logs quick reference

Filter types


4. Agent Configuration (LuaAgent)

The main configuration lives in src/index.ts:

Key Properties


5. Building Components

Skills & Tools

A Skill is a collection of related tools:
A Tool is a single function the AI can call:

Webhooks

HTTP endpoints for external events:

Jobs

Scheduled cron tasks:

PreProcessors & PostProcessors


6. Testing Strategy

This is one of the most important sections. Understanding when to use lua test vs lua chat is critical.

lua test - Isolated Component Testing

Purpose: Unit test for individual blocks (tools, jobs, webhooks, processors) How it works:
  • Creates a local VM and executes code directly
  • No AI involved - just runs the execute function
  • Fast - no network latency, no AI processing time
Use for: Quick testing, quick debugging, building components in isolation Input format: Must match the tool’s inputSchema exactly

lua chat - Live Agent Testing

Purpose: Real agent requests involving AI How it works:
  • HTTP requests for streaming/generating responses
  • Full integration - multiple components may execute (skills, tools, pre/post-processors)
Two modes:

Key Difference

Thread Isolation for Testing

Recommended for AI agents running automated tests. Use --thread to scope each chat session to an isolated conversation context. This prevents test state from leaking between runs — no need to call lua chat clear between tests.
Each --thread creates a completely independent conversation context. This also means multiple tests can run concurrently (5-10 at a time) without interfering with each other.
--thread flags:

Concurrent Testing

Because each --thread is a fully isolated conversation, you can run multiple lua chat invocations in parallel without any state collision. This is especially useful for AI agents that need to validate multiple conversation scenarios at once:

Clearing Conversation History (lua chat clear)

When to use lua chat clear vs --thread:

7. Push, Deploy, and Agent Versions

Understanding this distinction is critical. Many users — and AI agents following this guide — confuse these commands.
There are three commands involved in getting code live, and they do three different things:

lua push - Upload Code to Server

  • Compiles local code and uploads to Lua platform server/database
  • Mints a new immutable version of that one primitive
  • Code now exists on server, not just locally
  • Activates nothing. Does NOT make it live yet.
  • lua version create snapshots the latest pushed version of every primitive (skills, webhooks, jobs, processors, triggers, persona, voice, MCP config, model) into a single agent version.
  • lua version promote <N> atomically activates that snapshot — every primitive switches at once, with no window where some are old and some are new.
  • This is the recommended way to ship a release, especially when a change touches more than one primitive.
See the Version Command page for the full command set, including lua version status (shows what’s pushed but not yet live), lua version diff, and lua version list.

lua deploy - Legacy Single-Primitive Activation

  • Makes a previously pushed version of one primitive live/active.
  • Still fully supported, and still the fastest path for a one-off, single-primitive fix.
  • Behavior depends on the agent’s history:
    • If the agent has promoted at least one agent version already, lua deploy performs a scoped promote: it creates and promotes a new agent version identical to the current one except for the primitive you just deployed. The change is live immediately, and it still appears in lua version list (tagged with a deploy … message) — so agent-version history stays consistent even when you use the legacy command.
    • If the agent has never created or promoted an agent version, lua deploy activates the primitive directly, as before.

Key Difference

After lua push without --auto-deploy, code is staged, not live. The CLI says so explicitly — for example:
Use lua push … --auto-deploy, run lua deploy explicitly, or run lua version create + lua version promote before validating in production.
Execution guarantee: once lua deploy or lua version promote reports success, that exact code serves the very next invocation of the agent (allow up to roughly a minute for edge caches to catch up globally). Sandbox testing (lua chat, lua test) never touches what’s live, and deactivating a primitive (e.g. a webhook) stops it serving immediately regardless of version history.

8. Environment Variables

Sandbox vs Production

Commands

Set environment variables as needed when code requires them.

9. Sandbox Overrides

When using lua chat -e sandbox, the following can be overridden with local compiled code without needing to push/deploy: This allows testing changes instantly without the push/deploy cycle.

10. Compilation Gotchas

The CLI uses esbuild to bundle each execute function:

What Works

  • Standard TypeScript code
  • Imports from package.json dependencies
  • Relative imports within your project

What May Not Work

  • Not all Node.js file structures are supported
  • Each execute function’s code is extracted and bundled separately
  • lua-cli imports are stripped - APIs like User, Products, Data, Agents are sandbox globals

Warning Signs

Debug Mode

Run with --debug for verbose compilation output:

11. Platform APIs Available at Runtime

These are available as globals in the VM sandbox (don’t import from lua-cli):

User: Per-User Persistent Storage

Critical for AI agents building stateful workflows. The User API is the primary way to maintain state across conversations. It is a schemaless, persistent key-value store scoped to each end-user — not just a profile reader.
Any property you set on the user object persists forever (across conversations, sessions, days, months) until you explicitly change it. This makes it the go-to primitive for:
  • Onboarding flows — track user.onboardingStep, user.completedSteps
  • Multi-step workflows — accumulate data across tool calls with user.collectedData
  • Session state — store user.lastIntent, user.pendingAction
  • User preferences — persist user.theme, user.language, user.notificationSettings
State machine pattern — use user.onboardingStep (or any field) to track where the user is in a multi-step flow, then resume from that point in any future conversation:
See the full User API reference for all methods (update(), save(), send(), clear()).

12. Third-Party Integrations (POWERFUL FEATURE)

This is one of the most powerful features of the Lua platform. With a single command, you can give your agent access to 250+ third-party services (Linear, Discord, Google Calendar, HubSpot, Slack, GitHub, and more) - without writing any code.

Why This Matters

Instead of:
  • Writing API integration code
  • Managing OAuth tokens and refresh logic
  • Building tools for each third-party service
  • Handling rate limits and error handling
You simply run:
And your agent instantly gets:
  • Tools like linear_create_issue, linear_list_projects, linear_update_task, etc.
  • Triggers that wake up your agent when events occur (e.g., when a new issue is created)

How It Works

  1. Connect - Authenticate with the third-party service via OAuth or API token
  2. Auto-MCP - An MCP (Model Context Protocol) server is automatically created
  3. Instant Tools - Your agent can immediately use tools from that integration
  4. Triggers - Optionally enable triggers to wake up your agent on events

Discovery Commands (For AI Agents)

Before connecting, use discovery commands to understand what’s available:
JSON output is especially useful for AI coding assistants to programmatically discover:
  • Available OAuth scopes with friendly descriptions
  • Available trigger events with friendly descriptions
  • Webhook types (native vs virtual)

Connecting an Integration

Triggers: Event-Driven Agent Wake-Up

Triggers are one of the easiest ways to make your agent reactive. When enabled, your agent automatically wakes up when events occur in connected services.
What happens when a trigger fires:
  1. An event occurs in the connected service (e.g., a new Linear issue is created)
  2. Unified.to sends a webhook to your agent
  3. Your agent wakes up with the event data in runtimeContext
  4. The agent can respond based on what happened

Testing Integration Tools

After connecting, test immediately. Use --thread to keep each test isolated:

Available Integrations (250+)

Common integrations include: Run lua integrations available to see all available integrations for your workspace.

Managing MCP Servers for Integrations

Each integration creates an MCP server. You can manage them:

Integration Workflow Example

Key Points for AI Agents

Important for AI coding assistants building Lua agents:
  1. Use discovery commands to understand what’s available:
    • lua integrations available - list integrations
    • lua integrations info <type> --json - get scopes and triggers
    • lua integrations webhooks events --integration <type> --json - get trigger events
  2. Enable triggers during connection for event-driven workflows:
    • --triggers task_task.created,task_task.updated - specific triggers
    • --triggers all - all available triggers
  3. Connect integrations before writing custom tool code - the integration might already provide what’s needed
  4. Test with lua chat after connecting to verify tools are available
  5. One connection per integration type per agent - use update to change scopes

13. Complete Workflow Example


Quick Reference: Non-Interactive Commands


Debugging Loop

Canonical post-deploy debug loop and the active agent_error probe

CLI Commands Reference

Complete CLI command documentation

Non-Interactive Mode

All non-interactive flags and CI/CD examples

Integrations Command

Connect 250+ third-party services

LuaAgent API

Complete LuaAgent configuration reference

Platform APIs

User, Data, Products, and other runtime APIs

MCP Servers

Manage MCP servers for external tools

Version Command

Atomic agent versions, promote, rollback, and version status