Behind the Scenes: How My Multi-Agent Text-to-SQL System Answers Questions from Reddit Data

· 3 min read


One of the projects I'm currently rebuilding from scratch is a multi-agent Text-to-SQL platform that allows users to ask questions in plain English and receive answers directly from Reddit data stored in a PostgreSQL database.

Why rebuild it?

Because I believe the best way to teach AI engineering is through real-world projects. Last year, I built a similar agentic AI solution for Toyota, and now I'm recreating the entire architecture step-by-step so students at Kentecode AI can learn exactly how production-grade AI agent systems are designed, orchestrated, validated, and deployed.

This isn't a toy demo. It's a complete end-to-end system that demonstrates how multiple AI agents collaborate to solve complex business problems.

Example User Question

"List all the subreddits available and their number of posts."

While the question appears simple, several specialized agents work together behind the scenes before the answer reaches the user.

Agent 1: Intent Evaluation Agent

The first agent determines whether the user's request can be answered using the available database schema.

Responsibilities:

  • Understand the user's natural language request
  • Analyze database schema context
  • Determine if the question is answerable
  • Normalize user intent

This prevents unnecessary SQL generation and reduces hallucinations.


Agent 2: SQL Generation Agent

Once the request is validated, a dedicated SQL specialist generates the PostgreSQL query needed to answer the question.

Responsibilities:

  • Translate natural language into SQL
  • Leverage schema awareness
  • Generate optimized queries

Agent 3: SQL Confidence Evaluator

A second AI agent reviews the generated SQL before execution.

Responsibilities:

  • Validate SQL correctness
  • Assess confidence levels
  • Provide feedback if improvements are needed

This creates a quality-control layer that improves reliability.


Agent 4: Database Security & Execution Agent

Before execution, another agent performs security validation.

Responsibilities:

  • Reject unsafe queries
  • Ensure only approved operations are executed
  • Execute validated SQL against the database

This helps protect production environments from risky AI-generated queries.


Agent 5: Data Analyst Agent

After data is returned, a Data Analyst agent reviews the results.

Responsibilities:

  • Identify trends and patterns
  • Summarize findings
  • Convert raw data into insights

Users receive analysis rather than just rows and columns.


Agent 6: Customer Success Agent

The final agent converts technical results into a clear, user-friendly response.

Instead of SQL and database outputs, users get concise answers they can immediately understand and act upon.


Why Multi-Agent Systems?

Compared to a single-agent approach, multi-agent architectures provide:

✅ Better accuracy ✅ Stronger security controls ✅ Higher reliability ✅ Specialized reasoning ✅ Improved user experience ✅ Easier maintenance and scaling

This is the direction many enterprise AI systems are moving toward.


Why I'm Rebuilding This Project

Last year, I developed a similar agentic AI solution for Toyota. The experience taught me valuable lessons about AI orchestration, validation workflows, guardrails, and production deployment.

Now I'm rebuilding a similar system from scratch using CrewAI so students can see every component being designed and implemented in real time.

We'll cover:

  • Agent design patterns
  • CrewAI orchestration
  • Multi-agent collaboration
  • Prompt engineering
  • Tool integration
  • PostgreSQL and Text-to-SQL
  • Validation and guardrails
  • AI workflow architecture
  • Production deployment strategies

Students won't just learn AI concepts—they'll learn how real-world AI systems are built.


Join Us at Kentecode AI

If you're interested in learning AI Engineering, Agentic AI, CrewAI, and building production-ready AI applications from someone who has implemented these solutions in real-world environments, join us.

🚀 Learn by building real projects, not just watching tutorials.

Share this post