k1golestan commited on
Commit
5a17891
Β·
verified Β·
1 Parent(s): 14d9feb

Add comprehensive README

Browse files
Files changed (1) hide show
  1. README.md +98 -4
README.md CHANGED
@@ -1,12 +1,106 @@
1
  ---
2
- title: Text To Sql Agent
3
- emoji: 🌍
4
- colorFrom: gray
5
  colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 6.13.0
8
  app_file: app.py
9
  pinned: false
 
 
 
 
 
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Multi-Turn Text-to-SQL Agent
3
+ emoji: πŸ—ƒοΈ
4
+ colorFrom: blue
5
  colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 6.13.0
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
+ tags:
12
+ - text-to-sql
13
+ - agent
14
+ - smolagents
15
+ - multi-turn
16
+ - clarification
17
  ---
18
 
19
+ # πŸ—ƒοΈ Multi-Turn Text-to-SQL Agent with Clarification
20
+
21
+ An intelligent SQL assistant that doesn't just generate SQL β€” it **thinks before querying**. When your question is ambiguous, it asks for clarification first. When data doesn't exist, it tells you why and suggests alternatives.
22
+
23
+ ## 🎯 What Makes This Different
24
+
25
+ Traditional text-to-SQL systems blindly generate a query from your question. This agent follows a **3-step decision process** inspired by recent research:
26
+
27
+ 1. **Classify** β€” Is the question answerable, ambiguous, or unanswerable?
28
+ 2. **Clarify** β€” If ambiguous, ask the user targeted questions before generating SQL
29
+ 3. **Execute & Verify** β€” Generate SQL, run it, self-correct if errors occur
30
+
31
+ ## πŸ§ͺ Try These Examples
32
+
33
+ | Query | Expected Behavior |
34
+ |-------|------------------|
35
+ | `"Show me the top employees"` | πŸ€” **Asks clarification** β€” Top by salary? Orders handled? Tenure? |
36
+ | `"Which customer spent the most?"` | βœ… **Answers directly** with SQL JOIN across orders/customers |
37
+ | `"What's the customer satisfaction score?"` | ❌ **Explains** the data doesn't exist, suggests alternatives |
38
+ | `"By salary, in Engineering"` (after ambiguous Q) | βœ… **Remembers context** and answers the clarified question |
39
+
40
+ ## πŸ—οΈ Architecture
41
+
42
+ ```
43
+ User Question
44
+ β”‚
45
+ β–Ό
46
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
47
+ β”‚ Intent Classifier β”‚ ← Answerable / Ambiguous / Unanswerable
48
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
49
+ β”‚
50
+ β”Œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”
51
+ β–Ό β–Ό β–Ό
52
+ Clear Ambig N/A
53
+ β”‚ β”‚ β”‚
54
+ β–Ό β–Ό β–Ό
55
+ SQL Ask Explain
56
+ Gen Clarify Why
57
+ β”‚ β”‚
58
+ β–Ό β–Ό
59
+ Execute User
60
+ DB Reply
61
+ β”‚ β”‚
62
+ β–Ό └──→ (next turn)
63
+ Results
64
+ ```
65
+
66
+ ## πŸ“Š Demo Database
67
+
68
+ The Space comes with a pre-loaded **company database** (6 tables, ~60 rows):
69
+
70
+ - **departments** β€” Engineering, Sales, Marketing, HR, Finance
71
+ - **employees** β€” 12 employees with salary, hire date, department, manager
72
+ - **customers** β€” 8 B2B customers with tiers (standard/premium/enterprise)
73
+ - **products** β€” 8 products (Hardware/Software) with price, cost, stock
74
+ - **orders** β€” 12 orders with status (completed/shipped/pending/cancelled)
75
+ - **order_items** β€” 17 line items with quantity, price, discount
76
+
77
+ ## πŸ“š Research Foundation
78
+
79
+ This agent's design draws from:
80
+
81
+ | Paper | Key Contribution |
82
+ |-------|-----------------|
83
+ | [MMSQL](https://arxiv.org/abs/2412.17867) | 4-type question classification (answerable/ambiguous/unanswerable/improper) |
84
+ | [PRACTIQ](https://arxiv.org/abs/2410.11076) | Multi-turn clarification dialogue patterns for SQL |
85
+ | [SQLFixAgent](https://arxiv.org/abs/2406.13408) | Self-correcting SQL via ReAct reasoning |
86
+ | [MTSQL-R1](https://arxiv.org/abs/2510.12831) | Agentic multi-turn SQL with memory verification |
87
+ | [Disambiguate-then-Parse](https://arxiv.org/abs/2502.18448) | Interpretation generation for ambiguous queries |
88
+
89
+ ## πŸ”§ Technical Stack
90
+
91
+ - **Agent**: [smolagents](https://huggingface.co/docs/smolagents) `CodeAgent` with ReAct loop
92
+ - **LLM**: Qwen/Qwen2.5-Coder-32B-Instruct via HF Inference API
93
+ - **Database**: SQLite (in-memory demo)
94
+ - **UI**: Gradio chat interface with multi-turn support
95
+
96
+ ## πŸš€ Run Locally
97
+
98
+ ```bash
99
+ pip install smolagents[gradio] sqlalchemy
100
+ export HF_TOKEN=your_token_here
101
+ python app.py
102
+ ```
103
+
104
+ ## License
105
+
106
+ MIT