How wbbeyourself/mac-sql works
Project Type and Purpose
• This is a research‐oriented Python framework (“MAC‐SQL”) for multi‐agent collaborative Text‐to‐SQL generation. It provides:
• An inference pipeline in core/ that orchestrates three agents (Selector, Decomposer, Refiner) via a ChatManager.
• Evaluation tools under evaluation/ for execution accuracy and validity metrics (BIRD and Spider datasets).
• Demo scripts in scripts/ to run a lightweight Flask/SQLite app for query execution.
• Optional deployment of a local SQL‐Llama model (SQL‐Llama‐deployment.md).
File Structure Analysis
• Top‐level directories:
• data/: raw BIRD & Spider datasets (to be populated by unzipping data.zip).
• core/: inference modules:
– agents.py: definitions of Selector, Decomposer, Refiner.
– chat_manager.py: orchestrates inter‐agent communication.
– llm.py & api_config.py: wraps OpenAI or local LLM calls.
– utils.py, const.py: prompts, templates, helper functions.
• training_scripts/: end‐to‐end data binarization, config, fine‐tuning, inference for model training.
• evaluation/: scripts for measuring Execution Accuracy (EX) and Valid Efficiency Score (VES).
• scripts/: small Flask demo apps (app_bird.py, app_spider.py) and HTML template.
• Config & entry points: requirements.txt, run.py/run.sh/run.bat.
• Architectural patterns:
• Modular pipeline: training vs. inference vs. evaluation vs. demo.
• Multi‐agent orchestration: pipeline stages as independent agents.
• API abstraction: core/llm.py hides details of OpenAI vs. local model.
• Lay out four horizontal layers:
[A] Data Layer
– BIRD dataset
– Spider dataset
[B] Training Pipeline
– binarized_data.py → config.json → finetuning.py → Trained Model artifact
[C] Inference Pipeline
– Frontend Script (optional Flask UI in scripts/)
– Orchestrator (core/chat_manager.py)
• Agent 1: Selector (core/agents.py)
• Agent 2: Decomposer
• Agent 3: Refiner
– LLM Interface (core/llm.py, core/api_config.py) → External OpenAI API or Local SQL‐Llama
– SQL Processor (evaluation/process_sql.py or demo's SQLite backend)
[D] Evaluation Pipeline
– Execution Evaluator (evaluation/evaluation_*ex.py)
– Validity Evaluator (evaluation/evaluation_*ves.py)
– Metrics & Reports
• Components & Interactions:
Architectural Patterns & Design Principles
• Separation of Concerns: training, inference, evaluation, and demo are separate modules.
• Pipeline & Orchestration: each agent is a pipeline stage; ChatManager routes messages.
• Abstraction: llm.py abstracts underlying LLM choice (OpenAI vs. local).