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 |
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 |
Clearing Conversation History (lua chat clear)
Important for testing! The agent has memory/conversation history. When testing, you often want a fresh state. Use
lua chat clear to reset the AI’s memory.- Before testing a new feature or flow
- When the agent’s context is polluted from previous tests
- When debugging unexpected behavior that might be context-related
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,Dataare 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 | User data management |
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 |
env(key) | Environment variable access |
fetch | HTTP requests |
console | Logging (appears in lua logs) |
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
linear_create_issue, linear_list_projects, linear_update_task, etc.
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
- Event-Driven - Optionally subscribe to webhooks to react to events
Connecting an Integration
Testing Integration Tools
After connecting, test immediately: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.
Event-Driven Workflows with Webhooks
You can subscribe to events from connected integrations: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>" |
| Clear conversation history | lua chat clear --force |
| Clear user’s history | lua chat clear --user <email|mobile|userId> --force |
| View available integrations | lua integrations available |
| 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 integration webhooks | lua integrations webhooks list |
| Create integration webhook | lua integrations webhooks create --connection <id> --object <type> --event <event> --webhook <url> |
| Delete integration webhook | 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> --skill-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

