Agents
Define, deploy, and run Lunnoa agents with @lunnoa/client.
Use @lunnoa/client to build agents as code and run them from your own apps. You author a typed definition, deploy it into the workspace, then open chat tasks over the Public API. Lunnoa owns runtime, authorisation, connections, and audit logging so engineers can focus on the agent’s behaviour.
Coding agents (Cursor, Claude Code, and similar) can drive this flow with the packaged skills. See For agents.
Goal
By the end of this guide you will:
- Define an agent with
defineAgent, or as JSON inlunnoa/ - Save it with the CLI (
pushfor JSON,agents deployfor TypeScript) - Run a chat turn with
agentChat.streamMessage
Requirements
- Node.js 20 or newer
- A Lunnoa Automate deployment URL
- A workspace API key (
lna_…) with permission to manage and use agents in the workspace - An AI connection already configured in Automate (deploy does not create connections)
1. Define the agent locally
defineAgent is pure typed config. Nothing is written to the platform until you push a JSON file or agents deploy a TypeScript file. JSON is the two-way path with the UI. See Sync with the UI.
{
"$schema": "../../node_modules/@lunnoa/client/schemas/agent.schema.json",
"kind": "agent",
"slug": "greeter",
"name": "Greeter",
"description": "Replies with one short sentence.",
"model": "deepseek-ai/DeepSeek-V4-Pro",
"instructions": { "file": "greeter.instructions.md" },
"settings": { "suggestedPrompts": ["Say hello"] }
}The JSON file is what you commit under lunnoa/agents/. Its prompt is greeter.instructions.md in the same folder. Field rules, including which keys a push clears and which it leaves alone: Sync with the UI. A TypeScript file is for a definition that needs code. Deploying it locks the agent in the UI.
Upsert identity is the workspace-scoped slug. The slug is unique in the workspace. Nested defineWorkflow tools are supported: deploy creates those workflows first, then links them via workflowIds. Full factory table: Define locally.
Set model to a models[].id from npx @lunnoa/client ai-connections list --json. Pass defineAiConnection({ id }) for the connection that accepts that model. Omitting aiConnection does not assign one. Credentials stay on Lunnoa; never put secrets in the definition file.
The JSON file can set more than this TypeScript example. The reference is split into three pages:
| Page | What it covers |
|---|---|
| The agent file | Identity, instructions, model, profile image, canvas, and what cannot live in the file |
| Capabilities | Tools, workflows, sub-agents, connections, knowledge, variables, objects, MCP, A2A, skills, drive, and shares |
| Runtime settings | The settings object |
A TypeScript defineAgent does not write those extra fields. A later agents deploy leaves them as they are. Use the JSON file when you need them.
2. Deploy into Automate
Prefer the CLI. A TypeScript file sets codeSource to generated. The agent appears in the UI with the badge Managed by code, and the UI will not edit it. A JSON file in lunnoa/agents/ is pushed instead, sets codeSource to synced, and can be edited in the UI. codeSource replaces managedByCode on agents and workflows. See Sync with the UI.
npx @lunnoa/client agents deploy ./agents/support-triage.ts \
--url https://lunnoa.your-company.example \
--api-key "$LUNNOA_API_KEY"Flags and env fallbacks: --url / LUNNOA_URL and --api-key / LUNNOA_API_KEY. The workspace comes from the API key. Optional lunnoa.config.ts in the working directory can supply the same values.
For TypeScript definition files, run under Node with --experimental-strip-types (Node 22+) or use tsx.
Details and catalogue discovery: CLI. JSON round-trip: Sync with the UI.
3. Run the agent (chat)
After deploy, resolve the agent id (Automate UI, agents.list, or codegen) and stream a turn. A task is one conversation thread. Client-generated UUIDs are fine; the first message creates the task.
// `lunnoa` is the signed-in user client. See Authentication.
const agentId = process.env.AGENT_ID!;
const taskId = crypto.randomUUID();
const stream = await lunnoa.agentChat.streamMessage(
agentId,
taskId,
'Summarise open tickets for customer ACME.',
);
for await (const chunk of stream) {
if (chunk.type === 'text-delta') process.stdout.write(chunk.delta);
}
// History (UIMessage format)
const task = await lunnoa.tasks.get(taskId, { expansion: ['messages'] });For React UIs, prefer useAgentChat from @lunnoa/client/react. Resume and stop helpers, chunk types, and proxy notes: Agent chat.
With deployment codegen you can call agents by generated name (for example lunnoa.agents.supportTriage.streamMessage(...)). See Codegen.
What Lunnoa handles for you
| Concern | Platform behaviour |
|---|---|
| Runtime | Model calls, tool rounds, and streaming run on Automate |
| Authorisation | API keys / JWTs and RBAC decide who may deploy, list, and chat |
| Connections | Secrets and app credentials stay in workspace connections |
| Logging and audit | Chat turns and tool use are persisted on the deployment |
| Reuse | Catalogue actions and connections are shared across agents and workflows |
Your job is the agent definition, tools, and the product UI. Lunnoa is the control plane.
Auth
Chat from an app runs as the signed-in Lunnoa user, so agent shares and task history are theirs. Use createBrowserClient.
Deploy from the CLI uses the workspace API key (--api-key / LUNNOA_API_KEY). That key is not the app's login. Never ship an API key to the browser. Full detail: Authentication and API authentication.
Related
| Guide | When |
|---|---|
| For agents | Cursor / Claude skills and playbook |
| The agent file | JSON identity, image, canvas, and exclusions |
| Capabilities | Tools, links, skills, drive, and shares |
| Runtime settings | Every settings key |
| Define locally | defineAgent / defineWorkflow / defineAction |
| CLI | Discover tools, then upsert by slug |
| Sync with the UI | pull, push, and status for JSON definitions |
| Agent chat | SSE streaming depth |
| Workflows | Trigger and wait on workflow runs |
| API reference | Full Public API operation list |