|
| 1 | +# SQLite Agent |
| 2 | + |
| 3 | +**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](https://github.com/sqliteai/sqlite-mcp) and populate database tables. The extracted data can then be analyzed by LLMs, displayed in UIs, or used in applications. |
| 4 | + |
| 5 | +## Highlights |
| 6 | + |
| 7 | +* **Autonomous Agents** – Run AI agents that can plan and execute multi-step tasks |
| 8 | +* **MCP Integration** – Works with [sqlite-mcp](https://github.com/sqliteai/sqlite-mcp) for external tool access |
| 9 | +* **AI Powered** – Uses [sqlite-ai](https://github.com/sqliteai/sqlite-ai) for LLM inference and embeddings |
| 10 | +* **Table Extraction Mode** – Automatically fetch and populate database tables |
| 11 | +* **Auto-Embeddings** – Optionally uses [sqlite-vector](https://github.com/sqliteai/sqlite-vector) to generate vector embeddings automatically when inserting data for BLOB columns named `*_embedding` |
| 12 | +* **Auto-Vector Indexing** – Initialize vector search indices automatically |
| 13 | + |
| 14 | +## 🚀 Quick Start |
| 15 | + |
| 16 | +### Installation |
| 17 | + |
| 18 | +#### Pre-built Binaries |
| 19 | + |
| 20 | +Download the appropriate pre-built binary for your platform from the [Releases](https://github.com/sqliteai/sqlite-agent/releases) page: we do support **Linux**, **macOS**, **Windows**, **Android** and **iOS**. |
| 21 | + |
| 22 | +### Basic Usage |
| 23 | + |
| 24 | +```sql |
| 25 | +-- Load required extensions |
| 26 | +SELECT load_extension('./dist/mcp'); |
| 27 | +SELECT load_extension('./dist/ai'); |
| 28 | +SELECT load_extension('./dist/agent'); |
| 29 | + |
| 30 | +-- Initialize AI model |
| 31 | +SELECT llm_model_load('/path/to/model.gguf', 'gpu_layers=99'); |
| 32 | + |
| 33 | +-- Connect to MCP server |
| 34 | +SELECT mcp_connect('http://localhost:8000/mcp'); |
| 35 | + |
| 36 | +-- Run an autonomous agent (text-only mode) |
| 37 | +SELECT agent_run('Find affordable apartments in Rome with AC', 8); |
| 38 | +-- Agent uses MCP tools to accomplish the task and returns result |
| 39 | +``` |
| 40 | + |
| 41 | +## 📖 API Reference |
| 42 | + |
| 43 | +### Available Functions |
| 44 | + |
| 45 | +| Function | Description | |
| 46 | +|----------|-------------| |
| 47 | +| `agent_version()` | Returns extension version | |
| 48 | +| `agent_run(goal, [table_name], [max_iterations], [system_prompt])` | Run autonomous AI agent | |
| 49 | + |
| 50 | +See [API.md](API.md) for complete API documentation with examples. |
| 51 | + |
| 52 | +## Complete Example: AirBnb MCP Server |
| 53 | + |
| 54 | +This example demonstrates combining agent, MCP, AI, and vector extensions: |
| 55 | + |
| 56 | +```sql |
| 57 | +-- Load all extensions |
| 58 | +.load ../sqlite-mcp/dist/mcp |
| 59 | +.load ./dist/agent |
| 60 | +.load ../sqlite-ai/dist/ai |
| 61 | +.load ../sqlite-vector/dist/vector |
| 62 | + |
| 63 | +-- Initialize AI model (one-time) |
| 64 | +SELECT llm_model_load('/path/to/model.gguf', 'gpu_layers=99'); |
| 65 | + |
| 66 | +-- Connect to MCP server (one-time) |
| 67 | +SELECT mcp_connect('http://localhost:8000/mcp'); |
| 68 | + |
| 69 | +-- Create table with embedding column |
| 70 | +CREATE TABLE listings ( |
| 71 | + id INTEGER PRIMARY KEY, |
| 72 | + title TEXT, |
| 73 | + description TEXT, |
| 74 | + location TEXT, |
| 75 | + property_type TEXT, |
| 76 | + amenities TEXT, |
| 77 | + price REAL, |
| 78 | + rating REAL, |
| 79 | + embedding BLOB |
| 80 | +); |
| 81 | + |
| 82 | +-- Run agent to fetch and populate data |
| 83 | +-- Embeddings and vector index are created automatically! |
| 84 | +SELECT agent_run( |
| 85 | + 'Find affordable apartments in Rome under 100 EUR per night', |
| 86 | + 'listings', |
| 87 | + 8 |
| 88 | +); |
| 89 | +-- Returns: "Inserted 5 rows into listings" |
| 90 | + |
| 91 | +-- Semantic search (works immediately!) |
| 92 | +SELECT title, location, price, v.distance |
| 93 | +FROM vector_full_scan('listings', 'embedding', |
| 94 | + llm_embed_generate('cozy modern apartment', ''), 5) v |
| 95 | +JOIN listings l ON l.rowid = v.rowid |
| 96 | +ORDER BY v.distance ASC; |
| 97 | +``` |
| 98 | + |
| 99 | +Run the full demo: |
| 100 | +```bash |
| 101 | +make airbnb |
| 102 | +``` |
| 103 | + |
| 104 | +## How It Works |
| 105 | + |
| 106 | +The agent operates through an iterative loop: |
| 107 | + |
| 108 | +1. Receives goal and available tools from MCP |
| 109 | +2. Decides which tool to call |
| 110 | +3. Executes tool via sqlite-mcp extension |
| 111 | +4. Receives tool result |
| 112 | +5. Continues until goal achieved or max iterations reached |
| 113 | +6. Returns final result |
| 114 | + |
| 115 | +## Related Projects |
| 116 | + |
| 117 | +- [sqlite-mcp](https://github.com/sqliteai/sqlite-mcp) – Model Context Protocol client for SQLite |
| 118 | +- [sqlite-ai](https://github.com/sqliteai/sqlite-ai) – AI/ML inference and embeddings for SQLite |
| 119 | +- [sqlite-vector](https://github.com/sqliteai/sqlite-vector) – Vector search capabilities for SQLite |
| 120 | +- [sqlite-sync](https://github.com/sqliteai/sqlite-sync) – Cloud synchronization for SQLite |
| 121 | +- [sqlite-js](https://github.com/sqliteai/sqlite-js) – JavaScript engine integration for SQLite |
| 122 | + |
| 123 | +## Support |
| 124 | + |
| 125 | +- [GitHub Issues](https://github.com/sqliteai/sqlite-agent/issues) |
| 126 | +- [SQLite Extension Load Guide](https://github.com/sqliteai/sqlite-extensions-guide) |
| 127 | + |
| 128 | +## License |
| 129 | + |
| 130 | +This project is licensed under the [Elastic License 2.0 ](./LICENSE). 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 ](mailto:[email protected]) for a commercial license. |
0 commit comments