Documentation Index
Fetch the complete documentation index at: https://docs.heylua.ai/llms.txt
Use this file to discover all available pages before exploring further.
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
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:Option B: Email OTP (Semi Non-Interactive, 2 Steps)
If the user doesn’t have an API key yet: Step 1 - Request OTP:Workflow for AI Agents:
- Ask user if they have an API key
- If yes:
lua auth configure --api-key <key> - 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>
- Continue with
lua initonce authenticated
2. Initialization (lua init)
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
| Flag | Description |
|---|---|
--agent-id <id> | Use existing agent |
--agent-name <name> | Name for new agent |
--org-id <id> | Existing organization ID |
--org-name <name> | Create new organization |
--with-examples | Include example code |
--force | Override existing project |
Project Structure Created
3. Agent Configuration (LuaAgent)
The main configuration lives insrc/index.ts:
Key Properties
| Property | Required | Description |
|---|---|---|
name | Yes | Agent identifier |
persona | Yes | Personality, behavior, capabilities, limitations |
model | No | AI model to use — string like 'google/gemini-2.5-flash' or a function (request) => string for dynamic selection |
skills | Yes | Array of LuaSkill instances |
webhooks | No | HTTP endpoints for external events |
jobs | No | Scheduled cron tasks |
preProcessors | No | Message filters before agent processes |
postProcessors | No | Response formatters after agent responds |
mcpServers | No | External MCP tool servers (also auto-created via lua integrations) |
4. Building Components
Skills & Tools
A Skill is a collection of related tools:Webhooks
HTTP endpoints for external events:Jobs
Scheduled cron tasks:PreProcessors & PostProcessors
5. 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
executefunction - Fast - no network latency, no AI processing time
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)
| Mode | Description |
|---|---|
sandbox | Free, unbilled, can override local code without push/deploy |
production | Uses pushed and deployed versions |
Key Difference
| Command | What it does | AI involved? | Speed |
|---|---|---|---|
lua test | Runs execute function directly in VM | No | Fast |
lua chat | Full agent request with AI | Yes | Slower |
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.--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:
| Flag | Description |
|---|---|
-t, --thread [id] | Scope to a named thread. Omit the ID to auto-generate a UUID. Thread ID is printed at session start. |
--clear, --clear-thread | Clear the thread’s history when the session ends (interactive: on exit, non-interactive: after response). Requires --thread. |
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)
lua chat clear vs --thread:
| Approach | When to use |
|---|---|
lua chat clear --force | Reset all history before a new development session |
--thread <id> | Isolate individual test runs without touching other contexts |
--clear | Auto-clean up thread history at end of each automated test |
Recommended Development Workflow
6. Push vs Deploy
lua push - Upload Code to Server
- Compiles local code and uploads to Lua platform server/database
- Creates a version on the server
- Code now exists on server, not just locally
- Does NOT make it live yet
lua deploy - Activate a Version
- Makes a previously pushed version live/active
- Only 1 version can be active at a time per primitive
- This is what production uses
Key Difference
| Command | What it does |
|---|---|
lua push | Upload version to server (staging) |
lua deploy | Make that version live for all users |
7. Environment Variables
Sandbox vs Production
| Environment | Source |
|---|---|
| Sandbox | Local .env file or CLI env variables |
| Production | Stored on server (set via lua env production) |
Commands
8. Debugging with lua logs
This is the core debugging command. All
console.log, console.error, etc. output appears here.lua test, lua chat, production requests.
Log Types
| Type | Description |
|---|---|
all | All logs |
skill | Skill/tool executions |
job | Job executions |
webhook | Webhook executions |
preprocessor | PreProcessor executions |
postprocessor | PostProcessor executions |
user_message | User messages |
agent_response | Agent responses |
9. Sandbox Overrides
When usinglua chat -e sandbox, the following can be overridden with local compiled code without needing to push/deploy:
| Component | How it works |
|---|---|
| Skills | Local compiled code pushed to Redis cache |
| Persona | Local persona overrides deployed production persona |
| PreProcessors | Local code pushed to Redis cache |
| PostProcessors | Local code pushed to Redis cache |
| Environment | Local .env file used |
10. Compilation Gotchas
The CLI uses esbuild to bundle eachexecute function:
What Works
- Standard TypeScript code
- Imports from
package.jsondependencies - 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-cliimports are stripped - APIs likeUser,Products,Data,Agentsare sandbox globals
Warning Signs
| Issue | Meaning |
|---|---|
| Empty bundles (< 100 bytes) | Something went wrong during bundling |
| ”Could not resolve” errors | Check imports/dependencies |
| ”Transform failed” | TypeScript syntax issues |
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):| API | Description |
|---|---|
User | Per-user persistent storage — store onboarding state, preferences, workflow progress, or any custom data that persists across conversations |
Data | Custom data collections |
Products | Product catalog |
Baskets | Shopping cart |
Orders | Order management |
AI | AI generation |
Lua | Request context (Lua.request.channel, Lua.request.webhook) |
Jobs | Job scheduling |
Templates | Message templates |
CDN | File upload/retrieval |
BasketStatus | Enum for basket statuses (ACTIVE, CHECKED_OUT, ABANDONED, EXPIRED) |
OrderStatus | Enum for order statuses (PENDING, CONFIRMED, FULFILLED, CANCELLED) |
env(key) | Environment variable access |
process.env | Environment variables as an object (alternative to env()) |
fetch | HTTP requests |
console | Logging (appears in lua logs) |
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.- 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
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:
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
- 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
- Connect - Authenticate with the third-party service via OAuth or API token
- Auto-MCP - An MCP (Model Context Protocol) server is automatically created
- Instant Tools - Your agent can immediately use tools from that integration
- 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:- 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.- An event occurs in the connected service (e.g., a new Linear issue is created)
- Unified.to sends a webhook to your agent
- Your agent wakes up with the event data in
runtimeContext - 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:| Category | Examples |
|---|---|
| Task Management | Linear, Asana, Jira, Monday.com, ClickUp, Notion |
| Communication | Discord, Slack, Microsoft Teams, Telegram |
| Calendar | Google Calendar, Outlook Calendar, Calendly |
| CRM | HubSpot, Salesforce, Pipedrive, Zoho CRM |
| Development | GitHub, GitLab, Bitbucket |
| Storage | Google Drive, Dropbox, OneDrive, Box |
| Support | Zendesk, Intercom, Freshdesk |
| Gmail, Outlook, SendGrid |
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
13. Complete Workflow Example
Quick Reference: Non-Interactive Commands
| Task | Command |
|---|---|
| Authenticate with API key | lua auth configure --api-key <key> |
| Request email OTP | lua auth configure --email <email> |
| Verify email OTP | lua auth configure --email <email> --otp <code> |
| Initialize with existing agent | lua init --agent-id <id> |
| Initialize with new agent | lua init --agent-name <name> --org-id <id> |
| Test a tool | lua test skill --name <name> --input '<json>' |
| Test a webhook | lua test webhook --name <name> --input '<json>' |
| Test a job | lua test job --name <name> |
| Chat in sandbox | lua chat -e sandbox -m "<message>" |
| Chat in production | lua chat -e production -m "<message>" |
| Chat in isolated thread | lua chat -e sandbox -m "<message>" -t <thread-id> |
| Chat in auto-generated thread | lua chat -e sandbox -m "<message>" -t |
| Isolated test with auto-cleanup | lua chat -e sandbox -m "<message>" -t <id> --clear |
| Clear all conversation history | lua chat clear --force |
| Clear user’s history | lua chat clear --user <email|mobile|userId> --force |
| Clear specific thread history | lua chat clear --thread <thread-id> --force |
| View available integrations | lua integrations available |
| Get integration info (JSON) | lua integrations info <type> --json |
| List trigger events (JSON) | lua integrations webhooks events --integration <type> --json |
| Connect with triggers | lua integrations connect --integration <type> --auth-method oauth --scopes all --triggers <events> |
| Connect integration (OAuth) | lua integrations connect --integration <type> --auth-method oauth --scopes all |
| Connect integration (Token) | lua integrations connect --integration <type> --auth-method token |
| List connected integrations | lua integrations list |
| Update integration scopes | lua integrations update --integration <type> --scopes all |
| Disconnect integration | lua integrations disconnect --connection-id <id> |
| List triggers | lua integrations webhooks list |
| Create trigger | lua integrations webhooks create --connection <id> --object <type> --event <event> |
| Delete trigger | lua integrations webhooks delete --webhook-id <id> |
| List integration MCP status | lua integrations mcp list |
| Push all | lua push all --force |
| Push and deploy | lua push all --force --auto-deploy |
| Deploy specific version | lua deploy skill --name <name> --set-version <ver> --force |
| Set env variable | lua env <sandbox|production> -k <key> -v <value> |
| View logs | lua logs --type <type> --name <name> --limit <n> |
Related Documentation
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

