sudo-SQL 是一个基于 langgraph 框架的 Text2SQL 推理与评测智能体。设计的初衷是为了提供一个高效、准确的 Text2SQL 解决方案,同时也为了评测不同 Text2SQL 模型的性能。
文件结构设计如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| sudo-SQL/ ├── src/ │ ├── __init__.py │ ├── inference_agent.py # 主推理 Agent (StateGraph + Send API) │ ├── evaluation_agent.py # 评估 Agent (未来扩展) │ │ │ ├── utils/ # 主 Agent 的 utils │ │ ├── __init__.py │ │ │ │ │ ├── inference_agent_utils/ # inference_agent 的工具 │ │ │ ├── __init__.py │ │ │ ├── state.py # InferenceAgentState, ItemState │ │ │ ├── nodes.py # load_data, prepare_items, distribute, process_batch, aggregate │ │ │ └── tools.py # 协调工具 │ │ │ │ │ └── evaluation_agent_utils/ # evaluation_agent 的工具 │ │ ├── __init__.py │ │ ├── state.py # EvaluationAgentState │ │ ├── nodes.py # evaluate, compare 等节点 │ │ └── tools.py # 评估工具 │ │ │ ├── sub_agents/ # Sub-Agent 层 (独立可复用) │ │ ├── __init__.py │ │ │ │ │ ├── loader_agent/ # 数据加载 Sub-Agent │ │ │ ├── __init__.py │ │ │ ├── agent.py # StateGraph 定义 │ │ │ └── utils/ │ │ │ ├── __init__.py │ │ │ ├── state.py # LoaderState │ │ │ ├── nodes.py # load_dataset, unify_format, load_schema │ │ │ ├── tools.py # DatasetLoader │ │ │ └── tools_schema.py # SchemaLoader │ │ │ │ │ ├── prompt_agent/ # Prompt 构建 Sub-Agent │ │ │ ├── __init__.py │ │ │ ├── agent.py # StateGraph 定义 │ │ │ └── utils/ │ │ │ ├── __init__.py │ │ │ ├── state.py # PromptState │ │ │ ├── nodes.py # build_prompt │ │ │ └── tools.py # PromptBuilder │ │ │ │ │ ├── inference_agent/ # 模型推理 Sub-Agent │ │ │ ├── __init__.py │ │ │ ├── agent.py # StateGraph 定义 │ │ │ └── utils/ │ │ │ ├── __init__.py │ │ │ ├── state.py # InferenceState │ │ │ ├── nodes.py # call_model, extract_sql │ │ │ ├── tools.py # ModelInference │ │ │ └── base.py # BaseInference │ │ │ │ │ └── saver_agent/ # 结果保存 Sub-Agent │ │ ├── __init__.py │ │ ├── agent.py # StateGraph 定义 │ │ └── utils/ │ │ ├── __init__.py │ │ ├── state.py # SaverState │ │ ├── nodes.py # save_result │ │ ├── tools.py # ResultSaver │ │ └── base.py # BaseSaver │ │ │ └── core/ # 基础设施层 │ ├── __init__.py │ ├── config.py # 配置加载 │ └── exceptions.py # 自定义异常 │ ├── prompts/ # 模板资源 (项目根级别,全局共享) │ └── templates/ │ └── text2sql_basic.jinja2 │ ├── configs/ # 配置文件 (项目根级别,全局共享) │ └── config.yaml │ ├── tests/ # 测试目录 (与 src 结构对应) │ ├── conftest.py │ ├── test_inference_agent.py │ ├── test_evaluation_agent.py │ │ │ ├── utils/ │ │ └── test_inference_agent_utils/ │ │ ├── test_state.py │ │ └── test_nodes.py │ │ │ └── sub_agents/ │ ├── test_loader_agent/ │ │ ├── test_tools.py │ │ └── test_nodes.py │ ├── test_prompt_agent/ │ │ ├── test_tools.py │ │ └── test_nodes.py │ ├── test_inference_agent/ │ │ ├── test_tools.py │ │ └── test_nodes.py │ └── test_saver_agent/ │ ├── test_tools.py │ └── test_nodes.py │ ├── scripts/ # 脚本目录 │ └── run_inference.py # 推理入口脚本 │ ├── outputs/ # 推理结果输出目录(运行时生成) │ ├── pyproject.toml # 项目配置 └── README.md # 项目说明文档
|
遵循langgraph的状态管理规范,实现Text2SQL推理与评测智能体,包括数据加载、Prompt构建、模型推理、结果保存等功能,目前评测功能尚未实现。通过将不同功能模块当作独立的sub-agent节点,实现了高度的可扩展性和可维护性。同时基于节点间的分发功能(Send),实现了不同模块之间的解耦和并行处理,提高了系统的效率和响应速度。
评论