Community编程与开发github.com

grahama1970/batch-quality

批次 LLM 操作的预检验证与质量门控,实际通过 LLM 测试样本后再消耗 tokens,使用 SPARTA 合约进行 DuckDB 验证查询,并与 task-monitor 集成以强制执行质量门控。

batch-quality 是什么?

这是“grahama1970/batch-quality”技能的详细描述,用于在批量 LLM 操作前进行质量验证。与简单的文件存在性检查不同,该技能**实际运行 scillm 对 N 个样本进行 LLM 调用**,验证 JSON 响应结构(如 excerpts、source_quality),并基于 SPARTA 合约对 DuckDB 执行查询验证,确保批量输出质量。它提供三个主要命令:`preflight`(在少量样本上运行 LLM,检查通过率≥50%)、`validate`(根据合约中的 `validation_queries` 检查 DuckDB 结果,并通知 task-monitor)、`status` 和 `clear`(管理预检状态)。该技能无缝集成到 SPARTA 流程中,需要环境变量如 `CHUTES_API_KEY`、`CHUTES_TEXT_MODEL` 和 `SPARTA_ROOT`。特别地,技能强制要求**运行时质量门控**,即在长时间运行的批量操作(如 QRA 生成)中,每处理 N 个批次(如每 5 个 KNN 批次/约 1000 个 QRA)必须暂停、快照、评估、诊断、调整后才继续,否则可能产生大量低质量数据。支持的平台包括 CLI(uv run)和与 task-monitor 的集成。

兼容平台~Claude Code~Codex CLI~Cursor✓Antigravity
npx skills add https://github.com/grahama1970/agent-skills/tree/main/skills/batch-quality

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Batch Quality 技能

通过在运行完整批量操作之前验证质量,避免浪费 LLM 调用。

此技能实际执行的操作

与简单的文件存在性检查不同,此技能:

  1. 实际使用 scillm 对 N 个样本运行 LLM
  2. 验证 JSON 响应结构(如 excerpts、source_quality)
  3. 使用 SPARTA 合约执行 DuckDB 验证查询
  4. 与 task-monitor 集成以强制执行质量门控

快速开始

cd .pi/skills/batch-quality

# 预检:通过实际 LLM 测试 3 个样本
uv run python cli.py preflight \
    --stage 05 \
    --run-id run-recovery-verify \
    --samples 3

# 如果预检通过,运行您的批量操作
# ...batch operation...

# 验证:根据合约检查 DuckDB
uv run python cli.py validate \
    --stage 05 \
    --run-id run-recovery-verify \
    --task-name "sparta-stage-05"

命令

preflight

在运行完整批量操作之前,通过实际 LLM 测试 N 个样本。

uv run python cli.py preflight \
    --stage <stage-name> \
    --run-id <sparta-run-id> \
    --samples 3 \
    --prompt <optional-prompt-file>

实际执行的操作:

  1. 加载该阶段的 SPARTA 合约(如果存在)
  2. 检查环境变量(CHUTES_API_KEY、CHUTES_TEXT_MODEL)
  3. 连接该运行的 DuckDB
  4. 从输入队列中采样 N 个条目
  5. 通过 scillm 运行每个样本(实际 LLM 调用)
  6. 验证 JSON 响应结构
  7. 要求 50% 以上样本通过

退出码:

  • 0:通过 - 可以安全继续
  • 1:失败 - 请先修复问题

validate

使用 SPARTA 合约验证批量输出。

uv run python cli.py validate \
    --stage <stage-name> \
    --run-id <sparta-run-id> \
    --task-name <task-monitor-name>

实际执行的操作:

  1. 加载 SPARTA 合约(例如 05_extract_knowledge.json)
  2. 根据合约运行所有 validation_queries 以查询 DuckDB
  3. 检查每个查询结果是否满足 expected_min
  4. 向 task-monitor 通知通过/失败

合约示例(05_extract_knowledge.json):

{
  "validation_queries": [
    {"name": "url_knowledge_count", "query": "SELECT COUNT(*) FROM url_knowledge", "expected_min": 10},
    {"name": "urls_processed", "query": "SELECT COUNT(*) FROM url_extraction_log WHERE ok = true", "expected_min": 5}
  ]
}

status

检查当前预检状态(JSON 输出)。

uv run python cli.py status

clear

清除预检状态(需要重新进行预检)。

uv run python cli.py clear

SPARTA 流程集成

# 1. 注册需要验证的任务
uv run python .pi/skills/task-monitor/monitor.py register \
    --name "sparta-stage-05" \
    --require-validation

# 2. 运行预检(实际测试 LLM)
uv run python .pi/skills/batch-quality/cli.py preflight \
    --stage 05 \
    --run-id run-recovery-verify \
    --samples 3

# 3. 运行批量操作(仅在预检通过后)
uv run python -m sparta.pipeline_duckdb.05_extract_knowledge \
    --run-id run-recovery-verify

# 4. 使用合约查询进行验证
uv run python .pi/skills/batch-quality/cli.py validate \
    --stage 05 \
    --run-id run-recovery-verify \
    --task-name "sparta-stage-05"

配置

环境变量:

  • SPARTA_ROOT:SPARTA 项目路径(默认为 ~/workspace/experiments/sparta)
  • CHUTES_API_KEY:用于 LLM 调用的 API 密钥
  • CHUTES_API_BASE:API 基础 URL(默认为 https://llm.chutes.ai/v1)
  • CHUTES_TEXT_MODEL:用于文本提取的模型 ID

合约位置: $SPARTA_ROOT/tools/pipeline_gates/fixtures/D3-FEV/contracts/

依赖项

  • typer - CLI 框架
  • duckdb - 数据库查询
  • scillm - LLM 批量处理(用于实际样本测试)

强制性运行时质量门控(不可协商)

对于长时间运行的批量操作(尤其是 QRA 生成、提取等),仅靠预检是不够的。您必须在执行过程中运行质量门控,而不仅仅是在之前运行。

暂停-评估-诊断-调整-恢复循环

每 N 个批量检查点之后(例如,每 5 个 KNN 批次 / 约 1000 个 QRA):

  1. 暂停 — SIGSTOP 生成进程
  2. 快照 — 复制 DuckDB 用于离线分析,然后立即 SIGCONT
  3. 采样 — 分层随机抽样(高/中/低 grounding 层)
  4. 评估 — 检查每个样本:实体 grounding、答案质量、推理
  5. 诊断 — 趋势分析:grounding 是否下降?实体失败是否增加?
  6. 调整 — 如果持续恶化:调整提示、过滤阈值、关系分数
  7. 恢复 — 仅当质量满足阈值时
  8. 停止 + 通知 — 如果质量低于下限,停止并通知人工

这不是可选的。 在没有质量门控的情况下运行到 10 万个 QRA 的批量操作将产生垃圾数据,清理这些数据所需的时间比重新生成正确数据还要长。

QRA 质量门控脚本

# 持续看门狗(与 QRA 生成同时运行)
python $SPARTA_ROOT/scripts/qra_quality_gate.py watch \
    --run-id run-recovery-verify \
    --batch-interval 5 \
    --samples 10

# 一次性评估
python $SPARTA_ROOT/scripts/qra_quality_gate.py assess \
    --run-id run-recovery-verify \
    --samples 20

# 查看各检查点的趋势
python $SPARTA_ROOT/scripts/qra_quality_gate.py trend \
    --run-id run-recovery-verify

质量阈值

指标警告停止
平均 Grounding< 0.65< 0.55
实体失败 %> 5%> 10%
样本失败率> 15%> 30%
Grounding 下降(每个检查点)> 0.05> 0.10

为什么这很重要

QRA grounding 分数在数小时内从 0.74 下降到 0.62,且无人干预,因为看门狗是被动的。一个合适的质量门控会在 0.70 → 0.65 时发现下降并进行诊断(KNN 耗尽简单关系、提示漂移等),而不是任由其滑到 0.62。

关键原则

预检很便宜。失败的批量操作很昂贵。

测试 3 个样本花费约 0.01 美元,耗时 30 秒。 使用一个损坏的提示运行 1000 个条目花费约 3 美元,耗时数小时。

运行时门控比重生成更便宜。 每 1000 个 QRA 暂停 10 秒来验证质量几乎不会损失成本。盲目运行 10 万个 QRA 然后发现一半不可用,代价则是巨大的。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

grahama1970/acceptance-contract

Turn a client brief, zip bundle, directory, or single requirements file into a typed acceptance-contract bundle with extracted requirements, acceptance checks, open questions, an immutable-goal draft, and a create-report-backed decision report. Use when users say acceptance contract, brief to requirements, freeze the goal, create immutable goal, amend immutable goal, build a Battle requirements bundle, or extract requirements from this bundle.

grahama1970/agent-ecosystem

Canonical map and shared contracts for the agent-governance ecosystem: the pi.receipt_envelope.v1 boundary envelope, the component graph, and the rules for which component owns which schema. Use when wiring a skill or extension into the shared receipt world, when asking how shame, triage-error, tau, ask, project-watchdog, ops-herdr, ponytail, and Memory fit together, or when validating an envelope.

grahama1970/agentic-evals

Agentic evaluation of skills using multi-trial fixtures, deterministic command assertions, trajectory checks, safety constraints, and evidence-backed readiness scoring. Use when users ask for agentic evals, multi-trial skill evaluation, skill trajectory validation, or readiness scoring for a skill workflow.

grahama1970/agent-inbox

File-based inter-agent messaging with headless dispatch. Check inbox, send bugs/requests to other projects, automatically spawn headless agents to fix bugs, and track progress via task-monitor.

grahama1970/agents-registry

Generate and query the centralized agent identity registry. Scans .pi/agents/*/AGENTS.md, parses frontmatter, outputs agents-registry.json and optionally syncs to /memory for semantic search.

grahama1970/agent-status

Artifact-driven status surfaces for long-running project-agent work. Maintains status.json, events.jsonl, proof manifests, and a stale-aware STATUS.html so humans can tell where the agent is, what passed, what is still unproven, and what decision or action is next — without dashboard theater.

grahama1970/align

Round-based context alignment before execution. Use when the human, project agent, WebGPT, scillm, ask, dogpile, memory, or project-knowledge may each hold different facts about a task; especially before ambiguous design, infographic, product workflow, high-stakes implementation, plan-iterate, project-infographic, or multi-review work.

grahama1970/analytics

Flexible data science analytics for any dataset. Auto-discovers schema, recommends charts, exports to create-figure. Works with JSONL, JSON, CSV from any source.

grahama1970/analyze-chatterbox-emotions

Evaluate generated Chatterbox voice files as voice-quality artifacts: affect match, arousal/valence proxies, pause placement, intelligibility inputs, clipping, loudness, and discontinuity flags. Use when reviewing Chatterbox emotional tags, pauses, Turbo/base affect delivery, Persona Dream utterance renders, or whether generated speech matches an intended product-facing affect.

grahama1970/analyze-elf

Reverse-engineer features from ELF binaries. Extracts CLI commands, state machines, protocols, Zod schemas, and data models. Automatically generates a /create-walkthrough prosecution brief with Mermaid diagrams. Uses /treesitter for AST analysis of bundled JS/TS source.

grahama1970/animation-vocabulary

Reverse-lookup glossary that turns a vague description of a web animation or motion effect into its exact term ("the bouncy thing when a popover opens" → Pop in; "the iOS rubber-band scroll" → Rubber-banding). Use when the user asks "what's it called when…", or describes a motion effect without knowing its name and wants the right word to prompt an AI or designer with. For naming an effect, not designing or building one.

grahama1970/anonymize-data

Anonymize supported CSV, JSON, UTF-8 text, and SQLite files using an explicit policy through the oai-trial project. Use for anonymize data, pseudonymize exports, redact policy literals, or discover and explicitly approve fuzzy name aliases. The skill is a thin CLI/Docker interface, not another engine.

grahama1970/anvil

Heavy-duty "No-Vibes" debugging and hardening orchestrator. Use this for complex, stubborn bugs where `review-code` has failed, or for "Red Teaming" (hardening) a codebase. Runs multiple agents in parallel (Thunderdome) using git worktree isolation.

grahama1970/apple-design

Apple's approach to interface design and fluid, physical motion, translated for the web. Use when building or reviewing gesture-driven UI, spring animations, drag/swipe/sheet interactions, momentum and interruptible transitions, translucent materials and depth, typography (optical sizing, tracking, leading), reduced-motion, or the design foundations (feedback, spatial consistency, restraint) behind Apple-style interfaces.

grahama1970/argue

Multi-persona structured debate orchestrator. Personas research via /dogpile, consult colleagues via /ask, and argue toward nuanced synthesis on complex questions.

grahama1970/arxiv

Search arXiv for papers and extract knowledge into memory. Use `search` to find papers, `learn` to extract knowledge.

grahama1970/ask

Use when the user asks to query project memory, ask an oracle, use supported browser-backed reviewers, run Tau roundtable/single-handler workflows, ask Pi-native subagents from within Pi, run persona/deep-review workflows, generate image prompts, check OS/project health through composed skills, or run an ask DAG. This skill is the executable /ask runtime; do not replace it with an informal subagent, plain web search, or hand-written review; inside Pi, explicit Pi-native subagent targets are routed through the pi-subagents tool as an Ask target type.

grahama1970/assess

Step back and critically reassess project state. Use when asked to "assess", "step back", "fresh eyes", "check alignment", "sanity check", "health check", "prune documentation", or "evaluate what's working". Offers documentation pruning and doc-code alignment analysis. Offer to run after major changes (don't auto-run).

grahama1970/assistant

Shared GPT + classifier inference gateway for persona monitor tasks. Routes validation and classification through a 4-tier cascade: heuristic → classifier → local GPT → scillm.

grahama1970/assistant-lab

Self-improvement workbench for /assistant. All the tools needed to diagnose, train, evaluate, and promote models in a continuous loop. The "warm pond" where /assistant evolves its own inference stack.

相关技能