Spaces:
Sleeping
Sleeping
fix
Browse files
README.md
CHANGED
|
@@ -15,13 +15,36 @@ tags:
|
|
| 15 |
|
| 16 |
# SQL Agent OpenEnv
|
| 17 |
|
|
|
|
|
|
|
| 18 |
An OpenEnv-compliant RL environment for SQL generation, featuring:
|
| 19 |
|
| 20 |
- **LinUCB contextual bandit** β selects repair strategies based on error context
|
| 21 |
- **GEPA (Generative Evolutionary Prompt Adaptation)** β evolves the system prompt from failure patterns
|
| 22 |
-
- **
|
|
|
|
| 23 |
- **Shaped reward function** β success bonus, attempt penalty, error severity signal
|
| 24 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## OpenEnv API
|
| 27 |
|
|
@@ -31,6 +54,15 @@ An OpenEnv-compliant RL environment for SQL generation, featuring:
|
|
| 31 |
| `/step` | POST | Execute one repair action |
|
| 32 |
| `/state` | GET | Current environment state |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
## Demo
|
| 35 |
|
| 36 |
Click **Demo** in the top-right to watch the agent fail, self-repair via RL, then improve through two GEPA prompt-evolution cycles (42% β 91%).
|
|
|
|
| 15 |
|
| 16 |
# SQL Agent OpenEnv
|
| 17 |
|
| 18 |
+
> **Origin:** This project is a port of [gepa-tuned-sql-agent](https://github.com/Ar9av/gepa-tuned-sql-agent) β originally built as a TypeScript/Next.js application β rewritten in Python (FastAPI + React/Vite) to match the OpenEnv format and deploy on Hugging Face Spaces.
|
| 19 |
+
|
| 20 |
An OpenEnv-compliant RL environment for SQL generation, featuring:
|
| 21 |
|
| 22 |
- **LinUCB contextual bandit** β selects repair strategies based on error context
|
| 23 |
- **GEPA (Generative Evolutionary Prompt Adaptation)** β evolves the system prompt from failure patterns
|
| 24 |
+
- **Multi-turn repair loop** β LLM receives full failure history so each retry learns from the previous error
|
| 25 |
+
- **3 difficulty tiers** β easy / medium / hard benchmark tasks on a built-in e-commerce schema
|
| 26 |
- **Shaped reward function** β success bonus, attempt penalty, error severity signal
|
| 27 |
+
- **External database support** β connect any SQLite file or PostgreSQL database via connection string
|
| 28 |
+
|
| 29 |
+
## Background
|
| 30 |
+
|
| 31 |
+
The original [gepa-tuned-sql-agent](https://github.com/Ar9av/gepa-tuned-sql-agent) explored three research ideas in a Next.js stack:
|
| 32 |
+
|
| 33 |
+
1. **Self-debug loop** β the agent critiques and fixes its own SQL errors without human intervention
|
| 34 |
+
2. **GEPA prompt evolution** β after user feedback, an LLM reflects on failures and evolves the system prompt
|
| 35 |
+
3. **Mini-RL environment** β a LinUCB contextual bandit learns which repair strategy works best for each error class
|
| 36 |
+
|
| 37 |
+
This repo preserves all three ideas and adapts them to a Python backend so the environment can be packaged as a Docker container and hosted on Hugging Face Spaces.
|
| 38 |
+
|
| 39 |
+
## Key differences from the original
|
| 40 |
+
|
| 41 |
+
| | gepa-tuned-sql-agent | sql-agent-openenv (this repo) |
|
| 42 |
+
|---|---|---|
|
| 43 |
+
| Backend | Next.js API routes (TypeScript) | FastAPI (Python) |
|
| 44 |
+
| Frontend | Next.js pages | React + Vite (static, served by FastAPI) |
|
| 45 |
+
| LLM | Azure OpenAI | HF Router (Qwen 2.5-72B) |
|
| 46 |
+
| Deployment | Vercel / local | Hugging Face Spaces (Docker) |
|
| 47 |
+
| DB support | SQLite, PostgreSQL, MySQL | SQLite file + PostgreSQL DSN |
|
| 48 |
|
| 49 |
## OpenEnv API
|
| 50 |
|
|
|
|
| 54 |
| `/step` | POST | Execute one repair action |
|
| 55 |
| `/state` | GET | Current environment state |
|
| 56 |
|
| 57 |
+
## Connect your own database
|
| 58 |
+
|
| 59 |
+
In the UI click **Connect DB** (top-right) and enter:
|
| 60 |
+
|
| 61 |
+
- **SQLite:** `/path/to/your/database.db` or `:memory:`
|
| 62 |
+
- **PostgreSQL:** `postgresql://user:password@host:5432/dbname`
|
| 63 |
+
|
| 64 |
+
The agent auto-detects the dialect and adjusts its prompt accordingly.
|
| 65 |
+
|
| 66 |
## Demo
|
| 67 |
|
| 68 |
Click **Demo** in the top-right to watch the agent fail, self-repair via RL, then improve through two GEPA prompt-evolution cycles (42% β 91%).
|