ARTICLE · INTELLIGENCE

战地情报 · 详情页

来自尧图项目组的一线实战观察与深度解析

Patterns to Avoid

Patterns to Avoid Patterns to Avoid【免费下载链接】Agent-Skills-for-Context-EngineeringA comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems. Use when building, optimizing, or debugging agent systems that require effective context management.项目地址: https://gitcode.com/GitHub_Trending/ag/Agent-Skills-for-Context-EngineeringMissing Validation: Accepting tool responses at face value without verifying the actual state change occurred.Hallucinating Sources: Citing sources that failed to load.Ignoring Contradictions: Proceeding when tool results conflict.Recommended PracticesAfter every tool call, state the outcome explicitlyTrack sources separately: attempted vs successfulImplement error recovery with alternative approachesCross-reference key claims against multiple sourcesSKILL.md 的模板结构固定为YAML frontmattername description→ # 标题 → intro → When to Activate → Core Concepts → Patterns to Avoid → Recommended Practices → Guidelines → Examples → Skill Metadata生成日期、来源、优化迭代次数、分数提升。 ## API 参考 ### TraceCapture python capture TraceCapture( api_key..., # MiniMax API key base_urlhttps://api.minimax.io/anthropic, # API 端点 modelMiniMax-M2.1 # 使用的模型 ) trace capture.run( task..., # 要执行的任务 system_prompt..., # 系统提示词 tools[...], # 工具定义Anthropic 格式 tool_executorfn, # 执行工具的函数 max_turns10, # 最大对话轮次 max_tokens4096 # 每次响应的最大 token 数 )源码层面的默认值与限制capture.pyapi_key缺省时读取环境变量ANTHROPIC_API_KEYbase_url默认国际端点model可选MiniMax-M2.1、MiniMax-M2.1-lightning、MiniMax-M2CLI 的--model也提供这三个选项system_prompt默认You are a helpful assistant.max_turns默认 10超出未完成时记录successFalse与错误信息Reached maximum turns (10) without completion。TraceAnalyzeranalyzer TraceAnalyzer( api_key..., base_urlhttps://api.minimax.io/anthropic, modelMiniMax-M2.1 ) analysis analyzer.analyze(trace) # 返回: AnalysisResult包含 patterns、scores、recommendations quick_score analyzer.quick_score(trace) # 返回: float (0-100)用于快速反馈analyze()的max_tokens默认 8192analyze_batch()支持批量分析。分析器本身也使用 M2.1 的交错思考来思考如何分析——ANALYSIS_SYSTEM_PROMPT把分析器设定为专家级 AI Agent 调试器最终AnalysisResult.analyzer_thinking会保留分析器自身的推理过程实现用推理分析推理的可解释闭环。OptimizationLoop 与 LoopConfigconfig LoopConfig( # 迭代控制 max_iterations5, # 最大优化迭代次数 convergence_threshold3.0, # 改进幅度低于该百分比则停止 min_score_threshold75.0, # 分数超过该值则停止 regression_threshold8.0, # 分数回落超过该值则告警 # 优化行为 use_best_promptTrue, # 使用表现最好的提示词而非最后一轮的 max_prompt_growth5.0, # 提示词最大膨胀倍数相对原始5x # 输出选项 save_artifactsTrue, # 保存轨迹与分析 artifacts_dir./artifacts # 保存位置 ) loop OptimizationLoop(configconfig) result loop.run(task, initial_prompt, tools, tool_executor) # 返回: LoopResult包含 iterations、final_prompt、scores从 loop.py 可以看到 LoopConfig 还包含三个评分权重参数success_weight0.4、score_weight0.4、error_weight0.2以及verboseTrue输出控制。OptimizationLoop.run()每轮迭代执行四步捕获轨迹 → 分析 → 按_check_convergence()判断是否收敛分数达标 / 连续两次回归 / 改进小于阈值 / 达到最大迭代数四类停止条件→ 若继续则调用PromptOptimizer.optimize()生成新提示词并在新提示词超过initial_prompt × max_prompt_growth时回退保留当前提示词。优化保护机制最佳提示词跟踪保留产生最高分数的提示词use_best_promptTrue时最终结果使用它提示词膨胀限制通过max_prompt_growth限制体积膨胀回归检测分数下降时告警连续回归后停止。分数预期README 中的经验值供设定阈值参考任务复杂度典型分数区间说明简单1-2 个工具80-95直接任务快速收敛中等3-5 个工具70-85多工具协同带来波动复杂6 个工具、多步骤60-75长推理链固有方差多工具多步骤的复杂研究任务通常稳定在65-75分原因是工具输出可变性影响推理路径、多种有效路径导致评分差异、多步 Agent 执行的随机性。因此优化器关注的是相对提升与模式消除而非追求某个绝对分数。SkillGeneratorgenerator SkillGenerator() skill_path generator.generate( resultloop_result, # 来自 OptimizationLoop skill_namemy-skill, # 小写加连字符 output_dir./generated_skills, titleHuman Readable Title )此外SkillGenerator.generate_from_analysis()支持在未运行完整优化循环的情况下仅凭多份分析结果聚合生成 Skillanalysis.overall_score的平均值写入元数据。CLI 用法# 捕获推理轨迹 rto capture Explain interleaved thinking -s You are an AI researcher. # 分析任务并输出结果 rto analyze Debug this code snippet -o analysis.txt # 运行完整优化循环 rto optimize Research AI papers --max-iterations 5 --generate-skill # 从历史优化产物生成 Skill rto generate-skill my-skill-name --artifacts-dir ./optimization_artifacts对应 cli.py 的四个子命令全局参数包括--api-keyMiniMax API key或使用ANTHROPIC_API_KEY环境变量--base-url默认https://api.minimax.io/anthropic--model可选MiniMax-M2.1/MiniMax-M2.1-lightning/MiniMax-M2。optimize子命令特有参数--max-iterations默认 5、--convergence-threshold默认 5.0、--min-score默认 80.0、--artifacts-dir默认./optimization_artifacts、--generate-skill、--skill-name、--skills-dir默认./generated_skillsgenerate-skill子命令会从summary.json重建LoopResult再生成 Skill。鲁棒性设计解析韧性LLM 响应不总是产出合法 JSON系统对此做了优雅降级README 归纳 源码验证组件降级行为AnalyzerJSON 解析失败时用正则提取分数兜底默认 50/100而非 0Optimizer多策略提示词提取JSON → 正则 → 标记检测 → 代码块Loop最终提示词未变化时给出告警并跟踪最优迭代具体实现analyzer.py_parse_analysis_response()先剥离 markdown 代码围栏再json.loads失败时_fallback_parse_analysis()用 4 组正则overall[\s:](\d)、Overall Score[:\s](\d)等提取分数仍失败则返回中性分 50 并附上解析失败、分析可能不完整的提示若最终分数为 0 且无任何模式还会追加 WARNING 说明并尝试二次提取。optimizer.py_fallback_extract_prompt()依次尝试optimized_prompt: ...正则、四组起始/结束标记## Optimized Prompt、**Optimized Prompt**、OPTIMIZED PROMPT:、Here is the improved prompt:、以及长度大于 100 的非 JSON 代码块。10 轮扩展测试结果README 记录的实测经验Iteration Score Patterns Tool Calls Notes ──────────────────────────────────────────────── 1 69/100 4 22 Baseline 2 66/100 3 14 - 3 61/100 3 17 - 4 72/100 3 20 ← Best score 5 59/100 4 16 - 6 50/100* 0 15 *Parser fallback activated 7 70/100 3 12 Recovery 8 64/100 3 14 - 9 64/100 3 18 - 10 70/100 3 19 Final * Iteration 6: JSON parsing failed, fallback returned neutral score关键经验分数在迭代之间因模型随机行为波动 ±15 分最优分数72出现在运行中途而非末尾use_best_promptTrue正确选中了 iteration 4 的提示词解析失败现在被优雅处理不再返回 0 分。架构总览reasoning_trace_optimizer/ ├── __init__.py # 公共 API 导出 ├── models.py # 数据模型 │ ├── ThinkingBlock # 单段推理 │ ├── ToolCall # 工具调用记录 │ ├── ReasoningTrace # 完整执行轨迹 │ ├── Pattern # 检测到的失败模式 │ ├── AnalysisResult # 完整分析输出 │ └── LoopResult # 优化循环结果 ├── capture.py # TraceCapture - M2.1 API 包装 ├── analyzer.py # TraceAnalyzer - 模式检测含降级解析 ├── optimizer.py # PromptOptimizer - 提示词改进含降级提取 ├── loop.py # OptimizationLoop - 完整循环含最优分数跟踪 ├── skill_generator.py # SkillGenerator - 创建 Skill └── cli.py # 命令行接口此外 models.py 还定义了PromptDiff提示词差异section / original / optimized / reason与OptimizationResult原始提示词、优化提示词、diffs、预期提升百分比、置信度、优化器自身的推理过程为审计每次优化改了什么、为什么改提供了结构化支撑。与 Claude Code 集成项目自带 Claude Code SkillSKILL.mdfrontmatter 中name: reasoning-trace-optimizer支持三种激活方式失败自动触发Agent 任务失败时自动分析原因按需分析使用/reasoning-trace-optimizer命令会话分析分析当前对话中的思考过程。在 Claude Code 中配置钩子实现工具错误后自动分析{ hooks: { post_tool_error: { command: rto analyze-session --last-error } } }作为 Python 库使用from reasoning_trace_optimizer import ( TraceCapture, TraceAnalyzer, PromptOptimizer, OptimizationLoop, LoopConfig, SkillGenerator, )【免费下载链接】Agent-Skills-for-Context-EngineeringA comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems. Use when building, optimizing, or debugging agent systems that require effective context management.项目地址: https://gitcode.com/GitHub_Trending/ag/Agent-Skills-for-Context-Engineering创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
RELATED READING

延伸阅读

更多一线实战笔记与深度复盘,助您持续精进