Show HN: Building a SQL analyst agent from scratch
a day ago
- #AI Agent
- #SQL Analysis
- #Node.js
- The article describes building a SQL analyst agent using Node.js, OpenAI, Vercel AI SDK, and SQLite.
- It emphasizes using agents over one-shot prompts to allow step-by-step schema inspection, SQL query execution, and result explanation.
- Tools include listTables, describeTable, and runSql to guide the model in exploring the schema before writing queries.
- The Chinook sample database is used with SQLite via better-sqlite3 for simplicity.
- A system prompt directs the agent to inspect schema first, run only SELECT queries, and provide clean answers.
- The agent demonstrates a tight feedback loop for reliable, data-driven responses, serving as a foundation for more complex systems.
- A live example and downloadable project are provided for experimentation and extension.