Skip to content
cccskills
FreePublished on GitHub

reasoning-trace-optimizer

Analyze records of an AI agent’s decisions and tool use to find repeated failures, lost goals, and misunderstood instructions. Use the findings to refine prompts, rerun tasks, and turn debugging lessons into reusable skills.

OriginalShow the original description

Debug and optimize AI agents by analyzing reasoning traces, context degradation, tool confusion, instruction drift, repeated task failures, and performance regressions.

See how to install

Good for

  • Investigating repeated agent failures
  • Reviewing incorrect tool choices
  • Refining prompts through repeated evaluation
  • Turning debugging lessons into reusable skills

Files included (63)

  • SKILL.md6.2 KB
  • docs/agentthinking.md6.4 KB
  • docs/interleavedthinking.md30.0 KB
  • docs/m2-1.md9.3 KB
  • examples/01_basic_capture.py2.2 KB
  • examples/02_tool_usage.py5.7 KB
  • examples/03_full_optimization.py39.0 KB
  • generated_skills/comprehensive-research-agent/references/optimization_summary.json899 B
  • generated_skills/comprehensive-research-agent/references/optimized_prompt.txt81 B
  • generated_skills/comprehensive-research-agent/references/patterns_found.json12.4 KB
  • generated_skills/comprehensive-research-agent/SKILL.md8.3 KB
  • optimization_artifacts/final_prompt.txt3.2 KB
  • optimization_artifacts/iteration_1/analysis.txt2.8 KB
  • optimization_artifacts/iteration_1/optimization.txt485 B
  • optimization_artifacts/iteration_1/optimized_prompt.txt81 B
  • optimization_artifacts/iteration_1/trace.txt27.8 KB
  • optimization_artifacts/iteration_10/analysis.txt3.7 KB
  • optimization_artifacts/iteration_10/trace.txt28.2 KB
  • optimization_artifacts/iteration_2/analysis.txt3.4 KB
  • optimization_artifacts/iteration_2/optimization.txt6.8 KB
  • optimization_artifacts/iteration_2/optimized_prompt.txt3.4 KB
  • optimization_artifacts/iteration_2/trace.txt21.8 KB
  • optimization_artifacts/iteration_3/analysis.txt3.1 KB
  • optimization_artifacts/iteration_3/optimization.txt7.7 KB
  • optimization_artifacts/iteration_3/optimized_prompt.txt4.3 KB
  • optimization_artifacts/iteration_3/trace.txt28.3 KB
  • optimization_artifacts/iteration_4/analysis.txt3.0 KB
  • optimization_artifacts/iteration_4/optimization.txt6.4 KB
  • optimization_artifacts/iteration_4/optimized_prompt.txt3.2 KB
  • optimization_artifacts/iteration_4/trace.txt23.3 KB
  • optimization_artifacts/iteration_5/analysis.txt3.6 KB
  • optimization_artifacts/iteration_5/optimization.txt6.3 KB
  • optimization_artifacts/iteration_5/optimized_prompt.txt3.0 KB
  • optimization_artifacts/iteration_5/trace.txt30.6 KB
  • optimization_artifacts/iteration_6/analysis.txt460 B
  • optimization_artifacts/iteration_6/optimization.txt485 B
  • optimization_artifacts/iteration_6/optimized_prompt.txt81 B
  • optimization_artifacts/iteration_6/trace.txt18.9 KB
  • optimization_artifacts/iteration_7/analysis.txt2.6 KB
  • optimization_artifacts/iteration_7/optimization.txt5.4 KB
  • optimization_artifacts/iteration_7/optimized_prompt.txt2.6 KB
  • optimization_artifacts/iteration_7/trace.txt20.7 KB
  • optimization_artifacts/iteration_8/analysis.txt3.1 KB
  • optimization_artifacts/iteration_8/optimization.txt6.3 KB
  • optimization_artifacts/iteration_8/optimized_prompt.txt3.3 KB
  • optimization_artifacts/iteration_8/trace.txt21.6 KB
  • optimization_artifacts/iteration_9/analysis.txt2.7 KB
  • optimization_artifacts/iteration_9/optimization.txt5.8 KB
  • optimization_artifacts/iteration_9/optimized_prompt.txt2.6 KB
  • optimization_artifacts/iteration_9/trace.txt25.5 KB
  • optimization_artifacts/summary.json1002 B
  • pyproject.toml1.9 KB
  • README.md19.7 KB
  • reasoning_trace_optimizer/__init__.py1.2 KB
  • reasoning_trace_optimizer/analyzer.py15.8 KB
  • reasoning_trace_optimizer/capture.py14.3 KB
  • reasoning_trace_optimizer/cli.py8.4 KB
  • reasoning_trace_optimizer/loop.py17.6 KB
  • reasoning_trace_optimizer/models.py4.8 KB
  • reasoning_trace_optimizer/optimizer.py14.2 KB
  • reasoning_trace_optimizer/skill_generator.py16.0 KB
  • tests/__init__.py43 B
  • tests/test_models.py3.8 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Reasoning Trace Optimizer

Debug 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.

When to Activate

  • Agent reasoning traces need debugging, analysis, or prompt optimization
  • Agent task fails and user wants to understand why
  • User mentions "context degradation", "tool confusion", or "instruction drift"
  • Request to improve agent performance or reduce errors
  • User wants to generate shareable learnings from debugging sessions
  • After repeated failures on similar tasks

Core Concepts

Interleaved Thinking

Unlike standard reasoning models that think once at the start, interleaved thinking allows reasoning BETWEEN each tool interaction. This is critical because:

  1. Long-horizon tasks require maintaining focus across many turns
  2. External perturbations (tool outputs, environment changes) need real-time adaptation
  3. Debugging requires seeing HOW decisions were made, not just WHAT was output

The Optimization Loop

Execute Agent → Capture Traces → Analyze Patterns → Optimize Prompt → Re-run
                                                          ↑____________|

Each iteration improves the prompt based on detected patterns until convergence.

Pattern Detection

Common failure patterns the analyzer detects:

PatternDescription
context_degradationModel loses track of information over long contexts
tool_confusionModel misunderstands tool capabilities or outputs
instruction_driftModel gradually deviates from original instructions
goal_abandonmentModel stops pursuing the original goal
circular_reasoningModel repeats similar actions without progress
premature_conclusionModel concludes before completing the task

Usage Modes

Mode 1: M2.1 Agent Debugging

Run a task through M2.1 and analyze its reasoning:

from reasoning_trace_optimizer import TraceCapture, TraceAnalyzer

capture = TraceCapture()
trace = capture.run(
    task="Search for Python tutorials and summarize them",
    system_prompt="You are a research assistant.",
    tools=[search_tool],
    tool_executor=execute_search
)

analyzer = TraceAnalyzer()
analysis = analyzer.analyze(trace)

print(f"Score: {analysis.overall_score}/100")
for pattern in analysis.patterns:
    print(f"Found: {pattern.type.value} - {pattern.suggestion}")

Mode 2: Full Optimization Loop

Automatically iterate until the prompt is optimized:

from reasoning_trace_optimizer import OptimizationLoop, LoopConfig

config = LoopConfig(
    max_iterations=5,
    min_score_threshold=80.0,
)

loop = OptimizationLoop(config=config)
result = loop.run(
    task="Analyze this codebase and suggest improvements",
    initial_prompt="You are a code reviewer.",
    tools=[read_file_tool, search_tool],
    tool_executor=execute_tool
)

print(f"Improved: {result.initial_score} → {result.final_score}")
print(f"Final prompt:\n{result.final_prompt}")

Mode 3: Universal Session Analysis

Analyze any agent's previous thinking (works with Claude, GPT, etc.):

When this skill is activated in Claude Code, it can analyze the current session's thinking blocks to identify issues and suggest improvements.

/reasoning-trace-optimizer analyze-session

Mode 4: Generate Shareable Skills

Convert optimization learnings into reusable Agent Skills:

from reasoning_trace_optimizer import SkillGenerator

generator = SkillGenerator()
skill_path = generator.generate(
    result=loop_result,
    skill_name="web-search-best-practices",
    output_dir="./skills"
)

CLI Commands

# Capture reasoning trace
rto capture "Search for Python tutorials" -s "You are a helpful assistant."

# Analyze a task
rto analyze "Debug this code" -o analysis.txt

# Run optimization loop
rto optimize "Research AI papers" --max-iterations 5 --generate-skill

# Generate skill from artifacts
rto generate-skill my-skill-name --artifacts-dir ./optimization_artifacts

Integration with Claude Code

Auto-trigger on Failure

Add to your hooks to automatically analyze failures:

{
  "hooks": {
    "post_tool_error": {
      "command": "rto analyze-session --last-error"
    }
  }
}

On-demand Analysis

Use the slash command to analyze current session:

/reasoning-trace-optimizer

This will:

  1. Extract thinking blocks from the current session
  2. Identify patterns and issues
  3. Suggest prompt improvements
  4. Optionally update the system prompt

Guidelines

  1. Preserve full context: M2.1 requires full response history including thinking blocks for optimal performance
  2. Use appropriate tools: Define tools clearly with unambiguous descriptions
  3. Set realistic convergence thresholds: 5-10% improvement per iteration is typical
  4. Review generated skills: Auto-generated skills should be reviewed before sharing
  5. Monitor token usage: Each optimization iteration uses significant tokens

Examples

Before Optimization

System: You are a helpful assistant.

Issue: Agent called wrong tools, lost track of goal after 3 turns
Score: 45/100
Patterns: tool_confusion, goal_abandonment

After Optimization

System: You are a research assistant focused on finding accurate information.

IMPORTANT GUIDELINES:
- Always verify search results before summarizing
- If a tool returns an error, try an alternative approach
- Keep track of your original goal throughout the task
- Validate findings against multiple sources when possible

Issue: None
Score: 85/100
Patterns: None detected

References

  • MiniMax M2.1 Documentation: https://platform.minimax.io/docs
  • Interleaved Thinking Guide: See docs/interleavedthinking.md
  • Agent Generalization: See docs/agentthinking.md

Skill Metadata

Created: 2025-01-11 Author: Muratcan Koylan Version: 0.1.0 Powered by: MiniMax M2.1 Partnership: Built in collaboration with MiniMax AI

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Design systems that use language models to judge AI responses. Covers scoring criteria, comparisons between two answers, bias reduction, confidence calibration, and checks against human judgments to make automated quality assessments more consistent and traceable.

  • Compare responses from different models
  • Run A/B tests for prompt changes
  • Create shared scoring rubrics
muratcankoylan/Agent-Skills-for-Context-Engineering18.2KUpdated Oct 12, 2026

Model what an agent believes, wants, and commits to doing. Connect external facts to goals and plans using structured relationships, with evidence and validity periods that help trace why the agent chose an action.

  • Convert RDF data into agent beliefs
  • Trace the reasons behind agent decisions
  • Track belief validity and changes over time
muratcankoylan/Agent-Skills-for-Context-Engineering18.2KUpdated Oct 12, 2026

Turn ePub books into training examples for models that reproduce an author's writing style. Covers text extraction, coherent segmentation, varied instructions, model training, and checks for copied phrases and style transfer to new scenarios.

  • Build training datasets from ePub books
  • Train a model on an author's writing style
  • Check for copied phrases in generated prose
muratcankoylan/Agent-Skills-for-Context-Engineering18.2KUpdated Oct 12, 2026

Guide multi-source research through source checks, comparison of key claims, and recovery from failed tool calls. Produce reports that distinguish retrieved evidence from unresolved questions and clearly document remaining gaps.

  • Checking key claims against multiple sources
  • Recovering from failed source retrieval
  • Documenting evidence and gaps in research reports
muratcankoylan/Agent-Skills-for-Context-Engineering18.2KUpdated Oct 12, 2026

Design structured summaries for long agent sessions that preserve goals, file changes, decisions, and next actions. Choose compression methods and timing, then test whether the agent can continue accurately without repeatedly retrieving information it already processed.

  • Summarize long coding sessions for continuation
  • Preserve file changes and decision history
  • Create durable summaries for task handoffs
muratcankoylan/Agent-Skills-for-Context-Engineering18.2KUpdated Oct 12, 2026

Diagnose why an AI agent becomes less reliable as conversations and documents accumulate. Distinguish missed information, persistent false claims, irrelevant material, mixed tasks, and conflicting sources, then choose ways to clean, reorganize, or separate the context.

  • Investigating declining quality in long conversations
  • Recovering from false claims that persist after correction
  • Resolving conflicts between retrieved documents
muratcankoylan/Agent-Skills-for-Context-Engineering18.2KUpdated Oct 12, 2026

See all skills by muratcankoylan

Report a problem with this skill