Skip to content
Luciano Fried
ENES

Back to selected work

Project

Conversational Data Analyst Agent

A Mastra (TypeScript) agent that turns natural-language questions into SQL against a PostgreSQL database and streams answers plus the underlying query back token-by-token.

  • COMPLETE
View on GitHub (opens in a new tab)

Stack

  • TypeScript
  • Mastra
  • PostgreSQL
  • Vercel 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

  • Built a natural-language-to-SQL agent that streams results token-by-token for full transparency into query derivation.
  • Engineered a 7-processor control layer steering a 20B model to reliable multi-step query resolution without fine-tuning.
  • Hardened execution: read-only guard, 10-second timeout, 5-minute schema cache eliminating redundant introspection.
  • 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.