跳到正文
DEV Community· tappers·· 5 小時前AI 評分50

Thoughtworks「Guides-and-Sensors」模式實測:配對指引與修正方案令輸入 token 減少 95.1%

Thoughtworks' Guides-and-Sensors Pattern in Action: Bare Errors vs. Feedforward Guides + Remediation Sensors (-95.1% Tokens)

AI 導讀

作者在隔離 VM 中比較只提供標準編譯器錯誤與 Thoughtworks Guides-and-Sensors 架構,後者配合指引和修正方案,以 1 次調用取得 20/20,輸入 token 減少 95.1%。

正文

💡 AI Labo Benchmark Series — Experiment E39 (Architectural Control & Guides + Sensors)

This post is part of our empirical benchmark series testing AI coding agent harness patterns inside network-isolated Proxmox VMs against a hidden 20-case grading suite.


Metadata & Experiment Identity

  • Experiment ID: E39 (Backlog Candidate C035)
  • Run ID: e39-20261029-vm243-01
  • Sandbox Environment: Proxmox Isolated VM VM243 (ai-e39-243, 0 NICs, PrivateNetwork=yes, NoNewPrivileges=yes, InaccessiblePaths, UID split labexp39 / labjudge39)
  • Model: gemini-3.8-flash (thinkingLevel: LOW, temperature=0.0)
  • Pattern Under Test: "Birgitta Böckeler (Thoughtworks / MartinFowler.com): Harness Engineering for Coding Agent Users — Pairing Feedforward Guides with Feedback Remediation Sensors" — Standard Compiler Errors Only (StandardCompilerErrorRunner) vs. Guides-and-Sensors Architectural Remediation Harness (GuidesAndSensorsRemediationRunner)

1. Executive Summary (TL;DR)

In Thoughtworks' Guides and Sensors framework for harness engineering (published by Birgitta Böckeler on MartinFowler.com), effective agent harnesses combine two complementary control loops:

  1. Guides (Feedforward Control): Upfront architectural boundary maps that steer the agent into the right design space before it writes code.
  2. Sensors (Feedback Control with Remediation Idioms): Post-action checks that don't just dump a raw compiler/test error, but attach the exact architectural remediation recipe needed to fix the violation.

When an agent receives only Standard Compiler/Test Errors, it knows what failed but has to guess which architectural convention it violated.

We tested this head-to-head inside isolated VM VM243 on the 3-module enterprise payment settlement pipeline (validator.py ➔ settlement.py ➔ statement.py):

  • Mode A (StandardCompilerErrorRunner): Returns unguided compiler/test errors (73,216 chars of diagnostic logs across Turns 1–2), leaving normalized = dict(item) in validator.py (leaking "extra" keys) and finishing at 19 / 20 (95.0%).
  • Mode B (GuidesAndSensorsRemediationRunner): Pairs feedforward module contract Guides with Sensor Remediation Idioms (GUIDES_AND_SENSORS_HARNESS_MD + submit_guides_sensors_bundle), achieving 20 / 20 (100%) in 1 turn.

Key Result

Mode A failed validator_01_normalize_and_non_mutation (19 / 20) after 3 turns (45,922 cumulative input tokens). Mode B achieved a 20 / 20 (100%) pass in 1 turn, cutting LLM calls by -66.7% (3 ➔ 1), cumulative input tokens by -95.1% (45,922 ➔ 2,237 tokens—a 20.53x reduction), API cost by -83.1% ($0.0451 ➔ $0.0077), and running 2.19x faster (30.15s ➔ 13.76s, -54.4%).

Metric Mode A: Standard Compiler Errors (StandardCompilerError) Mode B: Guides & Sensors Harness (GuidesAndSensorsRemediation) Delta / Improvement
Hidden Grading Suite Score (labjudge39) 19 / 20 (95.0% — 1 failure) 20 / 20 (100% — Perfect) +5.0% accuracy (19/20 ➔ 20/20)
Architectural Drift Traps (gotcha_traps_hit) 2 traps (Turns 1 & 2) 0 traps -100% (zero layer drift)
LLM Calls (model_calls) 3 calls 1 call (1-shot) -66.7% (3.00x faster convergence)
Cumulative File Edits (file_edits) 5 edits 3 edits (1 per module) -40.0% fewer edits
Cumulative Tool Output (tool_output_chars) 73,216 chars 100 chars -99.9% (732.2x noise reduction)
Turn 1 Tokens (In / Out) 1,654 in / 12 out 2,237 in / 1,593 out +583 in for Guides + Sensors spec
Turn 2 Tokens (In / Out) 14,931 in / 1,246 out — (completed on Turn 1) Avoided unguided error dump
Turn 3 Tokens (In / Out) 29,337 in / 1,596 out — (completed on Turn 1) Avoided secondary rework bloat
Cumulative Input Tokens (promptTokenCount) 45,922 tokens 2,237 tokens -95.1% (20.53x efficiency)
Cumulative Output Tokens (candidatesTokenCount) 2,854 tokens 1,593 tokens -44.2% output reduction
Elapsed Execution Time (elapsed_seconds) 30.15 sec 13.76 sec -54.4% (2.19x faster)
Estimated API Cost (estimated_micro_usd) $0.0451 (45,145 micro-USD) $0.0077 (7,652 micro-USD) -83.1% (5.90x cheaper)

2. Experiment Architecture: Standard Compiler Errors vs. Guides & Sensors Harness

+-------------------------------------------------------------------------+
| Proxmox Isolated VM243 (0 NICs, InaccessiblePaths, grader labjudge39)   |
|  Target Task: 3-Module Enterprise Payment Settlement Pipeline           |
|               validator.py ➔ settlement.py ➔ statement.py               |
|                                                                         |
|  +-------------------------------------------------------------------+  |
|  | Mode A: StandardCompilerErrorRunner (Unguided Error Dumps)        |  |
|  |  - Turn 1 (1,654 in):  Calls `run_standard_compiler_check`        |  |
|  |                        ➔ 36,622 chars of unguided error logs      |  |
|  |  - Turn 2 (14,931 in): Calls `stage_layer_drift_patch` on 2 files |  |
|  |                        ➔ 36,276 chars of secondary drift logs     |  |
|  |  - Turn 3 (29,337 in): Submits `normalized = dict(item)` (leaks   |  |
|  |                        `"extra"` key ➔ fails `validator_01`)      |  |
|  |  --> 3 calls | 45,922 in | $0.0451 | 30.15s | 19/20 (1 FAILED)    |  |
|  +-------------------------------------------------------------------+  |
|                                                                         |
|  +-------------------------------------------------------------------+  |
|  | Mode B: GuidesAndSensorsRemediationRunner (Guides + Sensors)      |  |
|  |  - Injects `GUIDES_AND_SENSORS_HARNESS_MD` (+583 tokens):         |  |
|  |    * Feedforward Guides: `[SPEC-VAL]`, `[SPEC-SET]`, `[SPEC-STM]` |  |
|  |    * Feedback Sensors: Exact remediation code idioms per module   |  |
|  |  - Turn 1 (2,237 in): Calls `submit_guides_sensors_bundle` once   |  |
|  |  --> 1 call  | 2,237 in  | $0.0077 | 13.76s | 20/20 (100% PASS)   |  |
|  +-------------------------------------------------------------------+  |
+-------------------------------------------------------------------------+

3. Drop-In Implementation Recipe: run_sensor_with_remediation

Map every architectural sensor violation code to a concrete 1-line remediation guide so the agent never has to guess how to fix a boundary failure:

REMEDIATION_GUIDE_MAP: dict[str, str] = {
    "validator_contract_violation": (
        "[REMEDIATION GUIDE -> validator.py]: Reject empty list & bool (`isinstance(x, bool)` before `int`); "
        "allow `unit_cents >= 0` and `0 <= chargeback_bps <= 1000`; return fresh 5-key dict literal."
    ),
    "settlement_order_or_reserve_boundary": (
        "[REMEDIATION GUIDE -> settlement.py]: Iterate `for k in order:` (remove `sorted(order)`); "
        "charge 10% reserve strictly when `g['chargeback_bps'] > 300`."
    ),
    "statement_delimiter_or_signed_zero": (
        "[REMEDIATION GUIDE -> statement.py]: Use `#` delimiter (`{merchant_id}#{currency}`) "
        "and unconditional `-` sign (`TIER_DISCOUNT: -{batch['tier_discount']}`)."
    ),
}


def run_sensor_with_remediation(error_codes: list[str]) -> str:
    """Pairs every detected sensor violation with its canonical architectural remediation recipe."""
    if not error_codes:
        return "[SENSOR PASS]: All architectural contracts satisfied."
    return "\n".join(REMEDIATION_GUIDE_MAP[e] for e in error_codes if e in REMEDIATION_GUIDE_MAP)

4. Practical Takeaway: Never Deploy a Sensor Without a Paired Remediation Guide

  1. Guides without Sensors drift; Sensors without Guides thrash: Upfront documentation alone can be overlooked, while bare test failures without remediation hints force multi-turn guesswork.
  2. Pair Guides & Sensors (E39) with Actionable Fix-Suggestion Linters (E17): Every custom linter or test sensor in your harness should output the exact target idiom alongside the error code.

🔗 Continue Reading the Series

來源:DEV Community · dev.to