Replies: 2 comments
|
db_explainQuery can break the Phase 1 read-only promise: on Postgres, EXPLAIN ANALYZE executes the statement, so analyzing an UPDATE or DELETE the model drafted changes data, and analyzing the slow SELECT runs it in full against the live connection. I'd let the tool run ANALYZE only on a read-only session inside a transaction it always rolls back, and the same shape carries Phase 2: run the approved statement without auto-commit, show the affected row count, and leave the commit to the human. |
|
Good catch, and you're right that Phase 1 can't rest on the tool list alone — that was a gap in the proposal as written. To answer directly: the agent's session should be opened read-only at the driver level for these calls, not just restricted by which tools are exposed. On top of that, For Phase 2, reusing that shape (no-autocommit, show affected row count, human clicks to commit) makes sense — one safety mechanism across both phases instead of two different ones to reason about. I'll fold this into the proposal: Phase 1 = driver-level read-only session + rollback-wrapped EXPLAIN ANALYZE, not tool-list-only gating. Thanks for flagging it before any code existed to carry the bug forward. Drafted with Claude Code (autonomous mode, human-reviewed before posting) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
From chatbot to agent: extending
org.jkiss.dbeaver.model.aiwith a bounded tool-use loopWhile working on #42155 and #42157 (the two small bugs blocking Ollama/local-LLM use via the existing
openaiengine, tied to #36951), I read throughorg.jkiss.dbeaver.model.aiclosely enough to see what it already does well and where its ceiling is. Posting this as an idea rather than a PR, since it's a design/scope question before it's code.What exists today
A schema-scoped chat.
AIDatabaseScope/AIDatabaseContextrestrict the model's view to selected DB objects, and the model can call one function tool —db_listTableNames— against the live connection. Two provider engines (openai-compatible,copilot). The model answers questions and drafts SQL; a human copies, reviews, and runs it.The gap
It's Q&A. It can't look at why a query is slow, check whether an index would help, inspect what's actually in a table, or verify its own suggestion against the live database before handing it to the user — every one of those needs a second round-trip through a human. That's the gap between "chatbot that talks about your database" and "agent that works on it."
The proposal
Add a bounded plan → act → observe → reflect loop on top of the existing chat infrastructure, driven by a larger set of read-only (and, later, explicitly gated write) database tools. Not a new product or a new provider engine — an extension of the same
AIDatabaseScope/function-tool mechanism that's already there.New tools (read-only first)
Alongside
db_listTableNames:db_getTableDDL— fullCREATE TABLEfor a table: columns, types, constraintsdb_getIndexes— existing indexes, with selectivity/cardinality where the driver exposes itdb_explainQuery— runEXPLAIN/EXPLAIN ANALYZE(dialect-aware), return the plandb_sampleData—LIMIT Nsample rows, respecting the existing scope restrictiondb_getTableStats— row count, table size, last-analyzed time where availableAll read-only queries DBeaver already knows how to run through its existing driver abstraction (
DBPDataSource/DBCSession) — wiring, not new database-access code.The loop
Instead of one prompt → one answer, the agent gets a capped iteration budget (configurable, default ~5):
Concretely, for "why is this query slow": call
db_explainQuery, see a seq scan, calldb_getIndexeson that table, then answer with the diagnosis and the evidence — not a guess.Safety boundary — read vs. write
The part that most needs maintainer input before any code:
db_executeStatementtool for DDL/DML would need an explicit human-approval gate per call — a diff/preview requiring a click, not a settings toggle that silently allows it. DBeaver already has transaction/commit UI conventions worth reusing here rather than inventing new ones.Why this fits DBeaver specifically
AIDatabaseScope) that already limits blast radius.Suggested phasing
db_getTableDDL,db_getIndexes,db_sampleData,db_getTableStatsas read-only tools in the existing single-shot chat (no loop yet) — low risk, useful on their own, easy to review.db_explainQueryplus the plan/act/observe/reflect loop, capped, read-only tools only.db_executeStatement— a product/UX decision as much as an engineering one.Open questions
org.jkiss.dbeaver.model.aihave appetite for a multi-step loop at all, or is "single-shot with more tools" (step 1 only) the right stopping point?AIDatabaseScopealready does?Drafted with Claude Code (autonomous mode, human-reviewed before posting); the idea follows directly from reading the existing AI module while working on #42155/#42157.
Update (2026-10-19)
Checked for any overlap since posting: #42231 ("Optional ScreenContextAgent context for explaining a query error") is the only other open item mentioning "agent" — it's about pulling in external screen-capture context, unrelated to this proposal.
A couple of additions worth folding in here:
db_getTableDDL,db_getIndexes,db_sampleData,db_getTableStats,db_explainQuery) is read-only; only the phase-2 write tool needs the approval-gate design work.(Closing a duplicate discussion I opened separately before finding this one — consolidating here.)
All reactions