SQLite Agent is a cross-platform SQLite extension that brings autonomous AI agents to your database. It enables databases to run multi-step, tool-using agents that fetch data from external sources (web, APIs, etc.) through sqlite-mcp and populate database tables. The extracted data can then be analyzed by LLMs, displayed in UIs, or used in applications.
- Autonomous Agents – Run AI agents that can plan and execute multi-step tasks
- MCP Integration – Works with sqlite-mcp for external tool access
- AI Powered – Uses sqlite-ai for LLM inference and embeddings
- Table Extraction Mode – Automatically fetch and populate database tables
- Auto-Embeddings – Optionally uses sqlite-vector to generate vector embeddings automatically when inserting data for BLOB columns named
*_embedding - Auto-Vector Indexing – Initialize vector search indices automatically
Download the appropriate pre-built binary for your platform from the Releases page: we do support Linux, macOS, Windows, Android and iOS.
You can add this repository as a package dependency to your Swift project. After adding the package, you'll need to set up SQLite with extension loading by following steps 4 and 5 of this guide.
Here's an example of how to use the package:
import agent
...
var db: OpaquePointer?
sqlite3_open(":memory:", &db)
sqlite3_enable_load_extension(db, 1)
var errMsg: UnsafeMutablePointer<Int8>? = nil
sqlite3_load_extension(db, agent.path, nil, &errMsg)
var stmt: OpaquePointer?
sqlite3_prepare_v2(db, "SELECT agent_version()", -1, &stmt, nil)
defer { sqlite3_finalize(stmt) }
sqlite3_step(stmt)
log("agent_version(): \(String(cString: sqlite3_column_text(stmt, 0)))")
sqlite3_close(db)Add the following to your Gradle dependencies:
implementation 'ai.sqlite:agent:0.1.3'Here's an example of how to use the package:
SQLiteCustomExtension agentExtension = new SQLiteCustomExtension(getApplicationInfo().nativeLibraryDir + "/agent", null);
SQLiteDatabaseConfiguration config = new SQLiteDatabaseConfiguration(
getCacheDir().getPath() + "/agent_test.db",
SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.OPEN_READWRITE,
Collections.emptyList(),
Collections.emptyList(),
Collections.singletonList(agentExtension)
);
SQLiteDatabase db = SQLiteDatabase.openDatabase(config, null, null);Note: Additional settings and configuration are required for a complete setup. For full implementation details, see the complete Android example.
-- Load required extensions
SELECT load_extension('./dist/mcp');
SELECT load_extension('./dist/ai');
SELECT load_extension('./dist/agent');
-- Initialize AI model
SELECT llm_model_load('/path/to/model.gguf', 'gpu_layers=99');
-- Connect to MCP server
SELECT mcp_connect('http://localhost:8000/mcp');
-- Run an autonomous agent (text-only mode)
SELECT agent_run('Find affordable apartments in Rome with AC', 8);
-- Agent uses MCP tools to accomplish the task and returns result| Function | Description |
|---|---|
agent_version() |
Returns extension version |
agent_run(goal, [table_name], [max_iterations], [system_prompt]) |
Run autonomous AI agent |
See API.md for complete API documentation with examples.
This example demonstrates combining agent, MCP, AI, and vector extensions:
-- Load all extensions
.load ../sqlite-mcp/dist/mcp
.load ./dist/agent
.load ../sqlite-ai/dist/ai
.load ../sqlite-vector/dist/vector
-- Initialize AI model (one-time)
SELECT llm_model_load('/path/to/model.gguf', 'gpu_layers=99');
-- Connect to MCP server (one-time)
SELECT mcp_connect('http://localhost:8000/mcp');
-- Create table with embedding column
CREATE TABLE listings (
id INTEGER PRIMARY KEY,
title TEXT,
description TEXT,
location TEXT,
property_type TEXT,
amenities TEXT,
price REAL,
rating REAL,
embedding BLOB
);
-- Run agent to fetch and populate data
-- Embeddings and vector index are created automatically!
SELECT agent_run(
'Find affordable apartments in Rome under 100 EUR per night',
'listings',
8
);
-- Returns: 5 (number of rows inserted)
-- Semantic search (works immediately!)
SELECT title, location, price, v.distance
FROM vector_full_scan('listings', 'embedding',
llm_embed_generate('cozy modern apartment', ''), 5) v
JOIN listings l ON l.rowid = v.rowid
ORDER BY v.distance ASC;Run the full demo:
make airbnb #first place a .gguf model inside the models folder and run your AirBnb MCP serverSee USAGE.md for complete usage examples.
The agent operates through an iterative loop:
- Receives goal and available tools from MCP
- Decides which tool to call
- Executes tool via sqlite-mcp extension
- Receives tool result
- Continues until goal achieved or max iterations reached
- Returns final result
- sqlite-mcp – Model Context Protocol client for SQLite
- sqlite-ai – AI/ML inference and embeddings for SQLite
- sqlite-vector – Vector search capabilities for SQLite
- sqlite-sync – Cloud synchronization for SQLite
- sqlite-js – JavaScript engine integration for SQLite
This project is licensed under the Elastic License 2.0. You can use, copy, modify, and distribute it under the terms of the license for non-production use. For production or managed service use, please contact SQLite Cloud, Inc for a commercial license.