Docs / agent
An in-kernel conversational agent. Natural language in, verified SQL and result sets out — with a review flow for anything that writes.
The Agent is a JavaScript runtime inside the ShannonBase server, packaged as a MySQL stored procedure. You talk to it in natural language; it inspects your schema, runs read-only queries, builds plans, and only writes when you approve.
sys.shannon_chat is a procedure, so it is
called with CALL, not SELECT. Configuration
travels in the @chat_options session variable.
SET @chat_options = JSON_OBJECT(
'conversation_id', UUID(),
'model_options', JSON_OBJECT(
'provider', 'deepseek',
'model_id', 'deepseek-v4-pro',
'api_key', 'sk-...'));
CALL sys.shannon_chat('Which databases are on this instance?');
The answer comes back as a single-column result set named
response.
The agent is multi-turn. Keep conversation_id the same and
history carries over.
conversation_id — the agent auto-continues the last conversation on this connection"new" — force a fresh sessionhistory_length to control how many prior turns feed the prompt (default 5)-- first turn
SET @chat_options = JSON_OBJECT(
'conversation_id', UUID(),
'model_options', JSON_OBJECT('provider', 'deepseek',
'model_id', 'deepseek-v4-pro',
'api_key', 'sk-...'));
CALL sys.shannon_chat('What columns does orders have?');
-- follow-up: same connection, no conversation_id -> continues
CALL sys.shannon_chat('Now find orders over 1000 in the last 7 days'); Each call runs through a 4-level dispatcher that resolves which agent function executes:
@shannon_agent_plugin session variable pointing at a functionmysql.shannon_agent_plugins, by priorityshannon_agent() function in the current databasesys.shannon_agent_default() fallbackOnce dispatched, the built-in agent picks one of four routes:
Eleven tools are available to the loop. The model emits them as JSON
({"thought":"...","tool":"query_db","args":{...}}) and the
runtime validates and executes them.
query_db — read-only SQL (SELECT/SHOW/DESC/EXPLAIN/WITH); write statements are rejectedexplain_sql — EXPLAIN FORMAT=JSON plan with full-table-scan warningsplan_sql — an ordered list of read-only SQL steps (max 15)list_tables — list tables in the current database, optional keyword filterdescribe_table — full column definitions plus foreign keys for 1–8 tablesml_rag — retrieve relevant context via vector searchgenerate_text — raw LLM text generationbegin_tx — start a transaction with a lease in mysql.agent_tx_leaseupdate_data — INSERT/UPDATE/DELETE/REPLACE inside an active transaction; UPDATE/DELETE must have a WHERE clausecommit_tx / rollback_tx — finish or abandon the transaction
Write and risky operations are gated by a review state machine. Enable it
with review_mode='review' in @chat_options.
Read-only statements stay automatic via
auto_execute_read_only=true.
SET @chat_options = JSON_OBJECT(
'conversation_id', UUID(),
'model_options', JSON_OBJECT('provider', 'deepseek',
'model_id', 'deepseek-v4-pro',
'api_key', 'sk-...'),
'review_mode', 'review',
'require_approval_for_write', true);
CALL sys.shannon_chat('Set all failed orders from the last 7 days to review'); When a step needs approval the agent pauses and returns a prompt with the plan ID, the SQL, the affected table, and a risk level. You reply with one of:
Approve — continue with the stepReject — cancel the planModify:SQL — replace the pending SQL with your corrected versionSteps are claimed with compare-and-swap, so a concurrent approve/reject/modify from another session cannot race the decision.
begin_tx registers a lease; a stuck transaction is auto-rolled back in a finally block, and expired leases are cleaned up
Everything the agent does lands in tables under mysql., so
you get a full audit trail out of the box:
agent_sql_trace — every SQL execution with turn number and result previewagent_review_plan / agent_review_history — approval plans and actionsagent_memory — conversation memory with vector embeddingsagent_tx_lease — transaction leasesshannon_agent_plugins — the plugin registry model_options selects the LLM. Providers are the same set as
ML_GENERATE: deepseek, dashscope,
qianfan, openai, ollama, and
local onnx. Alongside provider /
model_id / api_key you get
temperature, max_tokens, top_p,
deepseek_thinking, reasoning_effort, and
language.
rag_options points the ml_rag tool at your
vector stores: vector_store, n_citations,
distance_metric (COSINE | DOT | EUCLIDEAN | L2), and
embed_model_id. If omitted, RAG falls back to the legacy
top-level retrieve_top_k / tables keys.
SET @chat_options = JSON_OBJECT(
'conversation_id', UUID(),
'model_options', JSON_OBJECT('provider', 'deepseek',
'model_id', 'deepseek-v4-pro',
'api_key', 'sk-...'),
'rag_options', JSON_OBJECT(
'vector_store', JSON_ARRAY('mydb.product_docs'),
'n_citations', 8,
'distance_metric', 'COSINE'));
CALL sys.shannon_chat('How does ShannonBase MVCC actually work?'); The dispatcher makes it possible to drop in your own agent as a JavaScript function. Management procedures cover the lifecycle:
sys.shannon_agent_register_plugin(name, schema, func, priority, desc, @result)sys.shannon_agent_unregister_plugin(name, @result)sys.shannon_agent_toggle_plugin(name, enabled, @result)sys.shannon_agent_list_plugins()