Communitygithub.com

代理架構稽核

全端診斷 agent 與 LLM 應用程式。稽核 12 層代理堆疊中的包裝回歸、記憶污染、工具紀律失效、隱藏修復迴圈以及渲染損壞。產生依嚴重性排序的發現結果,並提供以程式碼為優先的修復建議。對於開發代理應用程式、自主迴圈或任何 LLM 驅動功能的開發者來說至關重要。當代理或 LLM 功能異常且無法確定問題層級時,或在發佈代理堆疊之前使用。

代理架構稽核 是什麼?

代理架構稽核(Agent Architecture Audit)是一個診斷性工作流程,旨在找出並修復包裝層、陳舊記憶、重試迴圈或傳輸/渲染變異所導致的代理系統隱藏故障。它系統性地檢查一個 12 層堆疊,包括系統提示詞、對話歷史、長期記憶與工具執行等,以定位根本原因。此技能對於在發佈 LLM 驅動功能、新增包裝層,或遭遇工具不穩定、輸出一致性逐週期下降等模糊行為問題的開發者,是強制性的。該工作流程首先確定稽核範圍、收集程式碼庫實證(使用 `rg` 尋找反模式),再將發現映射至特定層級,並提出以程式碼優先的修復策略(例如對工具要求進行程式碼閘控、移除隱藏修復代理)。它支援任何 agent 系統(如 Claude Code、Cursor、Codex 等),並產出結構化的 JSON 報告,內含依嚴重性排序的發現與可執行的修復計畫。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/agent-architecture-audit

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

代理架構稽核 是做什麼的?

一個診斷性工作流程,用於找出那些將故障隱藏在包裝層、陳舊記憶、重試迴圈或傳輸/渲染變異後方的代理系統。

何時啟用

對以下情況是強制性的:

  • 將任何代理或 LLM 驅動的應用程式發佈至正式環境
  • 發佈具備工具呼叫、記憶或多步驟工作流程的功能
  • 代理行為在新增包裝層後退化
  • 使用者回報「代理越來越糟」或「工具不穩定」
  • 同一個模型在 Playground 能正常運作,但在您的包裝層內卻故障
  • 花了超過 15 分鐘除錯代理行為,仍找不到根本原因

在以下情況尤其關鍵:

  • 您新增了提示詞層、工具定義或記憶系統
  • 您系統中的不同代理行為不一致
  • 模型昨天運作正常,今天卻開始產生幻覺
  • 您懷疑有隱藏的修復/重試迴圈在默默地變異回應

不要在以下情況使用:

  • 一般的程式除錯 — 請使用 agent-introspection-debugging
  • 程式碼審查 — 請使用與語言相關的審查代理
  • 安全掃描 — 請使用 security-review 或 security-review/scan
  • 代理效能基準測試 — 請使用 agent-eval
  • 撰寫新功能 — 請使用適當的工作流程技能

12 層堆疊

每個代理系統都有這些層級。其中任何一層都可能破壞答案的正確性:

#層級可能出錯的地方
1系統提示詞相互衝突的指令、指令臃腫
2對話歷史先前輪次的陳舊脈絡被注入
3長期記憶跨對話的污染,舊主題出現在新對話中
4提煉壓縮過的成品以偽事實的形式重新進入
5主動召回多餘的重新摘要層浪費脈絡
6工具選擇工具路由錯誤,模型跳過必要的工具
7工具執行幻覺式執行 — 聲稱已呼叫但實際未執行
8工具解讀誤讀或忽略工具輸出
9答案成形最終回應的格式損壞
10平台渲染傳輸層變異(UI、API、CLI 變更了正確的答案)
11隱藏修復迴圈靜默執行的備援/重試代理,進行第二次 LLM 傳遞
12持久化將過期的狀態或快取成品當作即時證據重複使用

常見的故障模式

1. 包裝回歸

基礎模型能產生正確答案,但包裝層讓它變得更糟。

症狀:

  • 模型在 Playground 或直接 API 呼叫時正常,但在您的代理中出錯
  • 新增了一個提示詞層後,現有行為退化
  • 代理聽起來很有自信,但卻是充滿自信的錯誤
  • 「上次更新之前明明是正常的」

2. 記憶污染

舊主題透過歷史、記憶檢索或提煉洩漏到新對話中。

症狀:

  • 代理提起無關的舊主題
  • 使用者的修正沒有被記住(舊記憶覆寫了新記憶)
  • 同一對話的成品以偽事實的形式重新進入
  • 記憶無限制增長,隨著時間降低回應品質

3. 工具紀律失效

工具雖然在提示詞中被宣告,但未在程式碼中強制執行。模型會跳過它們或幻覺其執行。

症狀:

  • 提示詞中有「必須使用工具 X」,但模型在未呼叫它的情況下回答了問題
  • 工具結果看起來正確,但實際上從未被執行
  • 不同的工具爭奪同一個責任
  • 模型在不該使用時使用工具,或在不該跳過時跳過工具

4. 渲染/傳輸損壞

代理的內部答案是正確的,但平台層在傳遞時對其進行了變異。

症狀:

  • 記錄顯示正確答案,使用者卻看到損壞的輸出
  • 有效的回應被 Markdown 渲染、JSON 解析或串流片段破壞
  • 隱藏的備援代理在傳遞前默默地替換了答案
  • 終端機與 UI 之間的輸出不一致

5. 隱藏代理層

靜默修復、重試、摘要或召回代理在沒有明確合約的情況下運行。

症狀:

  • 內部生成與使用者傳遞之間的輸出發生變化
  • 「自動修正」迴圈運行了使用者不知情的第二次 LLM 傳遞
  • 多個代理在沒有協調的情況下修改同一個輸出
  • 答案被不可見的層「平滑化」或「修正」

稽核工作流程

第一階段:範圍界定

定義您要稽核的內容:

  • 目標系統 — 哪個代理應用程式?
  • 進入點 — 使用者如何與它互動?
  • 模型堆疊 — 使用哪些 LLM 和提供者?
  • 症狀 — 使用者回報了什麼?
  • 時間窗口 — 何時開始發生的?
  • 要稽核的層級 — 12 層中的哪些層級適用?

第二階段:證據收集

從程式碼庫收集證據:

  • 原始碼 — 代理迴圈、工具路由器、記憶准入、提示詞組裝
  • 日誌 — 歷史對話追蹤、工具呼叫記錄
  • 設定 — 提示詞範本、工具結構描述、提供者設定
  • 記憶檔案 — 標準作業程序、知識庫、對話存檔

使用 rg 搜尋反模式:

# 僅在提示文字(非程式碼)中表達的工具要求
rg "must.*tool|必须.*工具|required.*call" --type md

# 未經驗證的工具執行
rg "tool_call|toolCall|tool_use" --type py --type ts

# 主代理迴圈外的隱藏 LLM 呼叫
rg "completion|chat\.create|messages\.create|llm\.invoke"

# 缺乏使用者修正優先權的記憶准入
rg "memory.*admit|long.*term.*update|persist.*memory" --type py --type ts

# 執行額外 LLM 呼叫的備援迴圈
rg "fallback|retry.*llm|repair.*prompt|re-?prompt" --type py --type ts

# 靜默輸出變異
rg "mutate|rewrite.*response|transform.*output|shap" --type py --type ts

第三階段:故障映射

對於每個發現,記錄:

  • 症狀 — 使用者看到了什麼
  • 機制 — 包裝層如何導致該問題
  • 來源層級 — 12 層中的哪一層
  • 根本原因 — 最深層的原因
  • 證據 — 檔案:行號 或 日誌:行號 參考
  • 信心水準 — 0.0 到 1.0

第四階段:修復策略

預設的修復順序(以程式碼為優先,而非提示詞):

  1. 程式碼閘控工具要求 — 在程式碼中強制執行,而非僅在提示文字中
  2. 移除或縮小隱藏修復代理 — 使用合約讓備援變得明確
  3. 減少脈絡重複 — 相同資訊同時透過提示詞 + 歷史 + 記憶 + 提煉傳遞
  4. 收緊記憶准入 — 使用者修正 > 代理斷言
  5. 收緊提煉觸發條件 — 不要壓縮不該被壓縮的內容
  6. 減少渲染變異 — 穿透傳遞,不要轉換
  7. 轉換為型別化 JSON 封包 — 結構化的內部流程,而非自由形式的散文

嚴重性模型

等級意義行動
critical代理可能自信地產生錯誤的操作行為下次發佈前修復
high代理頻繁地降低正確性或穩定性此衝刺週期內修復
medium正確性通常無恙,但輸出脆弱或浪費資源規劃下個週期處理
low主要是外觀或可維護性問題放入待辦清單

輸出格式

按以下順序向使用者呈現發現:

  1. 依嚴重性排序的發現(最關鍵的優先)
  2. 架構診斷(哪一層破壞了什麼,以及原因)
  3. 有序的修復計畫(以程式碼為優先,而非提示詞)

不要以讚美或摘要開頭。如果系統壞了,就直接說出來。

快速診斷問題

稽核代理系統時,回答以下問題:

#問題如果「是」→
1模型能否在跳過必要工具的情況下仍能回答?工具未進行程式碼閘控
2舊對話內容是否出現在新的對話輪次中?記憶污染
3相同的資訊是否同時存在於系統提示詞、記憶和歷史中?脈絡重複
4平台是否在傳遞之前運行了第二次 LLM 傳遞?隱藏修復迴圈
5內部生成與使用者傳遞之間的輸出是否不同?渲染損壞
6「必須使用工具 X」的規則是否僅存在於提示文字中?工具紀律失效
7代理自身的獨白是否可能成為持久記憶?記憶中毒

應避免的反模式

  • 避免在未排除包裝層回歸之前就先責怪模型。
  • 避免在未顯示污染路徑之前就先責怪記憶。
  • 不要讓乾淨的當前狀態抹去骯髒的歷史事件。
  • 不要將 Markdown 散文視為可信任的內部協定。
  • 當程式碼從未強制執行時,不要接受提示文字中的「必須使用工具」。
  • 保持發現直接、有證據支持,並按嚴重性排序。

報告結構描述

稽核應產生遵循以下格式的結構化報告:

{
  "schema_version": "ecc.agent-architecture-audit.report.v1",
  "executive_verdict": {
    "overall_health": "high_risk",
    "primary_failure_mode": "string",
    "most_urgent_fix": "string"
  },
  "scope": {
    "target_name": "string",
    "model_stack": ["string"],
    "layers_to_audit": ["string"]
  },
  "findings": [
    {
      "severity": "critical|high|medium|low",
      "title": "string",
      "mechanism": "string",
      "source_layer": "string",
      "root_cause": "string",
      "evidence_refs": ["file:line"],
      "confidence": 0.0,
      "recommended_fix": "string"
    }
  ],
  "ordered_fix_plan": [
    { "order": 1, "goal": "string", "why_now": "string", "expected_effect": "string" }
  ]
}

相關技能

  • agent-introspection-debugging — 除錯代理執行時期故障(迴圈、逾時、狀態錯誤)
  • agent-eval — 基準測試代理的對比效能
  • security-review — 程式碼與設定的安全稽核
  • autonomous-agent-harness — 設定自主代理操作
  • agent-harness-construction — 從頭開始建構代理測試框架

Individual skills in this repo

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

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

api-connector-builder

Build a new API connector or provider by matching the target repo

相關技能