title: SQL Agent for Laravel
description: A self-learning text-to-SQL agent that converts natural language questions into SQL queries using LLMs.
template: splash
hero:
tagline: A self-learning text-to-SQL agent that converts natural language questions into SQL queries using LLMs.
image:
file: ../../assets/logo.svg
actions:
- text: Get Started
link: /sql-agent/getting-started/introduction/
icon: right-arrow
- text: View on GitHub
link: https://github.com/knobik/sql-agent
icon: external
variant: minimal
import { Card, CardGrid } from '@astrojs/starlight/components';
Why This Package?
Raw LLMs writing SQL hit a wall fast — schemas lack meaning, types are misleading, tribal knowledge is missing, and the same errors repeat endlessly. The root cause is missing context and missing memory.
How It Works
- Assemble context — The agent retrieves relevant table metadata, business rules, query patterns, and past learnings based on the question
- Enter tool loop — The LLM iteratively introspects schema, searches for additional knowledge, executes SQL, and refines results
- Learn and improve — Errors become learnings, successful queries become reusable patterns — both feed back into future context assembly
See the Introduction for a detailed architecture overview.
Quick Start
composer require knobik/sql-agent
php artisan sql-agent:install
Then configure your LLM provider in .env and start asking questions:
use Knobik\SqlAgent\Facades\SqlAgent;
$response = SqlAgent::run('How many users signed up this month?');
echo $response->answer;
See the Installation guide for full setup instructions.
Features
- Multi-Database Support — MySQL, PostgreSQL, SQLite, and SQL Server
- Multiple Search Drivers — Database full-text search or pgvector semantic search
- Agentic Loop — Tool calling to introspect schema, run queries, and refine results
- Livewire Chat UI — Ready-to-use chat interface with conversation history
- Evaluation Framework — Test your agent's accuracy with automated evaluations