import luciano
← back

Conversational Data Analyst Agent

COMPLETE
TypeScriptMastraPostgreSQLVercel AI SDK

Description

Built an agent with Mastra (TypeScript) that turns natural-language questions into SQL against a PostgreSQL database and streams answers plus the underlying query back token-by-token via the Vercel AI SDK, for full transparency into how each answer was derived. A 7-processor control layer — forced first tool-call, schema-repeat blocking, question re-anchoring, and token limiting — steers a locally-hosted 20B model to reliable multi-step query resolution without fine-tuning.

Highlights

  • Natural-language-to-SQL agent against a PostgreSQL database, streaming answers and the underlying query back token-by-token via the Vercel AI SDK for full transparency.
  • 7-processor control layer (forced first tool-call, schema-repeat blocking, question re-anchoring, token limiting) steering a locally-hosted 20B model to reliable multi-step query resolution — without fine-tuning.
  • Hardened execution with a read-only (SELECT-only) guard, a 10-second query timeout, and a 5-minute schema cache eliminating redundant introspection calls.
  • Deterministic output (temperature 0) so identical questions yield identical SQL, making agent behavior auditable and testable.

Architecture

Natural-language question → 7-processor control layer (tool-call forcing, schema-repeat blocking, re-anchoring, token limiting) → SQL generation against a cached schema → read-only execution guard (SELECT-only, 10s timeout) → token-by-token streamed response via the Vercel AI SDK. Temperature 0 keeps output deterministic and testable.

View on GitHub →