The AI notebook agent
funcionalAI cells that plan, build, investigate and review with labelled evidence, budgets and consent, and the things the agent can never do.
Uma IA cell asks SQLly's notebook agent a question about the notebook: why a query failed, how to investigate a number, whether a join double-counts. The agent reads the notebook, can run a few read-only queries within a budget you can see, and answers with findings that each say what they rest on. It never edits the notebook directly: everything it wants to change is a proposal you accept or reject.
AI cells use the AI provider you set up for the rest of SQLly. A local model (Ollama, MLX) runs straight away; a cloud model asks first and shows exactly what it will send (see below).
Modos
Add an AI cell, type a question ("Ask about this notebook: explain, plan, build, investigate or review…"), pick a mode and press Executar.
| Modo | O que faz | Can query | Default budget |
|---|---|---|---|
| Assist | Explain an error, complete or fix SQL, suggest a chart or read a plan. Proposes cells and edits. | Sim | 3 queries, 1,000 rows, 30 s of query time, 8 turns |
| Plano | Writes an investigation plan for you to review: goal, steps, sources, assumptions, cost and safety concerns, permissions needed. Nothing runs. | Não | No queries, 8 turns |
| Montar | Turns the request (or an approved plan) into proposed cells, edits and runs. | Não | No queries, 8 turns |
| Investigate | Runs a few read-only queries, iterates, and reports findings with evidence. Can propose cells and runs. | Sim | 8 queries, 5,000 rows, 60 s, 12 turns |
| Revisão | SQLly's own checks run first, then the model reviews the SQL and can propose edits. | Sim | 4 queries, 2,000 rows, 60 s, 12 turns |
| Explain changes | Says what changed between two points, and why: SQL, settings, parameters, connection or sign-in, an input cell, or the data. By default it compares with the last time the AI cell read each cell; two pickers ("Compare the last time this cell ran / the run of …" and "with now / the run of …") compare any two runs from the notebook's run history, or a past run with now. | Não | No queries, 8 turns |
Every mode also has a 40,000-token budget. In Plano, the answer becomes a reviewable plan with "Nothing runs until you approve." and Approve and build, which switches the cell to Build with the plan attached.


A failed SQL cell offers Explain with AI under its error: it adds an Assist cell below, aimed at the failed cell, and runs it. Explain Last Error on a notebook tab does the same for the notebook's failed cell. Plan cells have an Explain with AI button too, which asks which steps of the plan cost the most, why, and what would make the query faster.


Findings and evidence
Every finding is labelled:
- Observed fact
- Something a result shows directly.
- Derived metric
- A number worked out from results.
- Hypothesis
- A possible explanation, not proven.
- Recommendation
- Something to do next.
Each finding links to its evidence: a cell and the run it read ("by_country · run 3f2a…"), or a query the agent ran ("query q1"). SQLly, not the model, decides whether a finding is verified. It is marked Unverified, with the reason, when nothing was run, it cites no evidence, it cites a result the agent didn't read, the value it quotes isn't in its evidence, or it rests on sampled or partial data (or a query cut at its row limit). Two findings that give different values for the same thing are both kept and marked "Contradicted by …". The same labels appear in exported reports.


Review: SQLly's checks first
In Review mode, before the model sees anything, SQLly checks each query itself and shows the results as "SQLly check: …": totals inflated by a join that repeats rows (a fanout join, such as SUM(o.Freight) across orders joined to order lines, confirmed from the cell's own results when the join key repeats), COUNT(*) over joins, SUM ou AVG de DISTINCT, out-of-date or reused results, sampled or partial data, cells that skip a filter the rest of the notebook applies, server-clock functions such as GETDATE() e NOW(), cells allowed to change data, and sensitive-looking columns.


Proposals you approve
- Proposals are listed under the answer: "Insert 3 cells after by_country", "Edit orders" (with a line diff), "Run by_country".
- Accept ou Reject each one.
- Apply accepted (2) applies them as one group. New cells start read-only and carry an IA badge ("from investigate_freight"); they're ordinary cells you can edit. Accepted runs go through the normal run path and its checks.
- Undo AI changes reverses the whole group in one step.
The agent can propose every kind of cell it can describe, including plan and entity detail cells. Each proposal is checked again when you apply it. Anything that would change data, edit a cell that's allowed to change data, edit the AI cell itself, move a cell somewhere else to run (onto local data or another connection: "Refused: the new settings would change where orders runs. Only you can do that."), or doesn't fit the cell kind's settings is shown as "Refused by SQLly" with the reason. A proposal that changes a cell's settings, not just its SQL, shows those settings changes in its diff.


Budgets
The cell's Budget meter shows queries, rows, query time, tokens and turns used against their limits ("Queries 2 of 8"). Limits are checked before each step; a query's row limit is cut to what's left, and once a budget is spent the agent is told to finish. Parar ends a run at any time. Run again reruns the cell; Run All passes over AI cells without starting a model.
To see what a cloud run costs, type your provider's prices in Settings ▸ AI on the cloud profile: Price per 1,000 input tokens (USD) e Price per 1,000 output tokens (USD). They're optional, and SQLly never looks them up. With prices set, the meter shows "Estimated cost $0.04", or "Cost $0.04 of $0.50" when the cell has a cost cap (max_cost_usd in the cell's budget, up to $100), and the run stops at the cap ("Stopped: the cost cap was reached"). Without prices, a cell with a cap says "Cost cap $0.50 not applied: set this provider's prices in Settings → AI". Local models have no price.




Cloud models and consent
With a cloud model, the first run in a notebook stops at "Share this notebook's context with …?" and shows exactly what the first request will send (your request, the instructions, the notebook outline, the cell it's about, SQLly's check results), how many rows and queries the agent's tools may add later, and a Never sent list: connection credentials and anything that looks like a password, key or token, the values of sensitive parameters, and the values of sensitive-looking columns (also when the query renames them with an alias). Nothing leaves your computer until you press Share and run. That consent is kept for this notebook and provider on this computer only, never in the file.


What the agent can never do
- Write. There is no tool that changes data, and every query it runs must be a SELECT for that connection's engine, on a read-only session.
- Export or reach the network. There is no export, send or HTTP tool; a request for one is answered "Unknown tool".
- Pick its own connections. It can query only the notebook's connections that your trust allows (and that the production read lock doesn't block), whatever text in a cell or a result says.
- Gain permissions from your data. What it may do comes from SQLly's own code and your trust, never from text it reads. Cell text, errors, column names and sample rows reach the model fenced off as data, with invisible characters removed and the fence markers defused, which makes it harder for planted text to steer the model, but can't rule it out. That's why findings carry evidence SQLly checks, and every change waits for your approval.
- Change the notebook behind your back. Every change is a proposal, checked again when applied, and undoable.
Each run is recorded in a local action log (SQLLY/notebooks/ai/, readable only by you): the mode, provider and model, the tools it was offered, each tool call and query with hashes of its arguments and results, the budget used, and your approvals. Prompts and data are not written, only their hashes.
Limites
- The agent can read through production connections, as SQLly's other AI features can, unless the production read lock is on. It can never write to them.
- Token counts, and so costs, are estimates. A cost cap is set in the cell's settings in the file; there's no field for it in the cell yet.
- Undo AI changes is kept for the tab's session; it doesn't survive a restart.
- The run pickers in Explain changes list the runs the History tab loads (the newest 200).
- The action log isn't shown in the app yet.
- The fanout check relies on key names (
id,CustomerID,customer_id) and qualified columns; the ambiguous-term check knows English terms only. - AI cells run in the desktop app only.