Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports.
git clone https://github.com/affaan-m/ECC.git--- 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: ```markdown ## 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: ```markdown ## 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. ```markdown ## 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: 1. Restate the real objective in one sentence. 2. Verify the world state instead of trusting memory. 3. Shrink the failing scope. 4. Run one discriminating check. 5. 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-loop` after recovery if code was changed. - Use `continuous-learning-v2` when the failure pattern is worth turning into an instinct or later skill. - Use `council` when the issue is not technical failure but decision ambiguity. - Use `workspace-surface-audit` if 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
[{"step":1,"action":"Gather failure context including error messages, input data, and agent state logs. Use your agent's logging system or debugging tools to capture this information.","tip":"Save these details in a structured format (JSON works well) for easy analysis. Include timestamps and any relevant configuration snapshots."},{"step":2,"action":"Run the introspection workflow using the prompt template. Replace placeholders with your specific failure details and agent configuration.","tip":"For complex failures, break down the analysis into smaller components. Use the 'affected_components' field to organize your investigation."},{"step":3,"action":"Implement the recovery steps in a controlled environment first. Test each fix incrementally to ensure it resolves the issue without introducing new problems.","tip":"Use containerized testing environments or feature flags to isolate changes. Document each test case and its results."},{"step":4,"action":"Generate the final introspection report and share it with your team. Use the 'prevention_measures' to create action items for process improvements.","tip":"Schedule a retrospective meeting to discuss the findings. Assign clear owners and deadlines for each prevention measure."},{"step":5,"action":"Monitor the agent's performance after implementing fixes. Use the prevention measures to track whether similar failures reoccur.","tip":"Set up automated alerts for similar error patterns. Review logs weekly to catch any regressions early."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/affaan-m/ECC/tree/main/skills/agent-introspection-debuggingCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Act as an AI agent debugging specialist. Follow this structured workflow to diagnose and resolve failures in an AI agent system: 1) Capture the failure context including [ERROR_MESSAGE], [INPUT_DATA], and [AGENT_STATE]. 2) Diagnose root causes by analyzing the failure against [AGENT_CONFIGURATION] and [PREVIOUS_ACTIONS]. 3) Execute contained recovery by implementing [FIX_STRATEGY] with validation steps. 4) Generate an introspection report documenting [LESSONS_LEARNED] and [PREVENTION_MEASURES]. Return the final output in JSON format with keys: 'diagnosis', 'recovery_steps', 'introspection_report'.
```json
{
"diagnosis": {
"error_message": "ValueError: Expected numeric input for 'temperature' parameter, got string 'high'",
"root_cause": "The agent's input validation pipeline failed to convert string 'high' to a numeric value before passing to the temperature control module. This occurred because the input schema validation was bypassed in the agent's action sequence for the 'climate_control' tool.",
"affected_components": ["input_validation_module", "climate_control_tool", "agent_action_sequence"],
"severity": "high",
"reproducibility": "consistent"
},
"recovery_steps": [
{
"step": 1,
"action": "Implement strict type checking in the input validation module for all numeric parameters",
"validation": "Tested with inputs ['low', 'medium', 'high', '25.5'] - all now properly converted to numeric values",
"status": "completed"
},
{
"step": 2,
"action": "Add explicit error handling in the climate_control tool to reject non-numeric inputs with descriptive error messages",
"validation": "Verified rejection of string inputs with error message: 'Temperature must be a number between 0 and 100'",
"status": "completed"
},
{
"step": 3,
"action": "Update the agent's action sequence to enforce input validation before tool execution",
"validation": "Tested full workflow with invalid input - agent now returns structured error instead of crashing",
"status": "completed"
}
],
"introspection_report": {
"lessons_learned": [
"Input validation must be comprehensive and applied consistently across all agent components",
"Type conversion should happen as early as possible in the pipeline to prevent downstream issues",
"Descriptive error messages help with debugging and user experience",
"The agent's action sequence needs better error handling boundaries"
],
"prevention_measures": [
{
"measure": "Add automated type checking tests to the CI pipeline for all tools",
"owner": "devops_team",
"deadline": "2024-03-15"
},
{
"measure": "Implement a centralized input validation service that all tools must use",
"owner": "backend_team",
"deadline": "2024-03-22"
},
{
"measure": "Create a monitoring dashboard to track input validation failures in production",
"owner": "platform_team",
"deadline": "2024-03-29"
}
],
"root_cause_analysis": "The failure originated from insufficient input validation in the agent's action sequence. While individual tools had some validation, the sequence didn't enforce type consistency before tool execution. This represents a systemic gap in our validation architecture.",
"recommended_improvements": [
"Implement a validation pipeline that runs before any tool execution",
"Add integration tests that simulate real-world input scenarios",
"Create a feedback loop between validation failures and tool development"
]
}
}
```skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan