Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add datagallery-ai/dataagent --skill history-sql-retrievalgit clone --depth 1 https://github.com/datagallery-ai/dataagentWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/datagallery-ai/dataagent/history-sql-retrieval)<a href="https://agentmods.dev/skills/datagallery-ai/dataagent/history-sql-retrieval"><img src="https://agentmods.dev/badge/skills/datagallery-ai/dataagent/history-sql-retrieval/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/datagallery-ai/dataagent/history-sql-retrieval"><img src="https://agentmods.dev/badge/skills/datagallery-ai/dataagent/history-sql-retrieval.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00130 | $0.03315 |
| Opus 5.5 | $0.00052 | $0.01326 |
| Sonnet 5.5 | $0.00026 | $0.00663 |
| Haiku 4.5 | $0.00013 | $0.00331 |
Grade A, and why
history-sql-retrieval scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 147 lines — stays where its author put it; the contents beside it link to each section on GitHub.
历史SQL检索(相似历史SQL召回)
主 Agent 会以自然语言发起历史SQL检索请求,请求中会给出:计划输出的特征清单及每个特征的用户行为、本次输出主键、可选的"源表必须包含"要求、加分项。你的任务是只使用本地文件工具(glob / grep / read_file / ls),从历史 SQL 文件库中找出最相近的历史SQL并结构化返回。
职责边界
- 你返回的是"历史SQL里实际怎么写"的证据摘录(过滤条件、GROUP BY、UDF 调用、列用法),不是"建议怎么写"的 SQL 设计--设计由主 Agent 负责。
- 历史SQL是未验证的参考:schema 可能已经漂移,摘录时如实转述,不做正确性背书。
- 只读文件,绝不修改任何文件;绝不编造历史SQL;找不到就如实说找不到。
历史SQL文件库长什么样
- 位于 本次委派明确提供的语料根目录下的
.sql文件,用ls/glob即可发现。glob/grep 必须显式传path= 本次委派中的语料根目录绝对路径(不传时缺省只搜 workspace 根,会漏掉整个语料库)。 - 文件名 = 该SQL的输出表名(全大写下划线风格),与数仓表名小写一一对应:
ADS_AGALG_FEATURE_USERID_CALL_PACKAGE_APP_SEQ_14D_DM.sql↔ 表biads.ads_agalg_feature_userid_call_package_app_seq_14d_dm。 - 少数输出表存在多份历史SQL,其文件名带
_+ 12 位十六进制后缀--后缀仅用于区分同表多份文件,不属于表名;⌈输出表⌋一律以 SQL 正文(INSERT/CREATE 目标)为准,不得按文件名直接小写化还原表名。 - 文件内容以
INSERT OVERWRITE TABLE ... PARTITION(...) SELECT ...为主体,可从中解析出:输出表、GROUP BY(输出主键)、FROM/JOIN(源表)、WHERE(过滤口径)、UDF 调用、输出列。
第一步:识别检索请求
从主 Agent 的请求中提取:
| 要素 | 说明 | 必填 |
|---|---|---|
| 输出特征 + 用户行为 | 每个计划输出特征及其行为标注(曝光/点击/下载/激活/使用/卸载/通话/搜索/推送/计费/注册...) | 是 |
| 本次输出主键 | 特征主键字段组合(如 imei + app_id、user_id) |
是 |
| 源表必须包含 | 已确认源表时主 Agent 会指定(如 agapdw.dwd_hispace_client_down_tf_dm) |
否 |
| 加分项 | 特征类型 / 时间周期 / 排序维度等 | 否 |
第二步:候选生成(只靠本地文件,两条战术并用)
T1 文件名词法预筛:用"行为词表 × 主体词表"对文件名做 glob(词表见文末),两条结果取交集;无交集时放宽为仅行为词 glob。
例:行为=下载、主键含 user_id → glob *DOWNLOAD* ∩ glob *USERID*(注意:glob 模式必须带 * 包裹关键词,裸词只能匹配字面同名的文件)。
T2 内容 grep 收敛(覆盖文件名不含行为的文件):
- 主 Agent 指定了"源表必须包含"时:
grep该源表全名,命中的文件直接入围。 - 未指定源表时:用行为关键词 grep 文件内容--源表名本身就编码了行为(如
down_tf、exposure、click),能命中输出表名不含行为、但源表是行为事实表的文件。 - 候选仍多时可按主键列名(如
user_id)grep 做辅助收敛。
候选总量仍多时,按词表命中数排序,保留前 8~10 个进入第三步。
第三步:精读校验(read_file,最多读 5 个文件)
对每个候选文件解析并校验:
必须满足(M)-- 任一不满足则淘汰:
| # | 标准 | 判定方式 |
|---|---|---|
| M1 | 用户行为相同 | 读 FROM/JOIN 的源表名判断行为(dwd_hispace_client_down_tf_dm=下载明细、*_exposure_*=曝光、*_click_*=点击…);文件头注释、过滤字段可作辅助。文件名关键词只用于预筛,不作 M1 判定依据。 |
| M2 | 输出主键相同 | 结合最终 SELECT 投影、聚合粒度和唯一性证据判断是否与请求中的输出主键相同。GROUP BY(去掉分区列)只是粒度证据,不能自动等同用户业务主键;复杂 CTE、无 GROUP BY 或派生键无法确认时报告不确定,不得强行匹配。主键比对按 ID 体系严格区分:imei / dsid / udid / did / user_id / app_id 各自独立,绝不混同;仅做命名风格归一(user_id≈userid≈UPPER(user_id))。 |
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 147 lines · 130 tokens per session scan A 3fbd19a714dd
history-sql-retrieval is a skill published in the GitHub repository datagallery-ai/dataagent (748 stars, last pushed 3d ago), licensed Apache-2.0. It adds 130 tokens to every session and 3,315 once invoked, about $0.0005 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-11-28.
history-sql-retrieval compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| history-sql-retrievaldatagallery-ai/dataagent | Skill | 748 | 3d ago | Apache-2.0 | A | 130 | Claude Code, Codex |
| fetch-dataagentscope-ai/QwenPaw-Data | Skill | 208 | 5d ago | Apache-2.0 | A | 286 | Claude Code, Codex |
| cm-skillsagentscope-ai/QwenPaw-Data | Skill | 208 | 5d ago | Apache-2.0 | A | 73 | Claude Code, Codex |
| query-odpsagentscope-ai/QwenPaw-Data | Skill | 208 | 5d ago | Apache-2.0 | A | 111 | Claude Code, Codex |
| sql-analysisrunxhq/runx | Skill | 106 | yesterday | Apache-2.0 | A | 43 | Claude Code, Codex |
| setup-data-workspacedanielrosehill/Claude-Data-Analyst-plugin | Skill | 13 | 27d ago | MIT | A | 73 | Claude Code |
| documentdb-collection-adminKnuckles-Team/documentdb-mcp | Skill | 2 | 4d ago | MIT | A | 78 | Claude Code, Codex |