Skip to content

About

A SQLite extension that enables SQLite databases to run autonomous AI agents, using other SQLite AI extensions.

Topics

Resources

Stars

42 stars

Watchers

4 watching

Forks

Latest commit

 

History

38 Commits

Folders and files

Repository files navigation

SQLite AI

SQLite-Agent

Autonomous AI agents that run inside SQLite.
Define agents in SQL, give them tools and memory, run them locally. Built on sqlite-ai, sqlite-memory, and sqlite-mcp. No orchestration server required.

Free managed instance → · Docs · Website · Blog

Data: Vector · Sync · Columnar · JS
AI: AI · Agent · Memory · MCP


Running agents in production? SQLite-Agent works standalone; SQLite Cloud adds shared agent state, webhooks, edge functions, and observability across a fleet of agents. Free tier available.


SQLite Agent

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.

Highlights

  • 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

🚀 Quick Start

Installation

Pre-built Binaries

Download the appropriate pre-built binary for your platform from the Releases page: we do support Linux, macOS, Windows, Android and iOS.

Swift Package

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)

Android Package

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.

Flutter Package

Add the sqlite_agent package to your project:

flutter pub add sqlite_agent  # Flutter projects
dart pub add sqlite_agent     # Dart projects

Usage with sqlite3 package:

import 'package:sqlite3/sqlite3.dart';
import 'package:sqlite_agent/sqlite_agent.dart';

sqlite3.loadSqliteAgentExtension();
final db = sqlite3.openInMemory();
print(db.select('SELECT agent_version()'));

For a complete example, see the Flutter example.

Basic Usage

-- 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

📖 API Reference

Available Functions

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.

Example: AirBnb MCP Server

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 server

See USAGE.md for complete usage examples.

How It Works

The agent operates through an iterative loop:

  1. Receives goal and available tools from MCP
  2. Decides which tool to call
  3. Executes tool via sqlite-mcp extension
  4. Receives tool result
  5. Continues until goal achieved or max iterations reached
  6. Returns final result

Support


☁️ Hosted version

Coordinating multiple agents in production? SQLite Cloud is the managed backbone for SQLite-Agent — shared state, webhooks, REST APIs, and observability for fleets of autonomous agents.

Start free →


Part of the SQLite AI stack

SQLite-Agent is one piece of a larger ecosystem that turns SQLite into a runtime for intelligent, distributed data:

Data layer

AI layer

  • sqlite-ai — On-device LLM inference and embeddings
  • sqlite-agent — Autonomous AI agents running inside SQLite (you are here)
  • sqlite-memory — Persistent, searchable memory for agents
  • sqlite-mcp — Call MCP tools directly from SQL queries

Managed platform

Built by SQLite AI. Questions? Contact us.

About

A SQLite extension that enables SQLite databases to run autonomous AI agents, using other SQLite AI extensions.

Topics

Resources

Stars

42 stars

Watchers

4 watching

Forks

Releases

Contributors

Languages