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 the project's verification gate (
bosskuai-laravel-verification for Laravel)
- framework-specific debugging when a narrower bosskuai skill already exists (e.g.
bosskuai-diagnose-loop)
- 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
- the model id, SDK version and provider the failing call used, read from config and the lockfile
- prompts, responses and logs, with secrets (keys, tokens, passwords) and personal data masked
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 |
| Model or tool call hangs, or never replies |
no timeout set, or the provider is slow |
check the call's timeout and the provider's status before any retry |
| Reply breaks the expected shape (missing field, new type) |
provider or code changed the response, or output is not validated |
diff the last good reply against the first bad one |
| Model id not found, or a fallback model answered |
id renamed or retired, or the fallback returns near-empty output |
check the id against the provider's live model list; log which model served each call |
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
- before any retry, check whether the failed call already changed state (a sent message, a created record, a charge); retry only a call that is safe to repeat
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 BosskuAI
- Use the project's verification gate (
bosskuai-laravel-verification for Laravel) after recovery if code was changed.
- Use
bosskuai-continuous-learning when the failure pattern is worth turning into a durable memory entry.
- Use
bosskuai-council when the issue is not technical failure but decision ambiguity.
- Use
bosskuai-project-understanding if the failure came from conflicting local state or repo drift.
- Use
bosskuai-agent-architecture-audit when symptoms point at the wrapper stack itself (persona injection, model fallback, memory admission) rather than this run.
../../references/checklists/engineering-quality-bar.md: the shared bar each recovery is checked against.
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
1---2name: bosskuai-agent-introspection3description: "Use when an agent run loops, burns tokens, drifts, or returns empty/degraded results: self-debugging with failure capture, diagnosis, contained recovery, and a report."4license: MIT5metadata:6 author: affaan-m/ECC7 source: https://skillmd.com/skills/wankimmy/bosskuai-agent-introspection8 upstream: agent-introspection-debugging9---1011# Agent Introspection Debugging1213Use 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.1415This is a workflow skill, not a hidden runtime. It teaches the agent to debug itself systematically before escalating to a human.1617## When to Activate1819- Maximum tool call / loop-limit failures20- Repeated retries with no forward progress21- Context growth or prompt drift that starts degrading output quality22- File-system or environment state mismatch between expectation and reality23- Tool failures that are likely recoverable with diagnosis and a smaller corrective action2425## Scope Boundaries2627Activate this skill for:28- capturing failure state before retrying blindly29- diagnosing common agent-specific failure patterns30- applying contained recovery actions31- producing a structured human-readable debug report3233Do not use this skill as the primary source for:34- feature verification after code changes; use the project's verification gate (`bosskuai-laravel-verification` for Laravel)35- framework-specific debugging when a narrower bosskuai skill already exists (e.g. `bosskuai-diagnose-loop`)36- runtime promises the current harness cannot enforce automatically3738## Four-Phase Loop3940### Phase 1: Failure Capture4142Before trying to recover, record the failure precisely.4344Capture:45- error type, message, and stack trace when available46- last meaningful tool call sequence47- what the agent was trying to do48- current context pressure: repeated prompts, oversized pasted logs, duplicated plans, or runaway notes49- current environment assumptions: cwd, branch, relevant service state, expected files50- the model id, SDK version and provider the failing call used, read from config and the lockfile51- prompts, responses and logs, with secrets (keys, tokens, passwords) and personal data masked5253Minimum capture template:5455```markdown56## Failure Capture57- Session / task:58- Goal in progress:59- Error:60- Last successful step:61- Last failed tool / command:62- Repeated pattern seen:63- Environment assumptions to verify:64```6566### Phase 2: Root-Cause Diagnosis6768Match the failure to a known pattern before changing anything.6970| Pattern | Likely Cause | Check |71| --- | --- | --- |72| Maximum tool calls / repeated same command | loop or no-exit observer path | inspect the last N tool calls for repetition |73| Context overflow / degraded reasoning | unbounded notes, repeated plans, oversized logs | inspect recent context for duplication and low-signal bulk |74| `ECONNREFUSED` / timeout | service unavailable or wrong port | verify service health, URL, and port assumptions |75| `429` / quota exhaustion | retry storm or missing backoff | count repeated calls and inspect retry spacing |76| file missing after write / stale diff | race, wrong cwd, or branch drift | re-check path, cwd, git status, and actual file existence |77| tests still failing after “fix” | wrong hypothesis | isolate the exact failing test and re-derive the bug |78| Model or tool call hangs, or never replies | no timeout set, or the provider is slow | check the call's timeout and the provider's status before any retry |79| Reply breaks the expected shape (missing field, new type) | provider or code changed the response, or output is not validated | diff the last good reply against the first bad one |80| Model id not found, or a fallback model answered | id renamed or retired, or the fallback returns near-empty output | check the id against the provider's live model list; log which model served each call |8182Diagnosis questions:83- is this a logic failure, state failure, environment failure, or policy failure?84- did the agent lose the real objective and start optimizing the wrong subtask?85- is the failure deterministic or transient?86- what is the smallest reversible action that would validate the diagnosis?8788### Phase 3: Contained Recovery8990Recover with the smallest action that changes the diagnosis surface.9192Safe recovery actions:93- stop repeated retries and restate the hypothesis94- trim low-signal context and keep only the active goal, blockers, and evidence95- re-check the actual filesystem / branch / process state96- narrow the task to one failing command, one file, or one test97- switch from speculative reasoning to direct observation98- escalate to a human when the failure is high-risk or externally blocked99- before any retry, check whether the failed call already changed state (a sent message, a created record, a charge); retry only a call that is safe to repeat100101Do 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.102103Contained recovery checklist:104105```markdown106## Recovery Action107- Diagnosis chosen:108- Smallest action taken:109- Why this is safe:110- What evidence would prove the fix worked:111```112113### Phase 4: Introspection Report114115End with a report that makes the recovery legible to the next agent or human.116117```markdown118## Agent Self-Debug Report119- Session / task:120- Failure:121- Root cause:122- Recovery action:123- Result: success | partial | blocked124- Token / time burn risk:125- Follow-up needed:126- Preventive change to encode later:127```128129## Recovery Heuristics130131Prefer these interventions in order:1321331. Restate the real objective in one sentence.1342. Verify the world state instead of trusting memory.1353. Shrink the failing scope.1364. Run one discriminating check.1375. Only then retry.138139Bad pattern:140- retrying the same action three times with slightly different wording141142Good pattern:143- capture failure144- classify the pattern145- run one direct check146- change the plan only if the check supports it147148## Integration with BosskuAI149150- Use the project's verification gate (`bosskuai-laravel-verification` for Laravel) after recovery if code was changed.151- Use `bosskuai-continuous-learning` when the failure pattern is worth turning into a durable memory entry.152- Use `bosskuai-council` when the issue is not technical failure but decision ambiguity.153- Use `bosskuai-project-understanding` if the failure came from conflicting local state or repo drift.154- Use `bosskuai-agent-architecture-audit` when symptoms point at the wrapper stack itself (persona injection, model fallback, memory admission) rather than this run.155- `../../references/checklists/engineering-quality-bar.md`: the shared bar each recovery is checked against.156157## Output Standard158159When this skill is active, do not end with “I fixed it” alone.160161Always provide:162- the failure pattern163- the root-cause hypothesis164- the recovery action165- the evidence that the situation is now better or still blocked