agent-harness-construction
设计和优化 AI Agent 的行动空间、工具定义和观察格式,以提高任务完成率。用于改进 agent 的规划、工具调用、错误恢复和收敛能力。
- License 许可
- MIT
- 最近更新
- 2026-06-29
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- agent-harness-construction
- license
- MIT
- metadata
- { "role": "specialist", "scope": "optimization", "tools": "Read Write Edit", "author": "ECC", "domain": "agent-optimization", "version": "1.0.0", "triggers": "agent 优化, 工具设计, 行动空间, 错误恢复, 完成率, agent harness, tool design, action space", "auto-sync": false, "languages": "all", "local-only": true, "output-format": "structured", "related-skills": "orchestrator, executor, code-reviewer", "requires-installation": false }
- description
- 设计和优化 AI Agent 的行动空间、工具定义和观察格式,以提高任务完成率。用于改进 agent 的规划、工具调用、错误恢复和收敛能力。
02 资源文件 71
- 参考文档checklist.md19.6 KB
- 其他customize.toml1.5 KB
- 参考文档instructions.md4.1 KB
- 参考文档resources/knowledge/adr-quality-readiness-checklist.md24.8 KB
- 参考文档resources/knowledge/api-request.md16.7 KB
- 参考文档resources/knowledge/api-testing-patterns.md26.3 KB
- 参考文档resources/knowledge/auth-session.md15.8 KB
- 参考文档resources/knowledge/burn-in.md6.4 KB
- 参考文档resources/knowledge/ci-burn-in.md22.0 KB
- 参考文档resources/knowledge/component-tdd.md15.8 KB
- 参考文档resources/knowledge/contract-testing.md38.1 KB
- 参考文档resources/knowledge/data-factories.md15.0 KB
- 参考文档resources/knowledge/email-auth.md24.0 KB
- 参考文档resources/knowledge/error-handling.md22.4 KB
- 参考文档resources/knowledge/feature-flags.md22.7 KB
- 参考文档resources/knowledge/file-utils.md13.4 KB
- 参考文档resources/knowledge/fixture-architecture.md12.1 KB
- 参考文档resources/knowledge/fixtures-composition.md11.0 KB
- 参考文档resources/knowledge/intercept-network-call.md13.2 KB
- 参考文档resources/knowledge/log.md11.0 KB
- 参考文档resources/knowledge/network-error-monitor.md12.0 KB
- 参考文档resources/knowledge/network-first.md15.9 KB
- 参考文档resources/knowledge/network-recorder.md15.1 KB
- 参考文档resources/knowledge/nfr-criteria.md26.0 KB
- 参考文档resources/knowledge/overview.md9.4 KB
- 参考文档resources/knowledge/pact-broker-webhooks.md13.1 KB
- 参考文档resources/knowledge/pact-consumer-di.md11.7 KB
- 参考文档resources/knowledge/pact-consumer-framework-setup.md35.0 KB
- 参考文档resources/knowledge/pact-mcp.md8.8 KB
- 参考文档resources/knowledge/pactjs-utils-consumer-helpers.md15.7 KB
- 参考文档resources/knowledge/pactjs-utils-overview.md10.2 KB
- 参考文档resources/knowledge/pactjs-utils-provider-verifier.md17.8 KB
- 参考文档resources/knowledge/pactjs-utils-request-filter.md7.1 KB
- 参考文档resources/knowledge/playwright-cli.md14.6 KB
- 参考文档resources/knowledge/playwright-config.md21.0 KB
- 参考文档resources/knowledge/probability-impact.md18.8 KB
- 参考文档resources/knowledge/recurse.md12.6 KB
- 参考文档resources/knowledge/risk-governance.md20.5 KB
- 参考文档resources/knowledge/selective-testing.md21.3 KB
- 参考文档resources/knowledge/selector-resilience.md19.3 KB
- 参考文档resources/knowledge/test-healing-patterns.md20.9 KB
- 参考文档resources/knowledge/test-levels-framework.md14.4 KB
- 参考文档resources/knowledge/test-priorities-matrix.md11.2 KB
- 参考文档resources/knowledge/test-quality.md24.0 KB
- 参考文档resources/knowledge/timing-debugging.md13.7 KB
- 参考文档resources/knowledge/visual-debugging.md17.1 KB
- 参考文档resources/knowledge/webhook-module-setup.md5.7 KB
- 参考文档resources/knowledge/webhook-providers.md6.3 KB
- 参考文档resources/knowledge/webhook-risk-guidance.md6.3 KB
- 参考文档resources/knowledge/webhook-template-matchers.md5.9 KB
- 参考文档resources/knowledge/webhook-testing-fundamentals.md3.1 KB
- 参考文档resources/knowledge/webhook-timeout-error.md5.6 KB
- 参考文档resources/knowledge/webhook-waiting-querying.md6.9 KB
- 资产文件resources/tea-index.csv10.7 KB
- 参考文档steps-c/step-01-detect-mode.md3.7 KB
- 参考文档steps-c/step-01b-resume.md3.8 KB
- 参考文档steps-c/step-02-load-context.md7.7 KB
- 参考文档steps-c/step-03-risk-and-testability.md3.1 KB
- 参考文档steps-c/step-04-coverage-plan.md3.3 KB
- 参考文档steps-c/step-05-generate-output.md7.5 KB
- 参考文档steps-e/step-01-assess.md1.2 KB
- 参考文档steps-e/step-02-apply-edit.md1.4 KB
- 参考文档steps-v/step-01-validate.md1.8 KB
- 参考文档test-design-architecture-template.md7.6 KB
- 参考文档test-design-handoff-template.md3.1 KB
- 参考文档test-design-qa-template.md12.2 KB
- 参考文档test-design-template.md9.1 KB
- 参考文档validation-report-20260127-095021.md2.1 KB
- 参考文档validation-report-20260127-102401.md3.7 KB
- 参考文档workflow-plan.md540 B
- 参考文档workflow.yaml2.9 KB
03 SKILL.md 正文
Agent Harness Construction
使用此 skill 来改进 agent 的规划、工具调用、错误恢复和收敛能力。
核心模型
Agent 输出质量受以下因素约束:
- 行动空间质量 - 工具定义是否清晰
- 观察质量 - 工具返回结果是否清晰
- 恢复质量 - 错误恢复能力
- 上下文预算质量 - 上下文管理
行动空间设计
- 使用稳定、明确的工具名称
- 保持输入 schema 优先且窄
- 返回确定性的输出形状
- 避免全能工具,除非隔离不可能
粒度规则
| 工具类型 | 使用场景 |
|---|---|
| micro-tools | 高风险操作(部署、迁移、权限) |
| medium-tools | 常见的编辑/读取/搜索循环 |
| macro-tools | 当往返开销是主要成本时 |
观察设计
每个工具响应应包含:
{
"status": "success|warning|error",
"summary": "一行结果摘要",
"next_actions": ["可执行的后续行动"],
"artifacts": ["文件路径/ID"]
}
错误恢复契约
每个错误路径应包含:
| 元素 | 说明 |
|---|---|
| 根因提示 | 错误的根本原因 |
| 安全重试指令 | 如何安全地重试 |
| 明确的停止条件 | 何时停止重试 |
上下文预算
- 保持系统提示最小且不变
- 将大型指导移至按需加载的 skills
- 优先引用文件而非内联长文档
- 在阶段边界压缩,而非任意 token 阈值
架构模式指导
| 模式 | 适用场景 |
|---|---|
| ReAct | 探索性任务,路径不确定 |
| Function-calling | 结构化确定性流程 |
| Hybrid(推荐) | ReAct 规划 + 类型化工具执行 |
基准测试
追踪指标:
| 指标 | 说明 |
|---|---|
| completion rate | 完成率 |
| retries per task | 每任务重试次数 |
| pass@1 | 一次通过率 |
| pass@3 | 三次通过率 |
| cost per successful task | 每成功任务成本 |
反模式
| 反模式 | 说明 |
|---|---|
| 工具重叠 | 过多重叠语义的工具 |
| 不透明输出 | 工具输出无恢复提示 |
| 无后续步骤 | 仅有错误输出,无后续步骤 |
| 上下文过载 | 包含无关引用 |
应用到现有 Agent
Orchestrator 优化
- 行动空间设计:明确调度工具的定义
- 错误恢复:agent 调用失败时的恢复策略
- 观察设计:agent 返回结果的格式
Executor 优化
- 粒度规则:任务执行工具的粒度
- 观察设计:执行结果的格式
- 错误恢复:执行失败时的重试策略
Explorer 优化
- 输出格式:探索结果的格式
- 上下文预算:项目信息的管理
- 行动空间:codegraph 工具的定义
其他 Agent 优化
- 工具定义:每个 agent 的工具定义
- 错误处理:统一的错误处理策略
- 观察格式:统一的输出格式
最佳实践
- 明确工具定义 - 每个工具都有清晰的输入输出
- 统一输出格式 - 所有工具返回相同格式的结果
- 错误恢复优先 - 每个错误都有恢复策略
- 上下文精简 - 只传递必要的上下文
- 渐进式优化 - 逐步优化,不要一次性改变太多
示例
工具响应示例
{
"status": "success",
"summary": "成功找到 login 函数",
"next_actions": [
"查看 login 函数的调用者",
"分析 login 函数的依赖关系"
],
"artifacts": [
"src/lib/auth.ts:15"
]
}
错误响应示例
{
"status": "error",
"summary": "未找到 login 函数",
"root_cause": "函数名可能不同,可能是 loginAsync 或 authenticate",
"retry_instruction": "尝试搜索 authenticate 或 loginAsync",
"stop_condition": "如果连续 3 次搜索未找到,停止并报告"
}
04 同仓库更多 Skills
websocket-engineer
当使用 WebSocket 或 Socket.IO 构建实时通信系统时使用。适用于双向消息通信、Redis 水平扩展、在线状态追踪、房间管理。
security-reviewer
识别安全漏洞,生成带有严重性评级的结构化审计报告,并提供可操作的安全修复建议。在开展安全审计、审查代码漏洞或分析基础设施安全时使用。适用于 SAST 扫描、渗透测试、DevSecOps 实践、云安全审查、依赖审计、密钥扫描或合规检查。生成漏洞报告、优先级建议和合规清单。
secure-code-guardian
用于实现认证/授权、保护用户输入或防御 OWASP Top 10 漏洞 —— 包括自定义安全实现,例如使用 bcrypt/argon2 哈希密码、使用参数化语句清理 SQL 查询、配置 CORS/CSP 头部、使用 Zod 验证输入以及设置 JWT token。适用于认证、授权、输入验证、加密、OWASP Top 10 防护、安全会话管理和安全加固。对于预构建的 OAuth/SSO 集成或独立的安全审计,请考虑使用更专业的 skill。
rust-engineer
编写、审查和调试符合 Rust 风格的代码,确保内存安全和零成本抽象。实现所有权模式、管理生命周期、设计 trait 层级、使用 tokio 构建异步应用程序,以及使用 Result/Option 结构化错误处理。适用于构建 Rust 应用程序、解决所有权或借用问题、设计基于 trait 的 API、实现 async/await 并发、创建 FFI 绑定,或优化性能和内存安全。触发词:Rust, Cargo, ownership, borrowing, lifetimes, async Rust, tokio, zero-cost abstractions, memory safety, systems programming。
react-native-expert
使用 React Native 和 Expo 构建、优化和调试跨平台移动应用。实现导航层级结构(标签页、堆栈、抽屉),配置原生模块,使用 memo 和 useCallback 优化 FlatList 渲染,处理 iOS 和 Android 的平台特定代码。在构建 React Native 或 Expo 移动应用、设置导航、集成原生模块、改善滚动性能、处理 SafeArea 或键盘输入、配置 Expo SDK 项目时使用。
react-expert
当你使用 .jsx 或 .tsx 文件构建 React 18+ 应用、Next.js App Router 项目或 create-react-app 时使用。创建组件、实现自定义 hooks、调试渲染问题、将类组件迁移为函数组件、以及实现状态管理。适用于 Server Components、Suspense 边界、useActionState 表单、性能优化或 React 19 特性。