简介
langchain_data_agent 把自然语言问题变成 SQL,并提供 CLI 入口;它能按配置把问题路由到不同的专用数据 agent,适合把数据问答流程标准化。
最适合: 想用可复用配置 + CLI 快速原型 NL2SQL 助手的数据团队
适配: Python 3.12+ + uv;通过 .env 配置凭证(README 前置条件)
配置时间: 20–45 分钟
关键事实(已验证)
- README 列出 CLI 命令(
query/chat/configs/validate)以及按配置路由机制。 - Quick start 使用
uv sync --all-extras并复制.env.example(README)。 - GitHub:231 stars · 33 forks;最近更新 2026-01-14(GitHub API 验证)。
正文
NL2SQL agent 的实用护栏
在评测覆盖不够之前使用只读凭证,并记录生成的 SQL 与结果结构,便于审计。
README 原文节选(verbatim)
+ ╔╦╗╔═╗╔╦╗╔═╗ ╔═╗╔═╗╔═╗╔╗╔╔╦╗
+ ║║╠═╣ ║ ╠═╣ ╠═╣║ ╦║╣ ║║║ ║
+ ═╩╝╩ ╩ ╩ ╩ ╩ ╩ ╩╚═╝╚═╝╝╚╝ ╩
[ Natural Language → SQL Query Agent ]A natural language to SQL (NL2SQL) platform built on LangGraph and Azure OpenAI. This multi-agent system automatically routes user questions to the appropriate database backend and generates optimized SQL queries and results.
Built on top of LangChain's SQLDatabase with extended support for Azure AD authentication, Cosmos DB, and built-in dialect validation.
Features
- Multi-Database Support: PostgreSQL, Azure SQL, Azure Synapse, Azure Cosmos DB, Databricks SQL, and Google BigQuery
- Intent Detection: Automatically routes queries to the correct data agent based on question context
- Multi-Turn Conversations: Follow-up questions with context awareness (e.g., "What's the average?" after a query)
- SQL Validation: Safe query execution with sqlglot-based validation across all dialects
- Data Visualization: Generate charts and graphs from query results using natural language (e.g., "show me a bar chart")
- Configurable Agents: YAML-based configuration for adding new data sources
- A2A Protocol: Agent-to-Agent interoperability for integration with other A2A-compliant systems
Architecture
Intent Detection Flow
Routes user questions to the appropriate data agent based on context.

Data Agent Flow
Generates, validates, and executes SQL queries with retry logic.
