# AI assistant (/docs/guides/assistant)



The assistant is optional AI help built into the console. It is available to roles with the
`assistant.use` permission (editor, admin and owner by default; see
[Permissions](/docs/reference/permissions)) and it never acts beyond what the signed-in person
may do.

## Turn it on [#turn-it-on]

The assistant is off until the API has a model. Set these environment variables:

| Variable                          | Default | Meaning                                                                                 |
| --------------------------------- | ------- | --------------------------------------------------------------------------------------- |
| `ASSISTANT_MODEL`                 | empty   | The model as `provider/model`, for example `openai/gpt-4o-mini`. Empty disables the AI. |
| `ASSISTANT_API_KEY`               | empty   | The provider key. If empty, `OPENAI_API_KEY` is used.                                   |
| `ASSISTANT_RATE_LIMIT_PER_MINUTE` | `10`    | Requests per person per minute, across the chat and every assistant action.             |

This build only knows the `openai` provider; any other prefix is rejected. Without a model, the AI
features answer `AI_DISABLED`. Only the dead-rule scan keeps working (see below).

## Chat [#chat]

Open **Chat** in the sidebar to ask about your decisions, executions and tables. The chat calls the
same tools as the [MCP server](/docs/integrate/mcp), but through your session, so each call is
authorised and audited as if you had made it by hand. A tool the platform refuses to you comes back
to the assistant as an error.

* **Widgets.** Lists are shown as tables (up to 50 rows, 6 columns), single records as cards, and
  anything else as JSON. The assistant adds a short reading instead of repeating them.
* **Approval.** Read-only tools run on their own. A tool that changes something stops and asks you
  to **Approve** or **Deny**. Validating, simulating, backtesting, running tests, executing a
  decision and the assistant's own suggestions do not need approval.
* **History.** Conversations are private to you and the project. Reopen or delete them from
  **History**.
* **Language.** Answers follow the console language (English or Spanish).

### Attach files [#attach-files]

Use **Attach files** to give the assistant data to work with. Files are turned into text on upload
and sent with your message.

| Limit     | Value                                     |
| --------- | ----------------------------------------- |
| Types     | `md`, `txt`, `csv`, `json`, `pdf`, `xlsx` |
| Size      | 5 MB per file                             |
| Count     | Up to 3 per message                       |
| Text kept | The first 100,000 characters of each file |

PDFs are text-extracted, so a scanned PDF with no text is refused. Spreadsheets become one table
per sheet. The assistant treats a file as data, never as instructions.

## Help while you build [#help-while-you-build]

The same assistant is available in the flow builder (**AI assistant** button). Nothing is applied
without your confirmation.

| Action         | What it does                                                                                                                                                                                 |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Generate**   | Turns a description into a draft (models and graph) plus the problems publishing would report. **Apply to draft** replaces the models and graph; nothing is saved until you save or publish. |
| **Explain**    | Describes in plain language what the saved draft decides, from its graph and referenced tables.                                                                                              |
| **Test cases** | Proposes up to 10 inputs. The expected outcome comes from running the engine, so an added case passes.                                                                                       |
| **Dead rules** | Finds table rules that can never fire (never true, or shadowed by an earlier rule) and nodes no path reaches.                                                                                |

Generated drafts may only reference tables and decisions that have a published version in the
active project. Dead-rule detection is deterministic; the AI only writes the optional summary, so
the findings are returned even with no model configured.

Fields that take a formula or text also have **Write with AI**. Describe what you need and the
assistant writes a condition, arithmetic, template, text or SQL using only the fields in scope.
Formulas are parsed before they are shown, and an invalid one is flagged.

## Explain an execution [#explain-an-execution]

On an execution, **Explain with AI** answers "why this outcome?". It reads the recorded trace and the
decision tables the flow ran, so it can say which rule matched or why none did. The API takes a
`style`:

| Style       | For                                                          |
| ----------- | ------------------------------------------------------------ |
| `friendly`  | The default. End users who do not program.                   |
| `technical` | Authors and support: keeps node, rule and expression detail. |

The console's dialog uses the default style.

## API [#api]

All routes need a session and a project, and share the rate limit above.

| Route                                      | Purpose                               |
| ------------------------------------------ | ------------------------------------- |
| `POST /api/v1/assistant/decision-draft`    | Generate a draft                      |
| `POST /api/v1/assistant/explain`           | Explain a decision                    |
| `POST /api/v1/assistant/explain-execution` | Explain an execution                  |
| `POST /api/v1/assistant/test-cases`        | Suggest test cases                    |
| `POST /api/v1/assistant/dead-rules`        | Find dead rules                       |
| `POST /api/v1/assistant/formula`           | Write a formula or text               |
| `POST /api/v1/chat`                        | Send a chat message (streamed events) |

Every assistant route is read-only: it returns a suggestion and writes nothing.
