Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
examples/interleaved-thinking/SKILL.md
1---2name: reasoning-trace-optimizer3description: "Debug and optimize AI agents by analyzing reasoning traces. Activates on 'debug agent', 'optimize prompt', 'analyze reasoning', 'why did the agent fail', 'improve agent performance', or when diagnosing agent failures and context degradation."4---56# Reasoning Trace Optimizer78Debug and optimize AI agents by analyzing their reasoning traces. This skill uses MiniMax M2.1's interleaved thinking to provide deep insight into agent decision-making and generate concrete improvements.910## When to Activate1112- User asks to "debug agent", "analyze reasoning", or "optimize prompt"13- Agent task fails and user wants to understand why14- User mentions "context degradation", "tool confusion", or "instruction drift"15- Request to improve agent performance or reduce errors16- User wants to generate shareable learnings from debugging sessions17- After repeated failures on similar tasks1819## Core Concepts2021### Interleaved Thinking2223Unlike standard reasoning models that think once at the start, interleaved thinking allows reasoning BETWEEN each tool interaction. This is critical because:24251. **Long-horizon tasks** require maintaining focus across many turns262. **External perturbations** (tool outputs, environment changes) need real-time adaptation273. **Debugging** requires seeing HOW decisions were made, not just WHAT was output2829### The Optimization Loop3031```32Execute Agent → Capture Traces → Analyze Patterns → Optimize Prompt → Re-run33↑____________|34```3536Each iteration improves the prompt based on detected patterns until convergence.3738### Pattern Detection3940Common failure patterns the analyzer detects:4142| Pattern | Description |43|---------|-------------|44| `context_degradation` | Model loses track of information over long contexts |45| `tool_confusion` | Model misunderstands tool capabilities or outputs |46| `instruction_drift` | Model gradually deviates from original instructions |47| `goal_abandonment` | Model stops pursuing the original goal |48| `circular_reasoning` | Model repeats similar actions without progress |49| `premature_conclusion` | Model concludes before completing the task |5051## Usage Modes5253### Mode 1: M2.1 Agent Debugging5455Run a task through M2.1 and analyze its reasoning:5657```python58from reasoning_trace_optimizer import TraceCapture, TraceAnalyzer5960capture = TraceCapture()61trace = capture.run(62task="Search for Python tutorials and summarize them",63system_prompt="You are a research assistant.",64tools=[search_tool],65tool_executor=execute_search66)6768analyzer = TraceAnalyzer()69analysis = analyzer.analyze(trace)7071print(f"Score: {analysis.overall_score}/100")72for pattern in analysis.patterns:73print(f"Found: {pattern.type.value} - {pattern.suggestion}")74```7576### Mode 2: Full Optimization Loop7778Automatically iterate until the prompt is optimized:7980```python81from reasoning_trace_optimizer import OptimizationLoop, LoopConfig8283config = LoopConfig(84max_iterations=5,85min_score_threshold=80.0,86)8788loop = OptimizationLoop(config=config)89result = loop.run(90task="Analyze this codebase and suggest improvements",91initial_prompt="You are a code reviewer.",92tools=[read_file_tool, search_tool],93tool_executor=execute_tool94)9596print(f"Improved: {result.initial_score} → {result.final_score}")97print(f"Final prompt:\n{result.final_prompt}")98```99100### Mode 3: Universal Session Analysis101102Analyze any agent's previous thinking (works with Claude, GPT, etc.):103104When this skill is activated in Claude Code, it can analyze the current session's thinking blocks to identify issues and suggest improvements.105106```107/reasoning-trace-optimizer analyze-session108```109110### Mode 4: Generate Shareable Skills111112Convert optimization learnings into reusable Agent Skills:113114```python115from reasoning_trace_optimizer import SkillGenerator116117generator = SkillGenerator()118skill_path = generator.generate(119result=loop_result,120skill_name="web-search-best-practices",121output_dir="./skills"122)123```124125## CLI Commands126127```bash128# Capture reasoning trace129rto capture "Search for Python tutorials" -s "You are a helpful assistant."130131# Analyze a task132rto analyze "Debug this code" -o analysis.txt133134# Run optimization loop135rto optimize "Research AI papers" --max-iterations 5 --generate-skill136137# Generate skill from artifacts138rto generate-skill my-skill-name --artifacts-dir ./optimization_artifacts139```140141## Integration with Claude Code142143### Auto-trigger on Failure144145Add to your hooks to automatically analyze failures:146147```json148{149"hooks": {150"post_tool_error": {151"command": "rto analyze-session --last-error"152}153}154}155```156157### On-demand Analysis158159Use the slash command to analyze current session:160161```162/reasoning-trace-optimizer163```164165This will:1661. Extract thinking blocks from the current session1672. Identify patterns and issues1683. Suggest prompt improvements1694. Optionally update the system prompt170171## Guidelines1721731. **Preserve full context**: M2.1 requires full response history including thinking blocks for optimal performance1742. **Use appropriate tools**: Define tools clearly with unambiguous descriptions1753. **Set realistic convergence thresholds**: 5-10% improvement per iteration is typical1764. **Review generated skills**: Auto-generated skills should be reviewed before sharing1775. **Monitor token usage**: Each optimization iteration uses significant tokens178179## Examples180181### Before Optimization182183```184System: You are a helpful assistant.185186Issue: Agent called wrong tools, lost track of goal after 3 turns187Score: 45/100188Patterns: tool_confusion, goal_abandonment189```190191### After Optimization192193```194System: You are a research assistant focused on finding accurate information.195196IMPORTANT GUIDELINES:197- Always verify search results before summarizing198- If a tool returns an error, try an alternative approach199- Keep track of your original goal throughout the task200- Validate findings against multiple sources when possible201202Issue: None203Score: 85/100204Patterns: None detected205```206207## References208209- MiniMax M2.1 Documentation: https://platform.minimax.io/docs210- Interleaved Thinking Guide: See `docs/interleavedthinking.md`211- Agent Generalization: See `docs/agentthinking.md`212213---214215## Skill Metadata216217**Created**: 2025-01-11218**Author**: Muratcan Koylan219**Version**: 0.1.0220**Powered by**: MiniMax M2.1221**Partnership**: Built in collaboration with MiniMax AI222