knobik/sql-agent
Self-learning text-to-SQL agent for Laravel that turns natural language into accurate, safe SQL. Uses schema introspection, a curated knowledge base, query patterns, and conversation memory; recovers from errors and saves learnings. Includes built-in chat UI.
If the agent isn't finding relevant context or producing poor SQL:
php artisan sql-agent:load-knowledge --recreate.sql_agent_table_metadata table has entries: SELECT COUNT(*) FROM sql_agent_table_metadata.The agent couldn't complete the task within the allowed number of tool-calling rounds:
SQL_AGENT_MAX_ITERATIONS in your .env file.If queries are being rejected or failing:
sql-agent.sql.allowed_statements includes the statement types your queries need (default: SELECT and WITH).sql-agent.sql.forbidden_keywords.sql-agent.sql.max_rows if result truncation is causing issues.If the agent is taking too long to respond:
gpt-4o-mini instead of gpt-4o).chat_history_length to minimize the context sent to the LLM.database search driver for simpler setups — it avoids external service round-trips.If you're getting authentication or connection errors from the LLM provider:
ollama serve) and the model has been pulled (ollama pull <model>).If the search driver isn't returning expected results:
pgvector search driver for semantic similarity search.If you see errors about missing classes like Pgvector\Laravel\Vector or Pgvector\Laravel\HasNeighbors:
composer require pgvector/pgvector.php artisan sql-agent:setup-pgvector to publish migrations and create the embeddings table.SQL_AGENT_EMBEDDINGS_CONNECTION points to a PostgreSQL database with the pgvector extension installed.How can I help you explore Laravel packages today?