siddarth1872004/DataVigil

GitHub: siddarth1872004/DataVigil

DataVigil 是一个基于 LangGraph 和 Scikit-learn 构建的自主 ReAct 数据智能体,将自然语言查询自动转化为 SQL 并执行机器学习异常检测,最终生成交互式 Plotly 可视化仪表板。

Stars: 0 | Forks: 0

# DataVigil -- 自主 ReAct 数据智能与异常检测 Agent DataVigil 是一个使用 **LangGraph**、**SQLite**、**Scikit-learn** 和 **Plotly** 构建的自主 **ReAct Data Agent**。它将自然语言业务查询转换为经过验证的 SQL 语句,执行 ML 异常检测 pipeline(Isolation Forest 和 Local Outlier Factor),并生成交互式实时可视化仪表板 -- 由 HuggingFace prompt injection 防护机制保驾护航。 ## 架构拓扑 ``` graph TB subgraph USER_INTERFACE["Interface and Dashboard"] NL_IN["Natural Language Query Input"] PLOTLY["Plotly Interactive Charts and Visuals"] REST["FastAPI REST API and Web App"] end subgraph SECURITY_GUARD["Security and Injection Guardrail"] HF_GUARD["HuggingFace Prompt Injection Classifier"] SQL_SAN["SQL Sanitizer and Read-Only Enforcer"] end subgraph REACT_ENGINE["LangGraph ReAct Agent Loop"] PLANNER["Query Planner Node"] SQL_GEN["SQL Generator Agent"] EXEC["Database Execution Engine"] ML_ANOM["ML Anomaly Detector Node"] SYNTH["Dashboard Synthesizer"] end subgraph DATA_STORAGE["Data Storage and ML Engines"] SQLITE[("SQLite / PostgreSQL Database")] SKLEARN["Scikit-learn Isolation Forest / LOF"] end NL_IN --> HF_GUARD HF_GUARD -->|sanitized| PLANNER PLANNER --> SQL_GEN SQL_GEN --> SQL_SAN SQL_SAN --> EXEC EXEC <--> SQLITE EXEC --> ML_ANOM ML_ANOM <--> SKLEARN ML_ANOM --> SYNTH SYNTH --> PLOTLY SYNTH --> REST style USER_INTERFACE fill:#18181b,stroke:#a1a1aa,color:#fff style SECURITY_GUARD fill:#18181b,stroke:#ffffff,color:#fff style REACT_ENGINE fill:#000000,stroke:#ffffff,color:#fff style DATA_STORAGE fill:#18181b,stroke:#e4e4e7,color:#fff ``` ## 自主 ReAct 执行时序图 ``` sequenceDiagram participant User as User / Analytics Interface participant Guard as Security Guardrail participant Agent as LangGraph ReAct Agent participant DB as SQL Database Engine participant ML as Scikit-Learn Anomaly Model User->>Guard: Natural Language Query (e.g. Detect unusual sales spikes) Guard->>Guard: Verify prompt injection safety Guard->>Agent: Pass safe natural language query Agent->>Agent: Plan SQL query and anomaly parameters Agent->>DB: Execute dynamically generated SQL DB-->>Agent: Return structured tabular dataset Agent->>ML: Run Isolation Forest / LOF outlier detection ML-->>Agent: Tag anomalous rows and confidence scores Agent->>Agent: Build interactive Plotly chart JSON Agent-->>User: Render Plotly dashboard + Anomaly report ``` ## 核心能力与安全特性 - **自然语言转 SQL**:通过 schema 验证,将复杂的业务问题转换为 ANSI SQL 查询。 - **机器学习异常检测**:无监督的 Isolation Forest 和 Local Outlier Factor (LOF) 模型可识别时间序列和多变量业务指标中的异常值。 - **Prompt Injection 防护**:HuggingFace 分类器和 SQL AST 解析器可拦截破坏性语句(DROP、DELETE、UPDATE)及越狱尝试。 - **交互式可视化**:生成可直接在前端仪表板中渲染的 Plotly JSON 图表规范。 ## 目录结构 ``` DataVigil/ |-- docker-compose.yml # Container orchestration (Backend + Frontend) |-- README.md # ASCII Architecture and User Documentation |-- backend/ | |-- Dockerfile # Python FastAPI & Scikit-learn container | |-- requirements.txt # FastAPI, LangGraph, Scikit-Learn, Plotly dependencies | |-- main.py # FastAPI server entry point | |-- config.py # Environment & database settings | |-- agents/ # ReAct agent implementation & prompt templates | |-- database/ # SQL engine & schema inspector | |-- security/ # Prompt injection classifier & SQL sanitizer | `-- tests/ # Pytest unit & integration tests `-- frontend/ # Dashboard Web UI ``` ## 快速入门指南 ### 前置条件 - Python 3.10+ - SQLite 或 PostgreSQL 数据库实例 - Docker 和 Docker Compose(可选) ### 本地运行 1. **克隆仓库**: git clone https://github.com/siddarth1872004/DataVigil.git cd DataVigil 2. **设置后端**: cd backend pip install -r requirements.txt 3. **启动服务器**: uvicorn main:app --reload --port 8000 4. **访问仪表板 API**: 导航至 `http://localhost:8000/docs`。 ## 许可证 基于 **MIT License** 发布。详情请参阅 `LICENSE`。
标签:DLL 劫持, IaC 扫描, LangGraph, Text2SQL, 人工智能, 代码示例, 大语言模型, 异常检测, 数据分析, 测试用例, 用户模式Hook绕过, 请求拦截, 逆向工具