<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Governance on KbWen Blog</title>
    <link>https://www.kbwen.com/tags/governance/</link>
    <description>KbWen 的個人技術部落格，分享 Python、機器學習、深度學習、資料工程與 AI 開發的學習筆記與實作心得。</description>
    <generator>Hugo</generator>
    <language>zh-tw</language>
    <image>
      <url>https://www.kbwen.com/images/og-default.png</url>
      <title>KbWen Blog</title>
      <link>https://www.kbwen.com/</link>
    </image>
    
    <lastBuildDate>Fri, 22 May 2026 20:00:00 +0800</lastBuildDate><atom:link href="https://www.kbwen.com/tags/governance/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>No evidence, no completion</title>
      <link>https://www.kbwen.com/no-evidence-no-completion-verification-principle/</link>
      <pubDate>Fri, 22 May 2026 20:00:00 +0800</pubDate><dc:creator>KbWen</dc:creator>
      <guid>https://www.kbwen.com/no-evidence-no-completion-verification-principle/</guid>
      <description>No evidence, no completion: the one rule that closes most AI agent failures. A task isn&amp;#39;t done until it produces a verifiable artifact (commit SHA, test output).</description>
      <content:encoded><![CDATA[<blockquote>
<p><strong>TL;DR:</strong> &ldquo;No evidence, no completion&rdquo; is a single structural principle: a task isn&rsquo;t done until the agent produces an artifact that exists outside the conversation and can be checked independently. It sounds trivial. In practice it closes most of the common agent failure modes in one rule, because the act of specifying what evidence looks like, before the task runs, forces you to define what &ldquo;done&rdquo; actually means.</p>
</blockquote>
<hr>
<p>In the <a href="/why-ai-agents-fail-without-governance/">previous post in this series</a> I described an agent that said a feature was done (commit SHA requested, none existed, two of three modules unchanged). The failure had a name: no external completion criterion existed, so the agent supplied its own. That gap has a one-rule fix.</p>
<hr>
<h2 id="what-evidence-means-here">What &ldquo;evidence&rdquo; means here</h2>
<p>Evidence is any artifact that exists outside the conversation and can be verified independently of what the agent said.</p>
<p>A commit SHA is evidence. A test output is evidence. A file path with a checksum is evidence. A screenshot of a passing CI run is evidence.</p>
<p>&ldquo;I implemented it&rdquo; is not evidence. &ldquo;The feature is working&rdquo; is not evidence. A description of what the agent did is not evidence: it&rsquo;s the agent&rsquo;s own assessment of its work, which is exactly what you&rsquo;re trying to verify.</p>
<p>The distinction matters because conversation text is not auditable. It exists only within the session, can&rsquo;t be pointed to by anyone who wasn&rsquo;t there, and doesn&rsquo;t prove the underlying state of the system. An artifact external to the conversation can be checked at any time, by anyone, against the actual state.</p>
<hr>
<h2 id="why-one-rule-covers-so-much">Why one rule covers so much</h2>
<p><a href="/why-ai-agents-fail-without-governance/">The first post in this series</a> catalogued five structural gaps: no completion criterion, no phase gate, no state handoff, no resource scoping, no capability boundary. The evidence principle doesn&rsquo;t replace all of them, but it forces the most important one: you cannot specify what evidence looks like without first deciding what &ldquo;done&rdquo; means.</p>
<p>If the evidence for a feature task is &ldquo;passing tests + commit SHA on the feature branch,&rdquo; you&rsquo;ve implicitly defined the completion criterion, the scope boundary (the feature branch, not the main codebase), and a checkpoint for the phase gate. The evidence requirement is the handle that pulls the rest of the structure into place.</p>
<p>This is why <a href="/ai-agent-governance-distributed-systems-prior-art/">the distributed systems framing</a> maps so cleanly: delivery acknowledgment in a message queue is exactly this pattern. The queue doesn&rsquo;t trust the worker&rsquo;s internal state; it requires an external signal that the job completed. Decades of production systems run on that principle because systems without it fail in the same predictable way.</p>
<hr>
<h2 id="before-the-task-not-after">Before the task, not after</h2>
<p>The principle works when it&rsquo;s applied before the task starts, not as a review step after.</p>
<p>&ldquo;What would prove this is done?&rdquo; asked before the work begins forces a design decision. It&rsquo;s not a check on the agent — it&rsquo;s a check on the task specification. If you can&rsquo;t answer it, the task isn&rsquo;t specified well enough to run. If you can answer it but the answer is vague (&ldquo;the feature works&rdquo;), the vagueness is in your specification, not in the agent&rsquo;s execution.</p>
<p>This is the mechanism <a href="https://blog.thepete.net/blog/2025/05/22/why-your-ai-coding-assistant-keeps-doing-it-wrong-and-how-to-fix-it/">Pete Hodgson&rsquo;s analysis of AI coding tools</a> points toward: when a problem has many valid solutions, the agent will pick one. That one will probably be valid. It probably won&rsquo;t be the one you wanted. Specifying evidence before the task runs is a way of narrowing the solution space — the agent&rsquo;s output has to satisfy the evidence criterion, which eliminates the paths that don&rsquo;t.</p>
<p>In practice: &ldquo;implement email verification&rdquo; with no evidence criterion produces one kind of output. &ldquo;Implement email verification — done when: (1) tests pass for OTP generation and expiry, (2) commit SHA on feat/email-verification&rdquo; produces a different one. Same model. Different structure around it.</p>
<hr>
<h2 id="what-good-evidence-looks-like">What good evidence looks like</h2>
<p>Evidence should be:</p>
<p><strong>External to the conversation.</strong> It can be retrieved or verified by someone who wasn&rsquo;t in the session. A commit SHA can be looked up. A test output can be reproduced. A URL can be visited.</p>
<p><strong>Specific enough to be falsifiable.</strong> &ldquo;Tests pass&rdquo; is weaker than &ldquo;running <code>npm test</code> returns exit 0 with 47 tests passing.&rdquo; The second can be false in a way that &ldquo;tests pass&rdquo; can&rsquo;t — which is the point. If the evidence criterion can&rsquo;t be falsified, it&rsquo;s not doing the work.</p>
<p><strong>Proportional to the task.</strong> A one-line bug fix doesn&rsquo;t need a full audit trail. The evidence for a tiny fix is the commit SHA and a grep confirming the old string is gone. The evidence for a feature touching auth, API, and database schema is more involved: test output, migration SHA, API contract diff. The Agentic OS framework classifies tasks before they run partly to route to the appropriate evidence format: a quick-win task and an architecture-change task need different levels of proof.</p>
<hr>
<h2 id="the-cost-of-specifying-evidence">The cost of specifying evidence</h2>
<p>Specifying evidence costs something up front. It takes maybe two minutes to think through &ldquo;what would prove this is done&rdquo; before a task starts. That&rsquo;s real overhead.</p>
<p>The comparison is with recovery cost. A governance failure (completing a task that didn&rsquo;t actually complete, or completing it the wrong way) typically costs: discovering the error, rebuilding context, rerunning the work, and auditing scope. None of those costs are bounded. The two minutes up front is.</p>
<p>The <a href="https://github.com/KbWen/agentic-os">Agentic OS v1.1 benchmark</a> (April 2026, using <code>chars/4</code> as the token estimation formula, ±10%) measured governance overhead for a quick-win task at roughly 17,000 tokens: the cost of the full structured lifecycle, evidence requirement included. For a complex feature spanning API design, auth, and database schema, it&rsquo;s around 51,000 tokens. Those numbers are real costs. They&rsquo;re also the ceiling. The cost of an undetected wrong completion has no ceiling — it depends on when you find it and how much work built on top of it.</p>
<hr>
<h2 id="the-question-to-ask-before-your-next-task">The question to ask before your next task</h2>
<p>Before you give an agent its next task: what artifact would prove this is done?</p>
<p>Not &ldquo;what would it mean to be done&rdquo; — that&rsquo;s vague enough for the agent to fill in. What specific artifact, external to the conversation, would you point to afterward and say: here is the evidence this completed correctly.</p>
<p>If you have an answer, you have a completion criterion. If you don&rsquo;t, you&rsquo;re delegating the definition of &ldquo;done&rdquo; to the agent. It will define one. It almost never matches yours.</p>
<p><em>This post is part of a series on building real AI systems. The previous posts cover the <a href="/why-ai-agents-fail-without-governance/">two-failure taxonomy</a> and the <a href="/ai-agent-governance-distributed-systems-prior-art/">distributed systems prior art</a> that motivates the evidence requirement. The framework is open source at <a href="https://github.com/KbWen/agentic-os">github.com/KbWen/agentic-os</a>.</em></p>
]]></content:encoded>
    </item>
    
    <item>
      <title>Prior art: what distributed systems already knows</title>
      <link>https://www.kbwen.com/ai-agent-governance-distributed-systems-prior-art/</link>
      <pubDate>Fri, 22 May 2026 16:00:00 +0800</pubDate><dc:creator>KbWen</dc:creator>
      <guid>https://www.kbwen.com/ai-agent-governance-distributed-systems-prior-art/</guid>
      <description>AI agent governance maps onto distributed systems patterns: audit logs, delivery acknowledgment, idempotency, least privilege. The prior art already exists.</description>
      <content:encoded><![CDATA[<blockquote>
<p><strong>TL;DR:</strong> The governance problems that make AI agents unpredictable (unverified completions, state loss between sessions, unconstrained scope) are structurally identical to problems distributed systems engineering solved with audit logs, delivery acknowledgment, state machines, and least-privilege access. The one genuine difference is non-determinism: an agent given the same open-ended task twice will do something different, which means governance needs to front-load constraints rather than just catch failures after. But the rest of the pattern library applies directly.</p>
</blockquote>
<hr>
<p>If you have built a message queue, you have hit a version of this bug: a worker picks up a job, does the work, then fails before sending the acknowledgment. The queue marks it undelivered. The job runs again. Now you have a duplicate record, a double email, or worse, depending on what &ldquo;the job&rdquo; was.</p>
<p>The fix is well-understood: require the worker to produce evidence of completion that the system can verify externally. Don&rsquo;t trust the worker&rsquo;s internal state. Trust the artifact.</p>
<p>When an AI agent says &ldquo;done&rdquo; and you have no artifact to check against, that&rsquo;s the same design gap. <a href="/why-ai-agents-fail-without-governance/">The previous post in this series</a> has a concrete example: the agent said the feature was done, I asked for the commit SHA, there wasn&rsquo;t one, and two of the three modules it described implementing hadn&rsquo;t changed. A capability failure looks like wrong reasoning. This was neither: the agent completed exactly what it was given, through its own completion criterion, because no external one existed. The fix is in the surrounding structure.</p>
<p>Distributed systems already solved the worker-reliability problem. The patterns map directly.</p>
<hr>
<h2 id="what-agent-execution-looks-like-from-the-outside">What agent execution looks like from the outside</h2>
<p>Strip the language model out for a moment. What&rsquo;s left?</p>
<p>A task arrives. A worker picks it up, performs operations, and signals completion. The orchestrator decides what to do next.</p>
<p>Standard async task pipeline. The governance questions are the same ones distributed systems have always asked: Did the work actually happen? What state is the system in now? What was the worker allowed to touch?</p>
<p>The answers (delivery acknowledgment, audit logs, state machines, capability sandboxing) aren&rsquo;t novel. They exist because systems without them fail in predictable, documented ways. Agent deployments running without that structure encounter the same failure modes.</p>
<hr>
<h2 id="the-pattern-mapping">The pattern mapping</h2>
<table>
  <thead>
      <tr>
          <th>Distributed systems pattern</th>
          <th>Agent governance equivalent</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Delivery acknowledgment</td>
          <td>Every task completion requires an external verifiable artifact: commit SHA, test output, file path</td>
      </tr>
      <tr>
          <td>Idempotency key</td>
          <td>Task dispatch is deduplicated: same task classified and scoped the same way, regardless of retry</td>
      </tr>
      <tr>
          <td>Audit log / event sourcing</td>
          <td>Work Log: decisions recorded at the time they happen, not reconstructed from memory later</td>
      </tr>
      <tr>
          <td>State machine with explicit transitions</td>
          <td>Phase gate: plan before implementing, review before shipping, with real entry/exit conditions</td>
      </tr>
      <tr>
          <td>Least privilege / capability sandbox</td>
          <td>Agent&rsquo;s tool access scoped to what the specific task requires, not everything available</td>
      </tr>
      <tr>
          <td>Resource quota</td>
          <td>Task classification that routes work to an appropriately sized execution path before it begins</td>
      </tr>
  </tbody>
</table>
<p>The <a href="https://github.com/KbWen/agentic-os">Agentic OS framework</a> is essentially this table implemented as a working system, not because it invented these patterns, but because building it kept arriving at the same structural answers distributed systems already had. The evidence requirement feels new until you recognize it as a CI gate. The work log feels novel until you recognize it as event sourcing. The insight isn&rsquo;t original; it&rsquo;s just overdue.</p>
<hr>
<h2 id="the-one-place-the-analogy-breaks">The one place the analogy breaks</h2>
<p>Distributed systems assume deterministic workers. Same input, same output, retry is safe.</p>
<p>Agents aren&rsquo;t deterministic, at least not for open-ended tasks. The same prompt, the same tools, the same context: execution goes somewhere different. Sometimes better. Often just different. For well-scoped sub-tasks (&ldquo;run these tests and report failures,&rdquo; &ldquo;format this JSON to this schema&rdquo;), retry still works fine. But for the tasks where governance matters most (feature implementation, refactoring decisions, scope-touching work), retry isn&rsquo;t a recovery strategy; it&rsquo;s another roll.</p>
<p>This is what <a href="https://blog.thepete.net/blog/2025/05/22/why-your-ai-coding-assistant-keeps-doing-it-wrong-and-how-to-fix-it/">Pete Hodgson&rsquo;s analysis of AI coding tools</a> points toward: when a problem has many valid solutions, the probability that an agent independently lands on the one you wanted approaches zero. The governance implication is that task decomposition is itself a governance act. Break work into pieces small enough that non-determinism is contained. Then front-load the constraints on the pieces that remain open-ended: define what &ldquo;done&rdquo; means, specify which files are in scope, classify the task before the first tool call.</p>
<p>The circuit breaker in distributed systems stops a cascade after failures accumulate. The agent equivalent is not letting the cascade start.</p>
<hr>
<h2 id="where-to-instrument">Where to instrument</h2>
<p>Distributed systems tell you to instrument at the transition points: message intake, worker pickup, task completion, downstream dispatch. These are where state changes happen and where failures manifest.</p>
<p>The agent equivalent:</p>
<ul>
<li><strong>Task intake</strong>: Is this classified correctly? What phase path follows? What tools does it need, and only those?</li>
<li><strong>Phase completion</strong>: What artifact exists to prove this phase is done? Is it external to the conversation?</li>
</ul>
<p>The third transition point is worth more than a bullet. <strong>Session boundary</strong> is the agent-specific failure mode that has no clean distributed-systems equivalent: it&rsquo;s closer to a stateless worker that loses its in-memory state and reprocesses from the queue head on restart. <a href="https://spectrum.ieee.org/ai-coding-degrades">An IEEE Spectrum report on AI coding tools</a> documented the pattern: in longer sessions, agents increasingly regenerated functions that already existed and ignored conventions established earlier. The fix is identical to the queue case: persistent state external to the worker. In agent terms: a work log that records decisions at the time they&rsquo;re made, so the next session inherits context instead of reconstructing it.</p>
<hr>
<h2 id="which-gaps-cost-the-most">Which gaps cost the most</h2>
<p>The distributed systems frame doesn&rsquo;t just explain why agent governance looks the way it does — it tells you which gaps cost the most.</p>
<p>Missing completion verification produces the cheapest failures: you find out fast. Missing scope constraints produce the expensive ones: the agent did three things you didn&rsquo;t ask for, two of which were correct, and now you&rsquo;re auditing which is which. Missing session state produces the hidden ones: the agent solved a problem you already solved, using a pattern you already decided against, because it had no way to know.</p>
<p>If you&rsquo;re choosing where to add structure first: start with scope. The task intake gate is the circuit breaker — it constrains what the agent can reach before it runs. The work log is the audit trail you need after something goes wrong. The completion artifact is the acknowledgment the queue was never getting.</p>
<p>Add them in that order.</p>
<p><em>This post is part of a series on building real AI systems. The previous post, <a href="/why-ai-agents-fail-without-governance/">Why AI Agents Go Wrong: It&rsquo;s Not the Model</a>, covers the capability vs. governance failure taxonomy that motivates this framing. Next: <a href="/no-evidence-no-completion-verification-principle/">No Evidence, No Completion</a> takes the evidence requirement as a standalone principle and shows what it looks like in practice. The framework is open source at <a href="https://github.com/KbWen/agentic-os">github.com/KbWen/agentic-os</a>.</em></p>
]]></content:encoded>
    </item>
    
    <item>
      <title>只用 Prompt 和技能，也能做到基本治理</title>
      <link>https://www.kbwen.com/ai-governance-with-prompts-and-skills/</link>
      <pubDate>Fri, 22 May 2026 14:00:00 +0800</pubDate><dc:creator>KbWen</dc:creator>
      <guid>https://www.kbwen.com/ai-governance-with-prompts-and-skills/</guid>
      <description>不用框架也能治理 AI 代理：靠 AGENTS.md / CLAUDE.md 記憶檔、evidence 習慣和範圍宣告，就能擋掉大部分 Claude Code、Cursor 的常見問題。</description>
      <content:encoded><![CDATA[<blockquote>
<p><strong>TL;DR：</strong> 在裝任何框架之前，有一層治理是免費的：在專案根目錄放一個 <code>AGENTS.md</code> 或 <code>CLAUDE.md</code>，養成開口要求 evidence 的習慣，開始任務前先說清楚什麼不能動。這三件事不能替代跨 session 的狀態管理，但能擋掉大部分常見問題。這篇說的就是怎麼做、做到什麼程度、在哪裡會失效。</p>
</blockquote>
<p>有一段時間我的 Claude Code 工作流裡沒有任何框架，只有對話和一堆臨時 prompt。某天我做了兩個改變：把專案的架構決策寫進一個 <code>CLAUDE.md</code>，還有在每次 AI 說「好了」的時候問一句「commit SHA 是什麼？」</p>
<p>一類問題幾乎消失了：AI 在新 session 裡對著不存在的設計模式寫程式碼的情況，以及我接受了「完成」卻發現什麼都沒變的情況。不是所有問題都解決了。但那兩件事的性價比，讓我後來開始認真想「在裝框架之前，這個層面的治理到底能做多少」。</p>
<p>這篇是<a href="/ai-agent-common-pitfalls-and-fixes/">AI 代理常見痛點與我們的嘗試</a>的延伸。那篇列了五個反覆出現的問題，這篇專門回答：只靠 prompt 習慣和 skill 選擇，能解決多少？</p>
<h2 id="記憶檔案解決跨-session-失憶的最低成本方案">記憶檔案：解決跨 session 失憶的最低成本方案</h2>
<p>AI 代理在每一個新對話都是空白狀態。它不記得上次的架構決策，不記得你說過不要用哪個 pattern，也不記得你已經有一個 <code>utils/auth.ts</code>，所以它再寫一個新的。這個問題在 <a href="https://spectrum.ieee.org/ai-coding-degrades">IEEE Spectrum 的報導</a>裡有量測數據：長 session 後期，AI 重複生成已存在函式、忽視早期建立的 coding convention 的頻率明顯上升。</p>
<p>三個工具在試圖解決同一個問題：</p>
<p><strong><code>AGENTS.md</code></strong> 是 OpenAI Codex 最初設計的慣例，後來被 Cursor、GitHub Copilot 和 Google Antigravity 等主流工具廣泛採納。它的設計邏輯是：在任何工具讀取它之前，先告訴工具「這個專案是怎麼運作的、你可以做什麼、不可以做什麼」。</p>
<p><strong><code>CLAUDE.md</code></strong> 是 Anthropic 針對 Claude Code 的版本。Claude Code 在每個新 session 開始時自動注入這個檔案的內容，所以你放在這裡的東西就等於是每次都在對話開頭重新說一遍。</p>
<p><strong><code>.cursor/rules</code></strong> 是 Cursor 的對應物。原理相同。</p>
<p>這三個慣例同時存在，說明「怎麼讓 AI 記住專案規則」這個問題是通用的，不是某個工具特有的。選哪個取決於你主要用什麼工具，你不需要三個都放，放一個就有效果。</p>
<p>這類記憶檔案最有用的內容通常是三類：架構限制（「這個 repo 用 Repository pattern，不要把業務邏輯寫進 controller」）、命名規範（「service 命名用 <code>XxxService</code>，不要用 <code>XxxManager</code>」）、以及「不要碰」清單（「<code>/database/migrations</code> 只有在明確被要求的時候才能動」）。</p>
<p>一個重要的注意：這類檔案要短。研究觀察和實踐都指向同一個上限：<strong>200 行、2000 token 以內</strong>。超過這個長度，重要的規則會被稀釋。AI 技術上還是讀了整個檔案，但前面讀到的東西到後面已經注意力不足。寫 <code>CLAUDE.md</code> 的時候，如果你覺得需要加第六條規則，先問自己第一條能不能刪掉。</p>
<h2 id="skill-選擇要求愈具體干擾愈少">Skill 選擇：要求愈具體，干擾愈少</h2>
<p>在 Claude Code 或 Cursor 的一次工作 session 裡，你可以載入很多 context：整個 codebase 的 README、過去的對話歷史、多個技能文件。但「載入愈多愈好」是個陷阱。</p>
<p>一個改一行 typo 的任務，不需要知道整套測試策略、部署規範和 API 設計原則。把這些全部塞進 context，不會讓 AI 更謹慎，只會讓它在「哪些規則現在適用」這件事上分配更少的注意力給真正重要的那個。</p>
<p>這不是 Agentic OS 特有的問題，是任何 Claude Code 或 Cursor session 都存在的情況。具體做法是：開始一個任務之前，先想清楚這個任務需要知道什麼，然後只提供那些。一個 tiny-fix 說「這是那行 code，幫我修」就夠了；一個涉及多個模組的功能開發才需要交代設計模式、測試策略和資料庫規範。</p>
<p>結果是給了 AI 密度更高的相關資訊，不是更少的資訊。</p>
<h2 id="evidence-習慣不問則不說">Evidence 習慣：不問則不說</h2>
<p>這是成本最低的一個改變，也是讓我最驚訝的一個。</p>
<p>AI 說「完成了」的時候，它有可能真的完成了，也有可能完成了 90% 然後遇到小問題就繞過去了，也有可能整個理解方向就錯了。這三種情況在它的輸出裡，有時候看起來幾乎一樣。</p>
<p>養成一個習慣：在接受任何「完成」之前，要求一個具體的 artifact。</p>
<p>不是一個表單，也不是一套流程，就一句話：「commit SHA 是什麼？」「把 test 跑一遍，貼輸出給我」「你改了哪個檔案，第幾行？」</p>
<p>這個習慣有效的原因不只是讓你可以查。<strong>問這個問題本身會讓 AI 把它沒說清楚的地方說出來。</strong> 很多時候，我問「測試有過嗎」，它才會說「啊，那個測試我還沒跑，因為 X 的 setup 有問題」，而這個資訊如果我沒問，它可能就默默略過了。</p>
<p>誠實地說：這個習慣很累。問了十幾次之後你開始理解為什麼人們想要自動化這件事，框架裡的 evidence gate 就是把這個問答自動執行。但作為一個習慣，它能擋掉大概六七成的「接受了看起來完成的東西、後來發現沒有」的情況。</p>
<h2 id="範圍宣告先說不要碰什麼">範圍宣告：先說不要碰什麼</h2>
<p>開始一個複雜任務之前，明確告訴 AI 它應該不要碰什麼。</p>
<p>具體的說法比模糊的說法有效：「你在做 authentication module。除非我明確說，不要碰 <code>/api/payments</code> 和 <code>/database/migrations</code> 底下的任何東西」比「專注在 auth 就好」有用得多。</p>
<p>原因不完全是「AI 會遵守」，它不是每次都遵守。而是宣告了邊界之後，<strong>AI 在不確定的時候開始問問題而不是自己決定</strong>。我給了這樣的指令之後，在它原本會直接去改 payments module 的地方，它變成問我「這邊需要我更新 payment 的驗證邏輯嗎？」——這個轉變很有價值。</p>
<p>這個觀察跟 Pete Hodgson <a href="https://blog.thepete.net/blog/2025/05/22/why-your-ai-coding-assistant-keeps-doing-it-wrong-and-how-to-fix-it/">對 AI coding assistant 失效模式的分析</a>有直接的關係：當一個問題存在很多可能的解法，AI 選中你心目中那個的機率趨近於零。把解法空間縮小（也包括把「不能碰的部分」明確劃出來），大幅提高了它走向你要的方向的機率。這是流程問題，跟模型能力無關。</p>
<p>在<a href="/beyond-prompt-from-instructions-to-building-systems/">從「下指令」到「蓋系統」</a>裡，我說過「AI 只活在那一次的對話框裡」。宣告範圍是在這個限制之內，盡量讓它知道那個對話框的邊界在哪裡。</p>
<h2 id="這個層面的治理做到什麼做不到什麼">這個層面的治理做到什麼、做不到什麼</h2>
<p>做得到的：讓 AI 在新 session 裡記得你的架構決策（記憶檔案）。讓它在不確定的時候問你而不是自己做決定（範圍宣告）。讓你在接受輸出之前有一個具體的查核點（evidence 習慣）。把技能文件控制在合理長度，避免注意力被稀釋（skill 選擇）。</p>
<p>做不到的是跨 session 的連貫狀態。記憶檔案解決的是「規則記得住」的問題，不是「上次做到哪裡」的問題。如果你的任務橫跨多個 session，每次開始你還是要手動交代背景——或者接受 AI 從頭重推一遍。Evidence 習慣的疲勞感也是真實的：問個五十次之後，你會想要自動化。這不是壞事——這是你已經知道在哪裡需要更正式的結構的訊號。範圍宣告在複雜任務下同樣會降解，涉及的模組愈多，「先說不要碰什麼」就愈難窮舉。</p>
<p>這個層面的治理是真實的，不是「沒有框架的窮人版」。但它有天花板。當你開始覺得每次的 context 交接很重複、evidence 問答讓你厭倦、範圍宣告的清單比任務本身還長——那就是你已經碰到這個層面的邊界了。</p>
<p>下一篇：<a href="/work-log-cross-session-continuity/">Work Log：跨 session 的記憶機制</a></p>
<p><em>Agentic OS 是開源專案，記憶檔案的範本和設計說明都在這裡：<a href="https://github.com/KbWen/agentic-os">github.com/KbWen/agentic-os</a></em></p>
]]></content:encoded>
    </item>
    
    <item>
      <title>Why AI Agents Go Wrong: It&#39;s Not the Model</title>
      <link>https://www.kbwen.com/why-ai-agents-fail-without-governance/</link>
      <pubDate>Fri, 22 May 2026 12:00:00 +0800</pubDate><dc:creator>KbWen</dc:creator>
      <guid>https://www.kbwen.com/why-ai-agents-fail-without-governance/</guid>
      <description>Why AI agents fail: most agent failures aren&amp;#39;t model problems, they&amp;#39;re governance problems, and the two need completely different fixes. How to tell them apart.</description>
      <content:encoded><![CDATA[<blockquote>
<p><strong>TL;DR:</strong> &ldquo;The agent did something wrong&rdquo; usually gets diagnosed as a model problem. Most of the time it isn&rsquo;t. Capability failures (wrong reasoning) and governance failures (no structure to catch wrong reasoning) look identical from the outside but need completely different fixes. This post is about telling them apart, and why most teams are currently solving the wrong one.</p>
</blockquote>
<hr>
<p>The agent said the feature was done. I asked for the commit SHA. There wasn&rsquo;t one. When I checked the branch, two of the three modules it described implementing hadn&rsquo;t changed.</p>
<p>The instinct in that moment is to reach for a better prompt, a smarter model, maybe a different tool call. That instinct is usually wrong.</p>
<p>What happened wasn&rsquo;t a reasoning failure. The agent completed exactly the task it was given, interpreted through its own completion criterion, because no explicit one existed. There was no audit trail to check what it actually did. There was no scope boundary to constrain what &ldquo;done&rdquo; even meant. The model behaved correctly inside a system that gave it no structure to behave <em>correctly toward</em>.</p>
<p>That&rsquo;s a governance failure, not a capability failure. And the fix is not a better model.</p>
<hr>
<h2 id="two-failure-modes-that-look-the-same">Two failure modes that look the same</h2>
<p>When an agent produces bad output, the failure is almost always categorized as one thing: the AI got it wrong. Which leads to one solution category: better AI.</p>
<p>The problem is that &ldquo;the AI got it wrong&rdquo; conflates two distinct failure modes that have nothing to do with each other.</p>
<p><strong>Capability failure:</strong> the model reasoned incorrectly. It missed a constraint, hallucinated a fact, drew a wrong inference. The fix lives in the model layer: better prompt, better retrieval, better fine-tuning, sometimes a more capable model.</p>
<p><strong>Governance failure:</strong> the system had no invariant to catch or prevent what the agent did. The agent may have reasoned perfectly well and still produced a wrong outcome, because the surrounding structure gave it nothing to constrain against.</p>
<p>There&rsquo;s a useful diagnostic test: <em>would a smarter model have prevented this?</em></p>
<p>If yes, if the failure was clearly about incorrect reasoning or a factual miss, that&rsquo;s a capability failure.</p>
<p>If no, if a brilliant expert given the same underspecified task would have made the same wrong choice, or a different wrong choice, because the task itself had no defined success condition. That&rsquo;s a governance failure. Upgrading the model doesn&rsquo;t help.</p>
<p>Most of the &ldquo;unpredictable agent&rdquo; complaints I&rsquo;ve seen are governance failures. The problem gets framed as model unreliability because that&rsquo;s what&rsquo;s visible. The actual cause is invisible: the absence of structure.</p>
<hr>
<h2 id="the-five-structural-gaps">The five structural gaps</h2>
<p>These are the governance gaps that show up repeatedly, not as edge cases, but as the default state of most agent deployments. The zh-TW companion post <a href="/ai-agent-common-pitfalls-and-fixes/">AI 代理常見痛點與我們的嘗試</a> goes deeper on each one with narrative examples. Here I want to name the structural invariant that&rsquo;s missing in each case.</p>
<p><strong>Output not verifiable → no completion criterion or audit trail.</strong>
The agent says &ldquo;done.&rdquo; You have no artifact to check against. The agent&rsquo;s word that something happened is not evidence that it happened. The missing invariant: every task completion requires an attached evidence artifact: a file path, a commit SHA, a test result, something external to the conversation.</p>
<p><strong>Steps skipped → no phase gate.</strong>
Given a complex task, agents move toward output by the shortest path. Scope-setting, dependency mapping, impact analysis (anything that doesn&rsquo;t look like &ldquo;doing the thing&rdquo;) gets skipped. The missing invariant: phases with entry and exit conditions that must be satisfied before proceeding. Pete Hodgson has written about this from an angle worth noting: when a problem has many valid solutions, the probability that an agent independently arrives at the one you actually wanted approaches zero. Pre-alignment isn&rsquo;t overhead. It&rsquo;s the phase gate that prevents redoing work.</p>
<p><strong>Cross-session amnesia → no state handoff mechanism.</strong>
Every new conversation is a blank slate. Decisions made in session one are unknown in session two. The agent rediscovers problems you&rsquo;ve already solved, proposes patterns you&rsquo;ve already rejected, rebuilds context you&rsquo;ve already paid to build. An IEEE Spectrum report on AI coding tools documented this concretely: in longer sessions, agents increasingly regenerated functions that already existed and ignored conventions established earlier in the same session. The missing invariant: a structured work log that carries decisions forward across session boundaries. The mechanism we use is stupid-simple. It&rsquo;s essentially forcing the agent to keep a diary. That description isn&rsquo;t flattering, but cross-session amnesia is real enough that stupid-simple works.</p>
<p><strong>Unbounded token cost → no resource scoping.</strong>
An agent given a large task will read everything it can find, activate every relevant capability, and use as much context as the task allows it to justify. Without resource scoping, costs are unpredictable and you have no way to set expectations before a task starts. The missing invariant: task classification that routes to appropriately sized execution paths before the task begins.</p>
<p><strong>Scope creep → no capability boundary.</strong>
This is the quietest failure mode. The agent does what you asked, and also reorganizes a module you didn&rsquo;t ask it to touch, and also &ldquo;helpfully&rdquo; updates a config file while it was in the neighborhood. Security researcher Johann Rehberger (Embrace the Red) made this failure mode concrete in April 2025 when he spent $500 testing Devin AI&rsquo;s response to embedded instructions in GitHub issues, then reported the results to Cognition: 84–85% of attacks succeeded in getting the agent to execute actions outside the intended scope. That&rsquo;s an extreme case, but the everyday version of this (the agent quietly expanding what &ldquo;done&rdquo; means) is the same structural gap. The missing invariant: explicit capability boundaries that define what the agent is allowed to do, not just what it&rsquo;s been asked to do.</p>
<p>None of these gaps are model problems. A more capable model, given the same absent structure, makes the same category of errors, just more convincingly.</p>
<hr>
<h2 id="engineering-already-solved-these-problems">Engineering already solved these problems</h2>
<p>These aren&rsquo;t new problems with new solutions. They&rsquo;re old problems that software engineering solved decades ago, applied to a different execution substrate.</p>
<table>
  <thead>
      <tr>
          <th>Governance gap</th>
          <th>Engineering equivalent</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>No completion criterion</td>
          <td>CI gate: no merge without passing checks</td>
      </tr>
      <tr>
          <td>No phase gate</td>
          <td>PR review requirement: code doesn&rsquo;t ship without sign-off</td>
      </tr>
      <tr>
          <td>No state handoff</td>
          <td>Audit log / ADR: decisions are recorded, not reconstructed</td>
      </tr>
      <tr>
          <td>No resource scoping</td>
          <td>Budget / SLA: bounded cost before work starts</td>
      </tr>
      <tr>
          <td>No capability boundary</td>
          <td>Principle of least privilege: access limited to what the task requires</td>
      </tr>
  </tbody>
</table>
<p>The analogy isn&rsquo;t decorative. These are the same structural mechanisms. Building the evidence requirement for <a href="https://github.com/KbWen/agentic-os">Agentic OS</a>, I kept writing things that felt novel until I realized I was describing CI gates and audit logs with different names. The insight wasn&rsquo;t new. It was just late.</p>
<p>A CI gate doesn&rsquo;t trust the developer&rsquo;s word that the tests pass. It requires evidence. An audit log records decisions at the time they&rsquo;re made, so they don&rsquo;t need to be reconstructed from memory later. Least privilege limits what an agent can touch, not out of distrust, but to contain the blast radius when something goes wrong.</p>
<p>The AGENTS.md convention, now adopted across Claude Code, Cursor, and GitHub Copilot as a standard way for agents to load project context, is essentially a machine-readable project governance document. It&rsquo;s the same idea as a team&rsquo;s architecture decision record, but in a format the agent reads automatically. That&rsquo;s not a coincidence. It&rsquo;s the same structural need surfacing in a new context.</p>
<p>What&rsquo;s missing in most agent deployments isn&rsquo;t better AI. It&rsquo;s the application of mechanisms that software engineering already knows work.</p>
<hr>
<h2 id="what-governance-actually-costs">What governance actually costs</h2>
<p>&ldquo;Adding structure&rdquo; sounds like adding overhead. It&rsquo;s worth being concrete about the actual numbers.</p>
<p>We measured governance overhead across several task types in Agentic OS v1.1 (April 2026, using <code>chars/4</code> as the token estimation formula; actual counts vary by ±10% depending on tokenizer). For a quick-win task (something like fixing a date format in a CSV export), the governance overhead came to <strong>17,041 tokens</strong>. For a complex feature touching API design, authentication, and database schema, it came to <strong>50,975 tokens</strong>.</p>
<p>Those numbers sound large until you compare them to the cost of an ungoverned failure. A governance failure typically means: an undetected wrong completion that gets discovered later, a context restart, redone work, and scope cleanup. None of those costs are bounded or predictable.</p>
<p>The governance overhead is bounded. It scales with task complexity in a predictable way: the lightest path costs roughly 17K tokens; the heaviest measured scenario costs under 62K. The cost of recovering from a scope error or a missed completion criterion is not bounded. It depends on when you find it.</p>
<p>This isn&rsquo;t an argument for any particular framework. It&rsquo;s an argument for the structure itself: known, upfront cost versus unbounded, discovery-time cost. That trade-off is the same one CI gates resolved for software deployment twenty years ago.</p>
<hr>
<h2 id="the-question-to-ask-before-the-task-starts">The question to ask before the task starts</h2>
<p>None of this requires a framework. The diagnostic test at the task level is simpler than that.</p>
<p>Before your next agent task: what artifact would prove this is done?</p>
<p>Not &ldquo;what would it mean to be done.&rdquo; That&rsquo;s vague enough that the agent will fill in the answer. What <em>artifact</em>, specifically, would you point to afterward and say: here is the evidence this completed correctly?</p>
<p>If you can answer that question before the task starts, you have a completion criterion. If you can&rsquo;t, you don&rsquo;t, and the agent will invent one. That invented criterion is almost never the one you wanted. The everyday version doesn&rsquo;t look like a security incident. It&rsquo;s an agent that quietly refactored a module you didn&rsquo;t mention, or updated a config file it found nearby. Its completion criterion included those things. Yours didn&rsquo;t.</p>
<p>That&rsquo;s the smallest possible governance structure. A definition of done, stated before work begins, tied to something observable.</p>
<p>The rest of the gaps (phase gates, state handoffs, resource scoping, capability boundaries) are the same logic applied at increasing scope. But they all start from the same place: deciding what &ldquo;done&rdquo; means before asking the agent to find out.</p>
<hr>
<p><em>These observations are from building and using Agentic OS v1.1 (April 2026). The field moves fast — if a model capability has improved or a pattern here no longer holds, I want to know. The framework is open source and the issues are open: <a href="https://github.com/KbWen/agentic-os">github.com/KbWen/agentic-os</a>.</em></p>
<p><em>This post is part of a series on building real AI systems. Related reading: <a href="/what-makes-an-ai-skill-different-from-a-prompt/">What Makes an AI Skill Different from a Prompt?</a> covers the capability abstraction layer that sits below agent orchestration. The zh-TW companion post <a href="/ai-agent-common-pitfalls-and-fixes/">AI 代理常見痛點與我們的嘗試</a> covers the same failure catalogue with more narrative depth. Both build on <a href="/beyond-prompt-from-instructions-to-building-systems/">Beyond Prompt: From Instructions to Building Systems</a>.</em></p>
]]></content:encoded>
    </item>
    
    <item>
      <title>AI 代理常見痛點與我們的嘗試</title>
      <link>https://www.kbwen.com/ai-agent-common-pitfalls-and-fixes/</link>
      <pubDate>Fri, 22 May 2026 10:00:00 +0800</pubDate><dc:creator>KbWen</dc:creator>
      <guid>https://www.kbwen.com/ai-agent-common-pitfalls-and-fixes/</guid>
      <description>AI 代理（AI Agent）開發常見問題整理：輸出難核查、跳步驟、跨對話失憶、範圍失控。從實戰痛點到 Agentic OS 的應對方向，附 Claude Code 實例。</description>
      <content:encoded><![CDATA[<blockquote>
<p><strong>TL;DR：</strong> AI 代理失控通常不是模型的問題，而是缺少足夠的結構。這篇整理了我們在實踐中觀察到的幾個痛點，以及 Agentic OS 試著用哪些方向來應對——不保證這是最好的做法，AI 工具本身也還在快速演化。</p>
</blockquote>
<p>如果你已經在用 Claude Code、Cursor 或 Copilot 一段時間，你大概知道那種感覺：有時候它快得讓你懷疑自己為什麼還要打字，但有時候你盯著它的輸出，心裡只有一個念頭——「等等，它在幹嘛？」</p>
<p>印象更深的往往是後者。我發現有幾類問題會反覆出現，跟你用哪個模型或哪個工具關係不大，比較像是讓 AI 代理參與真實開發這件事本身帶來的結構性挑戰。</p>
<p>如果你讀過<a href="/beyond-prompt-from-instructions-to-building-systems/">從「下指令」到「蓋系統」</a>，這篇可以看成那個思路的延伸——當你開始用 agent 做真實開發，「結構不夠」這件事的代價變得具體很多。</p>
<p>Agentic OS 是站在很多公開工作的肩膀上做出來的。<code>AGENTS.md</code> 這個慣例最初來自 OpenAI Codex 的設計，後來被 Cursor、GitHub Copilot 等主流 AI 工具廣泛採納；Anthropic 有自己的 <code>CLAUDE.md</code>；Cursor 有 <code>.cursor/rules</code>——各自代表不同工具對「怎麼讓 AI 記住專案規則」這個問題的嘗試。我們參考了這些設計，加上 Hacker News、Reddit 社群裡的實測討論，還有 Pete Hodgson、Addy Osmani、Thorsten Ball 等工程師整理的失效模式分析，試著把它們整合成一套對我們自己有用的東西。這個框架比較像是整合與實驗的產物，不是從零發明的。</p>
<h2 id="幾個反覆出現的痛點">幾個反覆出現的痛點</h2>
<p>以下整理自我們自己踩過的坑，也有部分來自社群的集體觀察。不是嚴謹的研究，是實踐者的筆記。</p>
<h3 id="輸出難以核查">輸出難以核查</h3>
<p>AI 完成任務後，你拿到的往往是一段文字說「已完成」或「功能已實作」。問題是「完成」的依據是什麼？在單一短對話裡這不是大問題，但一旦任務橫跨多個 session，或者事後需要追溯某個決策的來源，你往往什麼都找不到——沒有 commit SHA、沒有測試輸出、沒有可以指著說「它在這裡」的東西。只有對話紀錄，而對話紀錄不算數。</p>
<p>這個問題後來直接影響了我們的框架設計。Agentic OS 裡有一條規則：就算是「重讀同一份文件」這個動作，也必須留下一筆收據。聽起來很囉嗦，但沒有這個，「我讀過了」和「我沒讀過」在紀錄裡是完全一樣的。</p>
<h3 id="跳過中間步驟">跳過中間步驟</h3>
<p>給 AI 一個任務，它的自然傾向是直接往結果走。這在小任務上沒問題。但任務稍微複雜一點——比如需要同時異動前端、後端和資料庫——省掉的「先確認範圍」、「列出影響的模組」這些步驟，往往要在後面以更大的代價補回來。工程師 Pete Hodgson 在<a href="https://blog.thepete.net/blog/2025/05/22/why-your-ai-coding-assistant-keeps-doing-it-wrong-and-how-to-fix-it/">他的文章</a>裡提到，當一個問題有很多不同的解法時，AI 選到你心目中那個的機率趨近於零——提前對齊方向，跟模型能力無關，是流程問題。</p>
<h3 id="跨對話的連貫性">跨對話的連貫性</h3>
<p>在<a href="/beyond-prompt-from-instructions-to-building-systems/">那篇談 Prompt 局限的文章</a>裡，我說過 AI「只活在那一次的對話框裡」。這個限制在用 agent 做持續開發的時候感受更強烈。每次開新對話，你得重新交代背景：這個專案的架構決策是什麼、上次決定用哪種設計模式、之前踩過什麼坑。這不只是麻煩，而是會讓同樣的問題被重新發現、同樣的決策被重新討論。IEEE Spectrum 的<a href="https://spectrum.ieee.org/ai-coding-degrades">一篇報導</a>裡提到，AI 在長 session 的後期，出現重複生成已存在函式、忽視早期建立的 coding convention 等情況的頻率明顯上升——本質上是 context 稀釋的問題。</p>
<h3 id="資源使用的不確定性">資源使用的不確定性</h3>
<p>AI 代理讀文件、呼叫工具、產生輸出，這些都有成本，而且差距可以很大。我們在 Agentic OS v1.1 的 benchmark 裡（2026 年 4 月量測）跑了幾個真實場景：quick-win 等級任務（例如修一個 CSV 格式問題）實際消耗約 17,041 token；涵蓋 API、認證、資料庫的複雜功能開發則約 51,000 token，相差接近三倍。這些數字來自特定的任務類型與工具組合——我們用的估算公式是 <code>chars / 4</code>，接近多數 OpenAI tokenizer，但不完全一致——不同模型、context 策略下的結果可能差距顯著。</p>
<p>更複雜的是，這個計算現在又多了一層變數。主流模型——包括 Claude 和 OpenAI 的系列——已經有 prompt cache 機制，在某些條件下可以大幅降低重讀相同 context 的成本。這讓我們原本關於「怎麼控制 context 讀取策略」的很多設計假設需要重新檢視。我們還在觀察這個演變，舊的建議不一定還適用。</p>
<h3 id="範圍的模糊">範圍的模糊</h3>
<p>這類問題比較難描述，因為它不一定會報錯——它只是靜靜地做了你沒有要求它做的事。安全研究員 Johann Rehberger（筆名 Embrace the Red）花 $500 測試了 Devin AI 的 prompt injection 抵抗力，並於 2025 年 4 月將結果通報給 Devin 的開發商 Cognition。測試結果顯示透過 GitHub issue 嵌入惡意指令，可以讓 Devin 執行預期範圍以外的操作，整體攻擊成功率達 84–85%。這是極端的例子，但「AI 自己決定任務邊界」這件事的普通版本，每天都在發生——它只是偷偷多改了一個 config 檔，或者順手重構了你沒說要動的模組。</p>
<h2 id="我們試著做的事">我們試著做的事</h2>
<p>Agentic OS 的出發點，是試著在這些問題上加一些結構。主要思路有幾個方向：</p>
<p>我們把核心原則叫做 &ldquo;No Evidence = No Completion&rdquo;——想法本身不新奇，軟體工程裡的 CI/CD gate 做的就是這件事，只是把它搬到了 AI 代理的工作流程裡。每個任務的交付都要附帶某種形式的 evidence，不一定很複雜，但要有東西可以查。同時，根據任務的規模，要走的流程也不一樣：單行改動走輕量路徑；功能開發走比較完整的流程，包含計劃、實作、審查幾個階段。這個分層設計部分參考了 Anthropic 和 Cursor 社群分享的做法，調整成對我們自己比較實用的版本。</p>
<p><strong>用 Work Log 保持連貫性。</strong> 每個任務有一份對應的工作記錄，記關鍵決策和目前狀態，讓下一個 session 能接續而不是重來。這是個很笨的方法（基本上就是強迫 AI 寫日記），但在我們找到更好的方式之前，它目前還算有用。</p>
<p>至於資源分配，我們試著把不同分類的任務對應到不同的 skill 載入策略，不一次讀所有東西。不過如前面說的，model cache 機制的演進讓這部分的設計面臨一些調整，舊的策略不一定還有效。</p>
<h2 id="一些誠實的話">一些誠實的話</h2>
<p>這套框架有用，但不是沒有問題——有些設計現在回頭看也不一定是最好的決定，只是當時看起來合理。Addy Osmani 把這個現象稱為<a href="https://addyosmani.com/blog/the-70-problem/">「70% 問題」</a>：AI 能很快帶你到 70% 的完成度，但剩下的 30% 往往需要更多工程判斷力，不是更少。設計一套治理框架也一樣——結構能幫你避開很多坑，但它改變不了你還是需要做設計決策這件事。</p>
<p>AI 工具的演進速度，讓任何固化的解法都有保鮮期的問題。有些我們在設計時試圖解決的問題，現在模型本身可能已經部分處理了；反過來，也有我們沒預想到的新狀況冒出來。我們把 Agentic OS 定位為一個持續演進的實驗，不是一個收斂的答案。這個系列會把框架的各個機制拆開來談。如果你也在摸索怎麼讓 AI 代理在實際開發工作裡更可控、更可追溯，希望有些地方能對你有參考價值。</p>
<p>下一篇：<a href="/ai-governance-with-prompts-and-skills/">只用 Prompt 和技能也能做好治理：實用技巧與範例</a></p>
<p><em>Agentic OS 是開源專案，歡迎看看我們怎麼實作，也歡迎指出你覺得不對的地方：<a href="https://github.com/KbWen/agentic-os">github.com/KbWen/agentic-os</a></em></p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
