DEV Community

Cover image for Build Your Own Local AI Agent (Part 2): The SQLite Analyst
Harish Kotra (he/him)
Harish Kotra (he/him)

Posted on

Build Your Own Local AI Agent (Part 2): The SQLite Analyst

In Part 1, we organized files. Now, let's talk to data.

SQL is hard. Natural Language is easy. Today, we build a Local SQLite Analyst that lets you ask questions like "Who are my top users?" and gets answers from your private database.

The Goal

An agent that:

  1. Takes a question ("Show me errors from yesterday").
  2. Inspects your database schema.
  3. Writes the correct SQL query.
  4. Runs it locally and explains the result.

The Architecture

This agent needs to use Tools (specifically, the command line).

The Architecture

The Challenge: Model Smarts

In our tests, smaller models like llama3.2 struggled to plan these multi-step interactions. They often hallucinated or failed to check the schema first.

Solution: Use a smarter local model!

  • Download: ollama pull gpt-oss:20b (or gemma3:12b)
  • These models have better "reasoning" capabilities.

The Recipe

title: SQLite Analyst
instructions: |
  To answer user questions:
  1. Run `sqlite3 .schema` to understand the DB.
  2. Construct a valid SQL query.
  3. Execute it using the shell tool.
  4. Report the answer.
Enter fullscreen mode Exit fullscreen mode

Run It

goose run --recipe sqlite_analyst.yaml --model gpt-oss:20b -s
Enter fullscreen mode Exit fullscreen mode

Now you have a private Data Analyst on your laptop!

The SQLite Analyst Output

Next Up: In [Part 3], we'll fix "Spaghetti Code" automatically.

Top comments (0)