> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating Agents in Coreflux

> Add AI to Coreflux in minutes — talk to live data and put intelligence inside LoT automations, bringing AI to your solutions.

## Turn Your Broker Into a Teammate — and Your Automations Into Thinkers

Your devices, integrations, and databases already run on Coreflux — whether you monitor a factory, a solar site, a building portfolio, or a mobile fleet. **AI agents** live in LoT on that same broker: no separate AI platform, no copy-paste into another chat app.

**Talk with live data and automate with judgment.** Teams ask in plain language and get answers from what the broker sees *right now*. Your **Actions** already react to MQTT and timers; with agents they can also **reason** on a schedule or when an event fires — a status digest, a plain-language take on an alarm, a handover brief — all through `CALL AGENT` in LoT.

| What you gain | Example (any vertical) |
| - | - |
| **Ask the system, don't only chart it** | *"Which zones are offline?"* · *"What's output at site B?"* · *"Any inverters under target?"* |
| **Smarter automations, not more scripts** | A timer or topic wakes an agent; LoT publishes the result — no babysitting a workflow |
| **Reports while you sleep** | Hourly or daily digest on MQTT for supervisors, facility managers, or NOC staff |
| **Specialists, not one overloaded chatbot** | A guide for people, a reporter on a schedule, an analyst when alarms fire — each with its own job |

You define two things: a **`TYPE LLM` connector** (the model, the key, the price) and a **`DEFINE AGENT`** that uses it. The agent can do nothing until `ADD TOOL` grants a tool. Full options — grants, delegation, topics — are in [AI Connectors and Agents](https://docs.coreflux.org/latest/lot-language/routes/ai-routes.md).

> [!TIP]
>
> **Like a supervisor on the floor and an analyst on the line.** People get answers when they ask; your automations get judgment when something changes — all on the broker you already run.

***

## Ready-to-Use Use Cases (Copy & Deploy)

> [!NOTE]
>
> The full `DEFINE AGENT` reference lives in the **LoT AGENT** section: [Agents Overview](https://docs.coreflux.org/latest/lot-language/agents/overview.md), [Agent Syntax](https://docs.coreflux.org/latest/lot-language/agents/syntax.md), and [Agent Examples](https://docs.coreflux.org/latest/lot-language/agents/examples.md).

Each tab is a full recipe: an LLM connector, an agent, and an Action where the work is scheduled or triggered. Adapt names to your vertical — examples in the table.

| Use case | Who benefits | How it runs |
| - | - | - |
| **Talk with your data** | Operators, support, NOC | Ask on `agents/site/<session>/ask`, read `agents/site/<session>/response` |
| **Automatic report** | Supervisors, managers | Scheduled summary on `reports/operations/hourly` |
| **Alert triage** | On-call, maintenance | Each alert gets a short AI explanation |
| **Shift handover** | Shift leads, crews | Plain-language brief before the next rotation |

Some examples of use-cases for your industry:

| Vertical | Typical data topics | Automatic report might cover |
| - | - | - |
| **Manufacturing** | `production/`, `lines/`, `quality/` | Throughput, downtime, batch issues |
| **Solar & energy** | `solar/`, `inverters/`, `grid/` | Generation, underperformance, curtailment |
| **Smart buildings** | `buildings/`, `hvac/`, `occupancy/` | Comfort, energy, fault patterns |
| **Fleet & logistics** | `fleet/`, `vehicles/`, `connectors/` | Utilisation, delays, asset health |

### Before you start

* A **running broker** — [Installation](https://docs.coreflux.org/latest/quick-start/installation.md) and [Getting Started](https://docs.coreflux.org/latest/quick-start/getting-started.md) if you are new
* A **Growth or Enterprise** license. Community refuses `-addAgent`. See [Licensing](https://docs.coreflux.org/latest/mqtt-broker/licensing.md#plans)
* A **model provider** — OpenAI, Anthropic, an OpenAI-compatible gateway, or **local Ollama** on the broker host. Every recipe below uses **OpenAI**. Swap `PROVIDER`, `MODEL`, and the secret name for another provider (see [Picking a provider](https://docs.coreflux.org/latest/lot-language/routes/ai-routes.md#picking-a-provider))
* A **broker user** named in `DEFAULT_USER`. Each recipe uses `operator`. Create that user first (`-addUser operator …`). Tasks started by an Action run as this user, and the user must be allowed to do what the grants allow

Store an [OpenAI API key](https://platform.openai.com/api-keys) once:

```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
KEEP SECRET "OPENAI_API_KEY" WITH "sk-..."
```

Deploy the connector with `-addConnector` and the agent with `-addAgent` (LoT Editor, a LoT Notebook, or `$SYS/Coreflux/Command`). The agent does not show up under Connectors.

> [!NOTE]
>
> The **[HUB AI Assistant](https://docs.coreflux.org/hub/ai-assistant.md)** (Coreflux icon in the dock) is a separate helper. It can run inside the HUB, or as a broker agent the wizard installs. This guide is about **your** agents — the ones you write in LoT.

> [tab] Talk with your data
>
> **Outcome:** Anyone who can publish to the interaction topic can ask a question. The agent reads live MQTT under `telemetry/#` and can list what is loaded.
>
> ```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> DEFINE CONNECTOR SiteModel WITH TYPE LLM
>     ADD LLM_CONFIG
>         WITH PROVIDER "openai"
>         WITH MODEL "gpt-6-luna"
>         WITH API_KEY GET SECRET "OPENAI_API_KEY"
>         WITH API_SURFACE "auto"
>
> DEFINE AGENT SiteGuide
>     USES LLM CONNECTOR SiteModel
>     WITH DESCRIPTION "Answers questions about this site from live MQTT"
>     WITH DEFAULT_USER "operator"
>     WITH SYSTEM_PROMPT "You are a site operations guide. Use your tools to answer from live MQTT data. Be concise."
>     WITH INTERACTION_TOPIC "agents/site"
>     ADD TOOL "read_mqtt"
>         WITH TOPICS "telemetry/#"
>     ADD TOOL "read_lot"
> ```
>
> **1. Deploy and confirm**
>
> Add **SiteModel** as a connector and **SiteGuide** as an agent. `-listAgents` should show `SiteGuide` as `online`. Read `$SYS/Coreflux/Agents/SiteGuide/status` if it stays in `error` — usually the connector has not started, or `operator` does not exist.
>
> **2. Ask a real question**
>
> In MQTT Explorer or HUB [Data Viewer](https://docs.coreflux.org/hub/mqtt/data-viewer.md), publish to `agents/site/s1/ask` and subscribe to `agents/site/s1/response`. `s1` is the session. A later question on `s1` continues that conversation for the same user.
>
> ```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> Which sensors have been updated in the last few minutes?
> ```
>
> ```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> What is the latest data on telemetry/zone1/status?
> ```
>
> Rename `telemetry/` in the grant to `production/`, `solar/`, `buildings/`, or your own tree. A wildcard read shortens payloads over 1,024 characters. Reading the exact topic returns the whole payload.
>
> **3. Read the answer on response**
>
> `agents/site/s1/response` carries the agent's answer. Tool calls for that session appear on `$SYS/Coreflux/Agents/SiteGuide/task/s1/stream` when your user may subscribe to `$SYS`.
>
> > [!TIP]
> >
> > You just **talked with your data**. No extra AI server — the agent runs where your MQTT already lives.

> [tab] Automatic report
>
> **Outcome:** **LoT automation with AI** — on a schedule, an Action calls the agent and publishes an **operations summary** to MQTT. No chat window.
>
> ```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> DEFINE CONNECTOR SiteModel WITH TYPE LLM
>     ADD LLM_CONFIG
>         WITH PROVIDER "openai"
>         WITH MODEL "gpt-6-luna"
>         WITH API_KEY GET SECRET "OPENAI_API_KEY"
>         WITH API_SURFACE "auto"
>
> DEFINE AGENT OperationsReporter
>     USES LLM CONNECTOR SiteModel
>     WITH DESCRIPTION "Writes the hourly operations summary"
>     WITH DEFAULT_USER "operator"
>     WITH SYSTEM_PROMPT "You write operations reports from live MQTT. Use your tools on telemetry/ topics. Bullet points: current status, anomalies, items needing follow-up. Plain language for managers."
>     WITH MEMORY "none"
>     ADD TOOL "read_mqtt"
>         WITH TOPICS "telemetry/#"
>
> DEFINE ACTION HourlyOperationsReport
> ON EVERY 1 HOUR DO
>     CALL AGENT "OperationsReporter.execute"
>         WITH (task = "Hourly operations report: summarise key signals from telemetry/ topics, flag anything off-norm or stale, note follow-ups before the next review period.")
>         RETURN AS {report}
>     PUBLISH TOPIC "reports/operations/hourly" WITH {report}
> ```
>
> **1. Deploy the connector, the agent, and the Action**
>
> There is no interaction topic. Only the schedule triggers this agent. A successful `CALL AGENT` returns the answer text in `{report}`.
>
> **2. Subscribe to the report**
>
> Subscribe to `reports/operations/hourly` in MQTT Explorer, a dashboard, or the HUB Data Viewer.
>
> **3. See the first report**
>
> Publish sample payloads under your data tree (`telemetry/`, `solar/site1/power`, `buildings/tower/hvac`, and so on), then wait for the next run — or temporarily use `ON EVERY 30 SECONDS` and change it back when done.
>
> > [!TIP]
> >
> > **Scheduled insight on autopilot** — the report speaks your operation's language, not broker diagnostics.

> [tab] Alert triage
>
> **Outcome:** When something hits your alerts topic, the broker adds a **plain-language triage note** — what it might mean and what to check first.
>
> Works for any alert source: equipment faults, threshold breaches, connectivity, security events.
>
> ```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> DEFINE CONNECTOR SiteModel WITH TYPE LLM
>     ADD LLM_CONFIG
>         WITH PROVIDER "openai"
>         WITH MODEL "gpt-6-luna"
>         WITH API_KEY GET SECRET "OPENAI_API_KEY"
>         WITH API_SURFACE "auto"
>
> DEFINE AGENT AlertAnalyst
>     USES LLM CONNECTOR SiteModel
>     WITH DESCRIPTION "Explains one alert in three sentences"
>     WITH DEFAULT_USER "operator"
>     WITH SYSTEM_PROMPT "You triage operational alerts from MQTT. In 3 short sentences: what happened, likely cause, recommended first check. Be direct."
>     WITH MEMORY "none"
>     ADD TOOL "read_mqtt"
>         WITH TOPICS "alerts/#"
>
> DEFINE ACTION TriageAlert
> ON TOPIC "alerts/#" DO
>     CALL AGENT "AlertAnalyst.execute"
>         WITH (task = "Alert on topic " + TOPIC + ": " + PAYLOAD, session_id = TOPIC)
>         RETURN AS {triage}
>     PUBLISH TOPIC "agents/site/alerts/analysis" WITH {triage}
> ```
>
> **1. Wire your alerts**
>
> Ensure your existing logic still publishes under `alerts/` — for example `alerts/inverter/fault`, `alerts/building/leak`, or `alerts/line2/quality`.
>
> **2. Deploy triage**
>
> Add **AlertAnalyst** and **TriageAlert**. Subscribe to `agents/site/alerts/analysis`.
>
> **3. Trigger once**
>
> Publish a test alert to `alerts/test/manual` with any message. Read the analysis on the triage topic. `session_id` is the alert topic, so a repeat of the same topic continues that conversation. Drop `session_id` when every alert must stand alone — `MEMORY "none"` already does that.
>
> > [!TIP]
> >
> > On-call gets **context with the alarm**, not only a raw payload.

> [tab] Shift handover
>
> **Outcome:** Before each rotation, a **handover brief** lands on MQTT — what changed, what looks odd, what the incoming team should watch. Common in manufacturing, utilities, and 24/7 operations centers.
>
> ```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> DEFINE CONNECTOR SiteModel WITH TYPE LLM
>     ADD LLM_CONFIG
>         WITH PROVIDER "openai"
>         WITH MODEL "gpt-6-luna"
>         WITH API_KEY GET SECRET "OPENAI_API_KEY"
>         WITH API_SURFACE "auto"
>
> DEFINE AGENT HandoverBrief
>     USES LLM CONNECTOR SiteModel
>     WITH DESCRIPTION "Writes the shift handover"
>     WITH DEFAULT_USER "operator"
>     WITH SYSTEM_PROMPT "You write handover notes for operations teams. Bullet points: status, anomalies, open items. Max 8 bullets."
>     WITH MEMORY "none"
>     ADD TOOL "read_mqtt"
>         WITH TOPICS "telemetry/#, alerts/#"
>
> DEFINE ACTION ShiftHandover
> ON EVERY 8 HOURS DO
>     CALL AGENT "HandoverBrief.execute"
>         WITH (task = "Prepare handover for the next shift: current operational status, active alarms, and anything unusual in the last 8 hours.")
>         RETURN AS {brief}
>     PUBLISH TOPIC "agents/site/shift/handover" WITH {brief}
> ```
>
> **1. Deploy**
>
> Add **HandoverBrief** and **ShiftHandover**. Subscribe to `agents/site/shift/handover`.
>
> **2. Test faster**
>
> Temporarily use `ON EVERY 2 MINUTES`, read one brief, then restore `ON EVERY 8 HOURS` for production.
>
> > [!TIP]
> >
> > **Crew change becomes a story**, not a scramble through dashboards.

> [!TIP]
>
> **Starter pack:** **SiteGuide** + **HourlyOperationsReport** + **AlertAnalyst** — ask your deployment, get scheduled insight, enrich every alarm. They can share one `SiteModel` connector. Rename topic grants to `production/`, `solar/`, or `buildings/` when you copy the prompts.

***

## When You're Ready to Grow

You already have the building blocks: **chat** (`{INTERACTION_TOPIC}/<session>/ask`), **schedules** (`ON EVERY`), and **event-driven** (`ON TOPIC`) automations with `CALL AGENT`. Next is a writing grant (`ADD TOOL "write_mqtt"` with `WITH LEVEL "write"`), peers the agent may call (`WITH AGENTS`), and [MCP Connectors](https://docs.coreflux.org/latest/lot-language/routes/mcp-routes.md) called from Actions.

For several agents on one broker, see [Multi-agent deployments](https://docs.coreflux.org/latest/lot-language/agents/syntax.md#delegation-with-agents).

If you still have a `TYPE AGENT` connector from an earlier release, rewrite it before you upgrade. The broker skips those connectors at load. See [Coming from TYPE AGENT](https://docs.coreflux.org/latest/lot-language/agents/overview.md#coming-from-type-agent).

***

## Stay Safe While You Experiment

> [accordion] Try read-only first
>
> Grant only `read_mqtt` and `read_lot` until you trust the prompt. For one question, publish JSON `{ "text": "…", "mode": "insight" }` on the ask topic. Insight mode refuses every writing tool, including in agents this one calls. A default of insight mode on the agent itself is not available yet.

> [accordion] Keep API keys off the clipboard in LoT files
>
> Always use `GET SECRET "OPENAI_API_KEY"` on the `TYPE LLM` connector — never paste keys into definitions that get saved or shared.

> [accordion] Match the agent to the audience
>
> An interaction topic is for people. Timed Actions are for machines. Leave `INTERACTION_TOPIC` off agents that should only run in the background.

> [accordion] Say who the agent is
>
> `DEFAULT_USER` is required. Pick a user that can do the job, and grant `ADD TOOL` only the topics that job needs. A writing tool also needs `WITH LEVEL "write"`.

***

## What to Explore Next

> [card] [AI Connectors and Agents](https://docs.coreflux.org/latest/lot-language/routes/ai-routes.md)
>
> Providers, tool grants, delegation, topics, and the move off TYPE AGENT.

> [card] [Using AI with Coreflux](https://docs.coreflux.org/latest/quick-start/using-ai.md)
>
> Use MCP in your editor to write LoT faster — separate from agents running on the broker.


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