Ask an agent for a query, then run it yourself¶
Draft: not yet validated
The AI assistant that drafted this tutorial sent the request in step 1 twice in MESA JupyterLab on 2026-11-19 (OpenCode 1.19.4), with one command rather than in the OpenCode screen, and ran the code in steps 3 to 5 in a terminal there. Nobody has yet followed the page as a reader would. Tell us what you find.
An agent that runs its own query hands you a number. An agent that only drafts the query hands you something you can read first. The run, and the result, are yours.
You will: have the agent's query in a file beside your notebook, a result you ran yourself, and a note of what the query leaves out.
Time: 10 minutes. You need: to have finished Sign in and start an AI agent in a MESA app in this app session, and the notebook from Load a file from your Data Store into a notebook with its first cell run.
Steps¶
-
In the OpenCode screen, ask for a draft and nothing more:
Write one DuckDB SQL query that reads the file readings.csv (columns: gauge_id, date, value, flag) and returns the total of value for each gauge_id. Do not run it and do not use any tools. Reply with the SQL only.You should see: a query of a few lines and no tool calls. Yours may differ from the one below.
-
Before you run it, read it for three things: which file it reads, which rows it leaves out, and whether it changes anything.
You should see, for the draft below:
readings.csvin the folder it is run from; no rows left out, as there is noWHERE; and nothing changed, as it is a singleSELECT. -
In your notebook, paste the draft into a cell and save it to a file. Put first where it came from:
from pathlib import Path draft = """-- Drafted by an AI agent (OpenCode, gpt-oss-120b) on 2026-11-19. -- Not yet checked. SELECT gauge_id, SUM(value) AS total_value FROM read_csv_auto('readings.csv') GROUP BY gauge_id ORDER BY gauge_id; """ saved = Path("agent_total_by_gauge.sql").write_text(draft)You should see: no output, and
agent_total_by_gauge.sqlin the file browser. -
Run the query from the file:
import duckdb duckdb.sql(Path("agent_total_by_gauge.sql").read_text())You should see: one total for each gauge. The long decimals come from adding fractions; 390.8999999999999 is 390.9.
┌──────────┬────────────────────┐ │ gauge_id │ total_value │ │ varchar │ double │ ├──────────┼────────────────────┤ │ G01 │ 190.29999999999998 │ │ G02 │ 21.830000000000002 │ │ G03 │ 273.59999999999997 │ │ G04 │ 198.80000000000004 │ │ G05 │ 390.8999999999999 │ └──────────┴────────────────────┘ -
Compare it with a total you compute another way:
readings.groupby("gauge_id")["value"].sum()You should see: the same five totals. The query does what you asked.
gauge_id G01 190.30 G02 21.83 G03 273.60 G04 198.80 G05 390.90 Name: value, dtype: float64 -
In the file, replace
Not yet checked.with what you found and what the query leaves out.You should see: something like "Run and matched against pandas on 2026-11-19. A plain sum: it includes the readings flagged
S."
Check it worked¶
The folder holds agent_total_by_gauge.sql, whose first lines say who drafted it and
what you checked. You can say why G05's 390.9 is not yet a rainfall total: you asked
for a sum, the agent never saw the data, and so nothing in the draft knows about the
flagged 180 mm reading.
If it didn't¶
The agent ran the query, or called a tool. Nothing is harmed. Ask again, keeping the sentence that begins "Do not run it".
IO Error: No files found that match the pattern "readings.csv". The draft names
the file without a folder. Open the notebook from mesa-practice and run the cell
again.
Next¶
- Check an AI-suggested result against the data takes the 390.9 apart.
- Save a query so someone else can run it
- Read back what an agent ran confirms it called no tools.
- Reference: AI agents in the MESA apps.
Not yet validated by a person in MESA JupyterLab. Drafted with AI assistance on 2026-11-19; the request and the code were run there that day (pandas 3.1.1, DuckDB 2.0.0).
Machine-readable versions of this page: Markdown twin · raw source on GitHub · llms.txt · llms-full.txt (whole site). See For AI agents.