reasoning-trace-optimizer

Analyze agent reasoning traces to detect failure patterns and optimize prompts.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/LGJ-Jonathan/Jonathan_Global_Claude_Skills --skill reasoning-trace-optimizer-lgj-jonathan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: reasoning-trace-optimizer
Source: https://github.com/LGJ-Jonathan/Jonathan_Global_Claude_Skills/tree/main/context-engineering/examples/interleaved-thinking
Command: npx skills add https://github.com/LGJ-Jonathan/Jonathan_Global_Claude_Skills --skill reasoning-trace-optimizer-lgj-jonathan

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires anthropic, pydantic, rich, python-dotenv.

What problem does it solve? AI agents fail in opaque ways: they call wrong tools, lose track of goals, or hallucinate information, and you cannot see why. This Skill captures the reasoning traces between every tool call, detects failure patterns like context degradation and tool confusion, and automatically generates improved prompts. ## Core Features & Use Cases - Trace Capture & Analysis: Wrap the MiniMax M2.1 API to record thinking blocks, tool calls, and results, then score reasoning quality and detect patterns such as hallucination, goal abandonment, and circular reasoning. - Automated Optimization Loop: Run capture-analyze-optimize cycles with convergence detection, best-prompt tracking, and prompt growth limits until the agent's score improves. - Skill Generation: Convert optimization learnings into shareable Agent Skills with documented patterns to avoid and recommended practices. - Use Case: Your research agent keeps citing sources that failed to load. Run the optimization loop to capture its reasoning, detect the missing_validation pattern, and produce an improved system prompt that requires explicit source verification. ## Quick Start Ask the agent to debug why your agent task failed by capturing and analyzing its reasoning trace with the reasoning-trace-optimizer.

Frequently Asked Questions about reasoning-trace-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I debug why my AI agent failed a task?

Capture the agent's reasoning trace with TraceCapture, then run TraceAnalyzer to detect failure patterns like tool confusion or goal abandonment. Each detected pattern includes evidence from thinking blocks, a severity rating, and a concrete prompt improvement suggestion.

What is interleaved thinking in MiniMax M2.1?

Interleaved thinking means the model reasons between every tool call instead of only once at the start. This exposes the agent's decision-making after each tool result, making it possible to see exactly where reasoning diverged from expected behavior.

How do I automatically optimize an agent system prompt?

Use OptimizationLoop with a LoopConfig setting max iterations and score thresholds. It repeatedly executes the task, analyzes the trace, rewrites the prompt, and tracks the best-performing version until scores converge or regress.

Does this work with models other than MiniMax M2.1?

Trace capture and analysis are built around M2.1's interleaved thinking via the Anthropic-compatible API. However, the session analysis mode can review thinking blocks from other agents like Claude or GPT to identify issues and suggest improvements.

Why did my optimization score drop between iterations?

Score fluctuation of plus or minus 15 points is normal due to stochastic model behavior in multi-step tasks. Enable use_best_prompt so the loop keeps the highest-scoring prompt, and rely on regression detection to stop after consecutive drops.