# multi-agent **Repository Path**: qingyitianxia/multi-agent ## Basic Information - **Project Name**: multi-agent - **Description**: 通用agent平台 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-04 - **Last Updated**: 2026-01-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # NL2SQL System This project demonstrates a Natural Language to SQL (NL2SQL) system built with LangGraph. ## Overview The system translates natural language queries into SQL statements and executes them against a database. It uses a multi-agent approach with LangGraph to orchestrate the various steps involved in this process. ## Architecture The system consists of several components organized as nodes in a LangGraph workflow: 1. **Intent Recognition**: Parses the natural language query to understand user intent 2. **Schema Recall**: Identifies relevant database tables based on the query 3. **SQL Generation**: Generates SQL based on the query and schema information 4. **SQL Validation**: Validates the generated SQL for safety and correctness 5. **SQL Execution**: Executes the SQL query against the database 6. **Result Analysis**: Analyzes the results and determines the best output format ## Setup 1. Install the required packages: ``` pip install -r requirements.txt ``` 2. Set up your API key in the `.env` file: For OpenAI: ``` OPENAI_API_KEY=your_openai_api_key_here ``` For SiliconFlow: ``` LLM_PROVIDER=siliconflow SILICONFLOW_API_KEY=your_siliconflow_api_key_here SILICONFLOW_MODEL=Qwen/Qwen2.5-7B-Instruct SILICONFLOW_API_BASE=https://api.siliconflow.cn/v1 ``` ## Usage To run the NL2SQL agent: ```python from src.nl2sql_agent import create_nl2sql_workflow # Create the workflow app = create_nl2sql_workflow() # Run with a query result = app.invoke({ "user_query": "Show me all employees", "retry_count": 0 }) print(result) ``` ## Database The system uses the Chinook database, a sample database that represents a digital media store. The database includes tables for tracks, albums, artists, customers, and more. The database will be automatically downloaded when you run the system for the first time. ## Supported Databases The system supports multiple database types through a modular database manager: 1. **SQLite** - Default Chinook database 2. **PostgreSQL** - Using psycopg2 driver 3. **MySQL** - Using PyMySQL driver To add a new database, use the DatabaseManager class in `src/db_utils.py`: ```python from src.db_utils import db_manager, DatabaseConfig # Register a PostgreSQL database config = DatabaseConfig( db_type="postgresql", uri="postgresql://user:password@localhost:5432/mydb", name="my_postgres_db" ) db_manager.register_database("my_postgres_db", config) ``` ## Supported LLM Providers The system supports multiple LLM providers: 1. **OpenAI** - Default provider 2. **SiliconFlow** - Chinese LLM provider with OpenAI-compatible API To switch providers, update the environment variables in `.env`. ## Security Features - Only allows SELECT statements - Blocks dangerous SQL keywords (DROP, DELETE, INSERT, etc.) - Uses parameterized queries where possible