Community程式設計與開發github.com

grahama1970/batch-quality

批次 LLM 操作的前置驗證與品質管控。實際透過 LLM 測試樣本,避免浪費 Token。採用 SPARTA 合約進行 DuckDB 驗證查詢,並與 task-monitor 整合以強制執行品質關卡。

batch-quality 是什麼?

Batch Quality Skill 是一個專為批次 LLM 操作設計的前置驗證與品質管控工具,支援 Claude Code、Cursor 等 AI 代理平台。不同於單純的檔案存在檢查,它會實際透過 scillm 對 N 個樣本執行 LLM 呼叫,驗證 JSON 回應結構(如 excerpts、source_quality 等),並利用 SPARTA 合約執行 DuckDB 驗證查詢。這個技能提供 preflight、validate、status 和 clear 四個指令,讓開發者在啟動完整批次前先測試少量樣本,確保品質達標後才正式執行,避免浪費大量 Token 與時間。對於長時間運作的批次作業(如 QRA 生成),它更強制要求在執行過程中定期暫停、抽樣、評估品質,並在品質惡化時自動停止並通知人工介入。整體上,這個技能大幅降低了批次 LLM 操作失敗的成本,透過提前發現問題來節省計算資源。

相容平台~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 Skill

透過在執行完整批次操作前驗證品質,避免浪費 LLM 呼叫。

這個技能實際做什麼

不同於單純的檔案存在檢查,此技能:

  1. 實際對 N 個樣本執行 LLM(使用 scillm)
  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

# 如果前置檢查通過,執行批次作業
# ...批次操作...

# 驗證:根據合約檢查 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 呼叫(實際 LLM 呼叫)
  6. 驗證 JSON 回應結構
  7. 要求至少 50% 以上的樣本通過

結束碼:

  • 0:PASSED - 可以安全繼續
  • 1:FAILED - 請先修正問題

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. 針對 DuckDB 執行合約中的所有 validation_queries
  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. PAUSE — 使用 SIGSTOP 暫停生成過程
  2. SNAPSHOT — 複製 DuckDB 進行離線分析,然後立即發送 SIGCONT
  3. SAMPLE — 分層隨機抽樣(高/中/低 grounding 分層)
  4. ASSESS — 檢查每個樣本:實體 grounding、回答品質、推理
  5. DIAGNOSE — 趨勢分析:grounding 是否下降?實體失敗是否增加?
  6. TWEAK — 如果品質惡化:調整提示詞、過濾閾值、關係分數
  7. RESUME — 僅當品質符合門檻時恢復
  8. STOP + NOTIFY — 如果品質低於底線,停止並通知人工

這不是可選項目。 一個批次如果未經品質關卡就跑到 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.

相關技能