agent-introspection-debugging
affaan-m/everything-claude-code
Structured self-debugging workflow for AI agents to diagnose and recover from failures systematically.
What is agent-introspection-debugging?
A workflow skill that teaches agents to debug themselves when runs fail repeatedly, loop on tools, or drift from objectives. Use it to capture failure state, diagnose root causes, apply contained recovery actions, and produce structured debug reports before escalating to humans.
- Capture failure state precisely: error type, tool sequence, context pressure, and environment assumptions
- Diagnose root causes by matching failures to known patterns: loops, context overflow, service unavailability, quota exhaustion, file state mismatches, or wrong hypotheses
- Apply contained recovery actions: restate objectives, verify world state, shrink scope, run discriminating checks
- Generate structured introspection reports documenting failure, diagnosis, recovery action, and follow-up needs
- Integrate with other ECC skills: verification-loop for code changes, continuous-learning-v2 for pattern encoding, council for decision ambiguity
How to install agent-introspection-debugging
npx skills add https://github.com/affaan-m/everything-claude-code --skill agent-introspection-debuggingHow to use agent-introspection-debugging
- 1.Activate the skill when an agent run fails repeatedly, loops, or consumes tokens without progress
- 2.Phase 1: Capture the failure precisely—record error, last tool calls, goal, context pressure, and environment assumptions
- 3.Phase 2: Diagnose the root cause by matching the failure to a known pattern (loop, context overflow, service unavailable, quota exhaustion, file state mismatch, or wrong hypothesis)
- 4.Phase 3: Apply the smallest contained recovery action—restate objective, verify world state, shrink scope, or run one discriminating check
- 5.Phase 4: Generate a structured introspection report with failure, root cause, recovery action, result, and follow-up needs
Use cases
- Agent reaches maximum tool call limit and enters a loop on the same command without progress
- Context grows unbounded with repeated prompts and oversized logs, degrading reasoning quality
- Service connection fails with ECONNREFUSED or 429 quota errors; agent needs to verify health and retry strategy
- File written to disk but subsequent reads fail; agent must re-check path, working directory, and git state
- Tests still fail after an attempted fix; agent must isolate the exact failing test and re-derive the bug
- AI agents experiencing repeated failures or token consumption without forward progress
- Development teams debugging agent behavior before escalating to human intervention
- Teams using Claude Code or Cursor with structured failure recovery workflows
agent-introspection-debugging FAQ
Activate when an agent run is failing repeatedly, looping on the same tools, consuming tokens without progress, or drifting from the intended task. Do not use it for feature verification (use verification-loop) or framework-specific debugging when a narrower skill exists.
This skill enforces a four-phase loop: capture the failure state precisely, diagnose the root cause by pattern matching, apply the smallest safe recovery action, and produce a structured report. Blind retrying wastes tokens and context. This skill makes the failure legible and prevents repeated mistakes.
Safe actions include: restating the hypothesis, trimming low-signal context, re-checking filesystem/branch/process state, narrowing the task to one failing command or test, and switching from speculation to direct observation. Do not claim unsupported auto-healing actions like 'reset agent state' unless you are actually doing them through real tools.
Use verification-loop after recovery if code was changed. Use continuous-learning-v2 when the failure pattern is worth encoding as an instinct. Use council for decision ambiguity. Use workspace-surface-audit if the failure came from conflicting local state or repo drift.
The report must document: session/task, failure, root cause, recovery action taken, result (success/partial/blocked), token/time burn risk, follow-up needed, and preventive changes to encode later.
Full instructions (SKILL.md)
Source of truth, from affaan-m/everything-claude-code.
name: agent-introspection-debugging description: Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. metadata: origin: ECC
Agent Introspection Debugging
Use this skill when an agent run is failing repeatedly, consuming tokens without progress, looping on the same tools, or drifting away from the intended task.
This is a workflow skill, not a hidden runtime. It teaches the agent to debug itself systematically before escalating to a human.
When to Activate
- Maximum tool call / loop-limit failures
- Repeated retries with no forward progress
- Context growth or prompt drift that starts degrading output quality
- File-system or environment state mismatch between expectation and reality
- Tool failures that are likely recoverable with diagnosis and a smaller corrective action
Scope Boundaries
Activate this skill for:
- capturing failure state before retrying blindly
- diagnosing common agent-specific failure patterns
- applying contained recovery actions
- producing a structured human-readable debug report
Do not use this skill as the primary source for:
- feature verification after code changes; use
verification-loop - framework-specific debugging when a narrower ECC skill already exists
- runtime promises the current harness cannot enforce automatically
Four-Phase Loop
Phase 1: Failure Capture
Before trying to recover, record the failure precisely.
Capture:
- error type, message, and stack trace when available
- last meaningful tool call sequence
- what the agent was trying to do
- current context pressure: repeated prompts, oversized pasted logs, duplicated plans, or runaway notes
- current environment assumptions: cwd, branch, relevant service state, expected files
Minimum capture template:
## Failure Capture
- Session / task:
- Goal in progress:
- Error:
- Last successful step:
- Last failed tool / command:
- Repeated pattern seen:
- Environment assumptions to verify:
Phase 2: Root-Cause Diagnosis
Match the failure to a known pattern before changing anything.
| Pattern | Likely Cause | Check |
|---|---|---|
| Maximum tool calls / repeated same command | loop or no-exit observer path | inspect the last N tool calls for repetition |
| Context overflow / degraded reasoning | unbounded notes, repeated plans, oversized logs | inspect recent context for duplication and low-signal bulk |
ECONNREFUSED / timeout | service unavailable or wrong port | verify service health, URL, and port assumptions |
429 / quota exhaustion | retry storm or missing backoff | count repeated calls and inspect retry spacing |
| file missing after write / stale diff | race, wrong cwd, or branch drift | re-check path, cwd, git status, and actual file existence |
| tests still failing after “fix” | wrong hypothesis | isolate the exact failing test and re-derive the bug |
Diagnosis questions:
- is this a logic failure, state failure, environment failure, or policy failure?
- did the agent lose the real objective and start optimizing the wrong subtask?
- is the failure deterministic or transient?
- what is the smallest reversible action that would validate the diagnosis?
Phase 3: Contained Recovery
Recover with the smallest action that changes the diagnosis surface.
Safe recovery actions:
- stop repeated retries and restate the hypothesis
- trim low-signal context and keep only the active goal, blockers, and evidence
- re-check the actual filesystem / branch / process state
- narrow the task to one failing command, one file, or one test
- switch from speculative reasoning to direct observation
- escalate to a human when the failure is high-risk or externally blocked
Do not claim unsupported auto-healing actions like “reset agent state” or “update harness config” unless you are actually doing them through real tools in the current environment.
Contained recovery checklist:
## Recovery Action
- Diagnosis chosen:
- Smallest action taken:
- Why this is safe:
- What evidence would prove the fix worked:
Phase 4: Introspection Report
End with a report that makes the recovery legible to the next agent or human.
## Agent Self-Debug Report
- Session / task:
- Failure:
- Root cause:
- Recovery action:
- Result: success | partial | blocked
- Token / time burn risk:
- Follow-up needed:
- Preventive change to encode later:
Recovery Heuristics
Prefer these interventions in order:
- Restate the real objective in one sentence.
- Verify the world state instead of trusting memory.
- Shrink the failing scope.
- Run one discriminating check.
- Only then retry.
Bad pattern:
- retrying the same action three times with slightly different wording
Good pattern:
- capture failure
- classify the pattern
- run one direct check
- change the plan only if the check supports it
Integration with ECC
- Use
verification-loopafter recovery if code was changed. - Use
continuous-learning-v2when the failure pattern is worth turning into an instinct or later skill. - Use
councilwhen the issue is not technical failure but decision ambiguity. - Use
workspace-surface-auditif the failure came from conflicting local state or repo drift.
Output Standard
When this skill is active, do not end with “I fixed it” alone.
Always provide:
- the failure pattern
- the root-cause hypothesis
- the recovery action
- the evidence that the situation is now better or still blocked
Related skills
More from affaan-m/everything-claude-code and the wider catalog.

security-review
Security checklist and patterns for authentication, input validation, secrets, and sensitive features.

golang-patterns
Idiomatic Go patterns, best practices, and conventions for building robust, efficient, and maintainable applications.

coding-standards
Baseline coding conventions for naming, readability, immutability, and quality across projects.

frontend-patterns
React and Next.js patterns for components, state management, performance, and modern frontend practices.

backend-patterns
REST/GraphQL API design, database optimization, and server-side patterns for Node.js, Express, and Next.js.

golang-testing
Go testing patterns: table-driven tests, subtests, benchmarks, fuzzing, and TDD methodology.