The Unified 'Corporate Brain': Orchestrating SQL and Text with Agents

There’s a frustration I hear from almost every executive.

In a board meeting, someone asks a simple, reasonable question:

“Why did our profit margin drop in Q3?”

Answering it is anything but simple.

First, someone opens a PowerBI dashboard to confirm what happened (structured data).

Then, emails go out to department heads to understand why it happened (unstructured context).

Then, someone digs through PDFs or incident reports from the supply chain team.

The executive ends up acting as a human translator—bridging SQL on one side and documents on the other.

Enterprise AI was supposed to eliminate this friction. Instead, many organizations ended up with two disconnected solutions:

  • Text-to-SQL chatbots
Great at telling you how many widgets you sold. Terrible at explaining why customers returned them.
  • Document chatbots (RAG)
Great at summarizing strategy decks. Completely unreliable when asked to calculate revenue.

The future of Enterprise AI isn’t choosing between these two.

It’s building a Unified Corporate Brain—a system that speaks both languages fluently.

Here’s how to architect a Supervisor Agent on Databricks that orchestrates SQL and text into a single, coherent answer.


The Data Silo Problem

Every organization’s knowledge lives in two hemispheres.

The Left Brain (Structured)

ERPs, CRMs, transaction logs. Precise, numerical, and stored in tables.

The Right Brain (Unstructured)

Emails, PDFs, incident reports, strategy documents. Nuanced, narrative, and stored as vectors.

LLMs can sound confident in both worlds. But sounding right isn’t the same as being right—especially when math is involved.

The solution isn’t forcing one model to do everything.

Instead, we build a compound AI system: specialized tools for each data type, coordinated by a Supervisor that knows when—and how—to use them.


The “Supervisor Agent” Pattern

At the center of the architecture is a single orchestrator: the Supervisor.

Its role is simple but powerful—delegate work to the right specialist.

Tool A: The Analyst (Structured Data)

For questions like “How much,” “When,” or “Compare,” we rely on SQL-native tools. On Databricks, there are two strong options:

  • Unity Catalog Functions
Secure, predefined SQL functions for common business questions (for example, get_revenue_for_region).
  • Databricks Genie
An AI agent that generates SQL dynamically for ad-hoc analytical questions.

Tool B: The Researcher (Unstructured Data)

For questions like “Why,” “How,” or “Summarize,” we use Mosaic AI Vector Search.

It retrieves relevant emails, PDFs, and reports to provide narrative context.


The Code Implementation

The Supervisor Agent—implemented with a framework like DSPy or LangGraph—acts as the router.

It decides which tool to call based on the user’s intent, and when to combine results.

# 1. Define the Tools
def tool_genie(question: str) -> str:
    """
    Use Genie for KPI/SQL asks (metrics, time windows, aggregates).
    Returns SQL query results and a data preview.
    """

    # Logic to call Databricks Genie Conversation API...
    return genie_response

def tool_rag(question: str) -> str:
    """
    Use the Vector Search KB to answer qualitative questions.
    Returns narrative text with citations.
    """

    # Logic to call Vector Search with Hybrid Retrieval...
    return rag_response

# 2. Define the Agent Logic (The Supervisor)
class AgentQA(dspy.Signature):
    """
    You are a Supervisor Agent.
    - If the user asks "How much" or "When", use 'tool_genie'.
    - If the user asks "Why" or "How", use 'tool_rag'.
    - If the user asks BOTH, use BOTH tools and synthesize the answer.
    """

    question: str = dspy.InputField()
    answer: str   = dspy.OutputField()


The code isn’t the point.

The architecture is.


The Scenario: Anatomy of an Answer

Let’s return to the boardroom question:

“Why did sales drop in Q3?”

When this query reaches the Supervisor Agent, it doesn’t guess. It executes a plan.

Reasoning

“I need to confirm the drop (data) and understand the cause (context).”


Action 1 — Structured

tool_genie("Show total sales decline Q2 vs Q3 2024")

Observation

Genie runs SQL against the ERP.

Result: Sales dropped by $2.4M (12%).


Action 2 — Unstructured

tool_rag("Reasons for Q3 2024 sales performance")

Observation

Vector Search retrieves the Q3 Supply Chain Incident Report.

Finding: Shipments were delayed due to the August port strike.


Synthesis

The Supervisor combines both signals into one answer.


Final Output

“Sales dropped by $2.4M (12%) in Q3 compared to Q2.

This decline correlates with the August port strike, which delayed inventory shipments by three weeks

(Source: Q3 Supply Chain Incident Report).”


This is the real goal of enterprise analytics:

quantitative facts explained by qualitative context.


Unified Governance via Unity Catalog

At this point, every CISO asks the same question:

“If we connect AI to our data, what stops it from dumping the payroll table?”

The answer is governance—built into the platform.

We don’t give agents access to raw data.

We give them access to governed Unity Catalog functions.


CREATE FUNCTION main.tools.get_sales_metrics(region STRING)
RETURNS TABLE
RETURN
  SELECT * FROM revenue
  WHERE region = get_sales_metrics.region;


The agent’s service principal receives EXECUTE permission on this function—nothing more.

Even if the LLM tries something reckless, the data platform enforces the boundary.

The agent is sandboxed by design.


Managerial Takeaway: Compound Systems Beat Chatbots

The era of the simple chatbot is ending.

The systems that win are compound AI systems—combinations of:

  • structured analytics,
  • unstructured retrieval,
  • and intelligent orchestration.


So stop asking:

“Which model should we use?”

Start asking:

“How do we connect our structured truth with our unstructured context?”


When you get that right, you stop building demos.

You start building a real Corporate Brain—one that answers the questions that actually matter.


Comments

Popular posts from this blog

10 Rules for Professional GenAI Engineering on Databricks

The "CFO-Approved" Deployment: Embedding FinOps into Your CI/CD Pipeline

Zero-Trust RAG: The C-Suite Guide to Secure Multi-Tenant AI | Everstone AI