Luau Bindings — ai
The
require("ai")script API — talk to the configured AI provider(s) from a script. Two calls: a multi-turnai.askand a one-shotai.askSimple. These are the same bindings the console?helper and theaichat client sit on. For providers, per-use-type configuration, and the tool-use / MCP design, see the AI subsystem reference. Every function is[antos].
local ai = require("ai")
print(ai.askSimple("Summarise this log in one line: " .. text))
Functions
| Function | Behaviour |
|---|---|
ai.ask(history, overrides) |
Send a multi-turn message history and get the model's reply. history is an array of { role = "user"\|"assistant"\|"system", content = "…" }. Returns reply, err — reply is the model's text; with tools enabled a third value carries any tool call (see AI subsystem). |
ai.askSimple(prompt, overrides) |
One-shot convenience — wraps a single user prompt and returns the reply text. |
overrides (optional in both) selects and tunes the request without touching global config:
| Field | Meaning |
|---|---|
provider / model |
override the configured provider / model for this call |
use_type |
pick a configured use-type profile (e.g. "chat", "code", "summarise") |
temperature, max_tokens, … |
standard generation parameters |
tools |
a tool list (from mcp.tools) to enable tool use for this call |
The exact override set and the provider/use-type configuration are documented in AI subsystem.
Multi-turn example
local ai = require("ai")
local history = {
{ role = "system", content = "You are a terse assistant." },
{ role = "user", content = "What's the capital of France?" },
}
local reply, err = ai.ask(history)
print(reply)
Tool use (with MCP)
Pass tools from an mcp connection in overrides.tools, and ai.ask runs the tool-use loop for you — the model may call tools, the results are fed back, and you get the final reply. The tool-use loop and MCP integration are described in AI subsystem → Tool use and MCP.
local ai, mcp = require("ai"), require("mcp")
local conn = mcp.connect_named("weather")
local reply = ai.ask(
{ { role = "user", content = "Is it raining in Rochdale?" } },
{ tools = mcp.tools(conn) }
)
print(reply)
Related
- AI subsystem (providers, configuration, tool-use design — the library reference)
- luau_mcp (the MCP client, usable with or without AI) · AntOS Libraries