Communitygithub.com

agent-architecture-audit

针对智能体与LLM应用的全栈诊断。审计12层智能体堆栈,检测包装回归、内存污染、工具纪律失效、隐藏修复循环及渲染损坏等问题。生成按严重程度排序的发现结果及代码优先修复方案。

agent-architecture-audit 是什么?

agent-architecture-audit 是一个用于诊断智能体系统故障的专用技能,特别适用于问题根源未知或即将发布智能体堆栈前的场景。它采用“12层堆栈”模型,全面审核从系统提示、会话历史、长期内存到工具选择、执行、解释,以及答案塑造、平台渲染和隐藏修复循环等所有可能引入错误的层次。该技能通过提供明确的激活条件、基于证据的收集命令(如使用 rg 搜索反模式)和结构化的审计工作流(范围界定 → 证据收集 → 故障映射 → 修复策略),帮助开发者快速定位并解决包装回归、内存污染、工具纪律失效和渲染损坏等常见故障模式。最终输出包含按严重程度排序的发现结果、架构诊断和代码优先的修复计划,并支持结构化 JSON 报告模式,是构建和发布可靠智能体应用的关键工具。

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

在你喜欢的 AI 中提问

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

文档

Agent 架构审计

一个用于诊断智能体系统的诊断工作流,这些系统的问题可能隐藏在包装层、陈旧内存、重试循环或传输/渲染变更背后。

何时激活

必须使用于:

  • 将任何智能体或 LLM 驱动的应用程序发布到生产环境
  • 发布包含工具调用、内存或多步骤工作流的特性
  • 添加包装层后智能体行为退化
  • 用户报告“智能体越来越差”或“工具不稳定”
  • 相同模型在 Playground 中工作正常,但在你的包装器内出错
  • 调试智能体行为超过 15 分钟仍未找到根本原因

以下情况尤其关键:

  • 你添加了新的提示层、工具定义或内存系统
  • 系统中的不同智能体行为不一致
  • 昨天模型还好好的,今天却开始产生幻觉
  • 你怀疑存在静默修改响应的隐藏修复/重试循环

不要用于:

  • 通用代码调试——请使用 agent-introspection-debugging
  • 代码审查——请使用特定语言的审查智能体
  • 安全扫描——请使用 security-review 或 security-review/scan
  • 智能体性能基准测试——请使用 agent-eval
  • 编写新特性——请使用适当的工作流 skill

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 层中哪些层适用?

阶段二:证据收集

从代码库中收集证据:

  • 源代码——智能体循环、工具路由器、内存准入、提示组装
  • 日志——历史会话追踪、工具调用记录
  • 配置——提示模板、工具模式、提供商设置
  • 内存文件——SOP、知识库、会话档案

使用 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/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

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.

相关技能