> ## 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.

# LuaAgent

> Agent configuration class with name, persona, model, model settings, and the primitive arrays the compiler bundles

`LuaAgent` is the object your project exports from `src/index.ts`: it names the [agent](https://docs.heylua.ai/concepts/agents.md), holds its [persona](https://docs.heylua.ai/concepts/persona.md) and [model](https://docs.heylua.ai/concepts/models.md), and registers every primitive the compiler bundles. `lua compile` looks for `new LuaAgent({ … })` in `index.ts`, `src/index.ts`, `agent.ts`, `src/agent.ts`, `main.ts`, then `src/main.ts`, and compiles only the primitives referenced from that object's arrays. Pass the config as an object literal directly to the constructor; a config held in a variable isn't traversed, so its primitives aren't compiled.

*Verified against lua-cli 3.33.0.*

```ts theme={null}
import { LuaAgent } from 'lua-cli';
```

## Quick example

```ts src/index.ts theme={null}
import { LuaAgent } from 'lua-cli';
import ordersSkill from './skills/orders.skill';
import dailyDigest from './jobs/DailyDigestJob';
import orderPaid from './webhooks/OrderPaidWebhook';

export default new LuaAgent({
  name: 'shop-assistant',
  description: 'Answers order, delivery, and returns questions for Acme customers.',
  persona: 'You are the Acme support agent. Be concise and confirm order numbers before acting.',
  model: 'openai/gpt-5.4',
  modelSettings: { temperature: 0.2, reasoning: { effort: 'low' } },
  skills: [ordersSkill],
  jobs: [dailyDigest],
  webhooks: [orderPaid],
});
```

`lua push agent` uploads this configuration; the primitives in the arrays are pushed with their own `lua push <type>` commands or together with `lua push all`.

## Constructor

```ts theme={null}
new LuaAgent(config: LuaAgentConfig)
```

The constructor throws when:

* `persona` is an object with none of `base`, `voice`, `text`: `Agent persona object must have at least one of: base, voice, text`
* `modelSettings.temperature` is outside 0 to 2: `Agent modelSettings.temperature must be between 0 and 2`
* `modelSettings.topP` is outside 0 to 1: `Agent modelSettings.topP must be between 0 and 1`
* `modelSettings.maxOutputTokens` is less than 1: `Agent modelSettings.maxOutputTokens must be >= 1`
* `temperature`, `topP`, `topK`, `maxOutputTokens`, `presencePenalty`, `frequencyPenalty`, or `seed` is not a finite number: `Agent modelSettings.<key> must be a finite number`
* `modelSettings.stopSequences` is not an array of strings: `Agent modelSettings.stopSequences must be a string array`
* `modelSettings.reasoning` is not an object, its `effort` is not one of the six values, or its `show` is not a boolean: `Agent modelSettings.reasoning must be an object`, `Agent modelSettings.reasoning.effort must be one of: off, minimal, low, medium, high, max`, `Agent modelSettings.reasoning.show must be a boolean`

`name` and a string `persona` are not validated; `lua compile` warns `Agent should have a persona` when the persona is empty.

## Configuration

Fields of `LuaAgentConfig`, in declaration order.

**name** `string` *required*

Agent name shown in the compiled manifest and in CLI output. The platform identifies the agent by the `agentId` in `lua.skill.yaml`, not by this name.

**description** `string`

Summary of what the agent can do, read by a [Space](https://docs.heylua.ai/concepts/spaces.md) when deciding whether to route a request to this agent. The persona owns tone and behavior. Omit it to leave any description set in the admin dashboard untouched; set `''` to clear it on the next `lua push agent`.

**persona** `PersonaText` *required*

The prompt text that defines who the agent is and how it behaves. A string, or `{ base?, voice?, text? }` where `base` is rendered on every channel, `voice` is appended in voice sessions, and `text` is appended on text channels. An object needs at least one key.

**model** `LuaAgentModel`

A [model code](https://docs.heylua.ai/concepts/models.md) such as `'openai/gpt-5.4'` (list them with `lua models list`), or a model resolver `(request: LuaRequest) => string | Promise<string>` that runs on every request with every runtime object available. Omit it to use the platform default model.

```ts theme={null}
model: async (request) => (request.channel === 'whatsapp' ? 'openai/gpt-5.4-mini' : 'openai/gpt-5.4'),
```

**modelSettings** `AgentModelSettings`

Sampling settings sent with every model call. A key left out keeps the provider's default. `reasoning` is the agent-level default; a per-request override wins.

**keys**

**temperature** `number`

0 to 2.

**topP** `number`

0 to 1. Set either `temperature` or `topP`, not both.

**topK** `number`

Top-K sampling. Provider support varies.

**maxOutputTokens** `number`

At least 1.

**presencePenalty** `number`

-2 to 2 where the provider supports it. The range is not checked at construction.

**frequencyPenalty** `number`

-2 to 2 where the provider supports it. The range is not checked at construction.

**stopSequences** `string[]`

Generation stops when the model emits one of them.

**seed** `number`

Deterministic sampling where the provider supports it.

**reasoning** `\{ effort?: 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'max'; show?: boolean \}`

Default reasoning effort and whether the reasoning trace is returned. `show` defaults to `true`. An effort the resolved model doesn't support is mapped to its nearest tier.

**skills** `LuaSkill[]` (default: \[])

[Skills](https://docs.heylua.ai/reference/sdk/luaskill.md) and, through them, tools.

**webhooks** `LuaWebhook[]` (default: \[])

[Webhooks](https://docs.heylua.ai/reference/sdk/luawebhook.md).

**triggers** `LuaTrigger[]` (default: \[])

[Triggers](https://docs.heylua.ai/reference/sdk/luatrigger.md).

**jobs** `LuaJob[]` (default: \[])

[Jobs](https://docs.heylua.ai/reference/sdk/luajob.md).

**workflows** `LuaWorkflow[]` (default: \[])

[Workflows](https://docs.heylua.ai/reference/sdk/workflow-builder.md) built with `createWorkflow` or `defineWorkflow`. Tools referenced by a workflow's tool steps are compiled through this array too.

**preProcessors** `PreProcessor[]` (default: \[])

[Preprocessors](https://docs.heylua.ai/reference/sdk/preprocessor.md), run before a message reaches the model.

**postProcessors** `PostProcessor[]` (default: \[])

[Postprocessors](https://docs.heylua.ai/reference/sdk/postprocessor.md), run on the reply before it is sent.

**mcpServers** `LuaMCPServer[]` (default: \[])

[MCP servers](https://docs.heylua.ai/reference/sdk/luamcpserver.md).

**devices** `LuaDevice[]` (default: \[])

[Devices](https://docs.heylua.ai/reference/sdk/device-definition.md).

**deviceTriggers** `LuaDeviceTrigger[]` (default: \[])

Standalone [device triggers](https://docs.heylua.ai/reference/sdk/device-definition.md).

**voices** `LuaVoice[]`

[Voices](https://docs.heylua.ai/reference/sdk/voice.md) the agent can answer with. A channel picks one in its channel configuration; without a binding the first entry is used.

**batching** `BatchingConfig`

Message batching for this agent. A key left out falls back to the platform default.

**keys**

**firstMessageDelayMs** `number`

How long to hold the first message so rapid follow-ups join the same batch. `0` disables the hold.

**debounceWindowMs** `number`

Window for collecting further messages while a turn is in flight. `0` disables batching. The window slides: each new message restarts it, so the reply goes out `debounceWindowMs` after the person's last message. Pair a large value with `maxWaitMs`.

**maxWaitMs** `number`

The longest a batch is held, in milliseconds, counted from the message that started it. The batch goes out after the quiet period or this cap, whichever comes first, so a person who keeps typing still gets a reply. Absent or `0` means no cap. It caps the debounce wait only, not the wait for a turn already running under `serializeProcessing`. lua-cli 3.47.0 or later.

**maxBatchMessages** `number`

Maximum messages in one batch.

**serializeProcessing** `boolean` (default: false)

When `true`, a message arriving mid-turn waits for the current turn instead of aborting it. No effect when `debounceWindowMs` is `0`.

**governance** `GovernanceConfig`

[Governance](https://docs.heylua.ai/concepts/governance.md) policy for tool calls, preprocessors, and postprocessors. The credential for `'api'` mode is read from the `GOVERNANCE_API_KEY` environment variable, never from this object.

**keys**

**mode** `'sdk' | 'api'` *required*

`'sdk'` enforces `preset`, `injection`, and `rules` in the runtime; `'api'` defers to the server at `serverUrl`.

**preset** `'security'`

Named baseline rule set, layered under `rules`.

**injection** `\{ threshold: number; ml?: boolean; mlThreshold?: number \}`

Prompt-injection scan on inputs. `ml: true` adds the platform's classifier with its own `mlThreshold`.

**rules** `\{ blockTools?: string[]; requireToolApproval?: string[]; tokenBudget?: number \}`

Tool names to block, tool names that need human approval, and a token budget. `requireApproval` is a deprecated spelling of `requireToolApproval`.

**serverUrl** `string`

Enforcement server for `'api'` mode.

**browser** `boolean | BrowserSwitchConfig`

Browser tools and the [`Browser`](https://docs.heylua.ai/reference/sdk/browser) runtime object for the agent, off by default. `true` turns them on with platform defaults; an object adds policy. Attaching a browser with `browsers` also turns them on.

**keys**

**engine** `'auto' | 'browser-use' | 'agent-browser'`

`'auto'` (default) uses the user's desktop browser when it is online and the Lua cloud browser otherwise; a page the Lua cloud browser can't get past (a captcha, a bot block, or an empty page) is retried once on Browser-Use, unless `fallback` is `'none'` or `allowedDomains` is set. `'agent-browser'` uses the same two, never Browser-Use; `'browser-use'` uses only Browser-Use. Jobs, webhooks, triggers, web routes, and workflow steps always use the Lua cloud browser.

**fallback** `'browser-use' | 'none'`

`'browser-use'` (default) retries a page the Lua cloud browser can't get past on Browser-Use; `'none'` keeps every page on the Lua cloud browser.

**proxyCountry** `string`

Two-letter country code, such as `'gb'`, for the country Browser-Use browses from. Applies only to work on Browser-Use.

**allowedDomains** `string[]`

Hosts the browser may open, checked before every command that opens a URL. On the Lua cloud browser it also applies to redirects and everything a page loads. Setting it turns off the Browser-Use retry.

**confirmActions** `string[]`

Actions that must be approved before they run: `navigate`, `click`, `fill`, `type`, `select`, `press`, `scroll`, or `submit`. See [`confirmActions`](https://docs.heylua.ai/reference/sdk/browser#configuration).

**logContent** `'summary' | 'full' | 'none'`

How much page content browser log rows keep. Default `'summary'`.

**screenshots** `'always' | 'onError' | 'never'`

When a browser log row carries a screenshot reference. Default `'onError'`. On the Lua cloud browser a screenshot is not stored, so its log rows carry no reference.

**maxSessionMinutes** `number`

Lua cloud browser session length in whole minutes. Default 10, maximum 60; a larger value is cut to 60 when the session opens.

**idleTimeoutSeconds** `number`

How long a Lua cloud browser session may go without a command, in whole seconds. Default 120, maximum 900; a larger value is cut to 900 when the session opens.

**maxConcurrentSessions** `number`

How many Lua cloud browser sessions this agent may have open at once for one person. Default 3, at most 10, and your plan may allow fewer. One session too many fails with `BROWSER_SESSION_LIMIT`.

**maxDownloadMb** `number`

Turns on [downloads, PDFs and uploads](https://docs.heylua.ai/reference/sdk/browser.md#files) and caps each file, in whole megabytes from 1 to 500, lowered to your plan's limit. Off when unset.

**allowedMimeTypes** `string[]`

The types a download may have, such as `['application/pdf', 'image/*']`, up to 50 entries. Read from the file's own bytes. Empty or unset allows any type.

**allowScripts** `boolean`

Lets your own code run [page scripts](https://docs.heylua.ai/reference/sdk/browser.md#page-scripts) with `Browser.eval`. Off by default, and it needs an `allowedDomains` list naming at least one real domain. The chat model and `Browser.execute` never run scripts.

**credentials** `string[]`

Accepted and stored, not enforced yet. To sign the browser in, use a [saved login](https://docs.heylua.ai/reference/sdk/browser.md#saved-logins).

**browsers** `LuaBrowser[]`

[Named browsers](https://docs.heylua.ai/reference/sdk/luabrowser.md), each with its own settings. A call picks one with `browser: '<name>'`. Attaching at least one turns the browser on, so `browser: true` is not needed. Calls without a name use the `browser` settings when `browser` is set, and the first entry here when it isn't. [`LuaBrowser`](https://docs.heylua.ai/reference/sdk/luabrowser) takes the same keys as `browser` plus `name` and `description`; `persist` and `credentials` are stored and not enforced yet. A limit over its maximum, or `allowScripts: true` with no real domain in `allowedDomains`, fails `lua compile`. Push them with `lua push browser` or `lua push all`.

```ts theme={null}
import { LuaAgent, LuaBrowser } from 'lua-cli';

const supplierPortal = new LuaBrowser({ name: 'supplier-portal', allowedDomains: ['ikea.com'], fallback: 'none' });

export default new LuaAgent({
  name: 'stock-checker',
  persona: 'You check stock levels for the store team.',
  browsers: [supplierPortal],
});
```

## Methods

Read-only getters that return what was passed to the constructor.

| Method | Returns |
| - | - |
| `getName()` | `string` |
| `getDescription()` | `string \| undefined` |
| `getBrowser()` | `boolean \| BrowserSwitchConfig \| undefined` |
| `getBrowsers()` | `LuaBrowser[] \| undefined` |
| `getPersona()` | `PersonaText` |
| `getModel()` | `LuaAgentModel \| undefined` |
| `getModelSettings()` | `AgentModelSettings \| undefined` |
| `getSkills()`, `getWebhooks()`, `getTriggers()`, `getJobs()`, `getWorkflows()`, `getPreProcessors()`, `getPostProcessors()`, `getMCPServers()`, `getDevices()` | The registered array, `[]` when unset |
| `getBatching()` | `BatchingConfig \| undefined` |
| `getVoices()` | `LuaVoice[] \| undefined` |

There is no getter for `deviceTriggers` or `governance`.

## Types

`LuaAgentConfig`, `LuaAgentModel`, `PersonaText`, `AgentModelSettings`, `LuaRequest`, `BrowserSwitchConfig`, and `LuaBrowserConfig` are exported types. `BatchingConfig` and `GovernanceConfig` are declared inline; derive them from the config type.

```ts theme={null}
import type { LuaAgentConfig, LuaAgentModel, PersonaText, AgentModelSettings, BrowserSwitchConfig } from 'lua-cli';

type BatchingConfig = NonNullable<LuaAgentConfig['batching']>;
type GovernanceConfig = NonNullable<LuaAgentConfig['governance']>;
```

## See also

* [About agents](https://docs.heylua.ai/concepts/agents.md)
* [About persona](https://docs.heylua.ai/concepts/persona.md)
* [About models](https://docs.heylua.ai/concepts/models.md)
* [lua push](https://docs.heylua.ai/reference/cli/push.md)
* [LuaSkill](https://docs.heylua.ai/reference/sdk/luaskill.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.