dag-iteration-detector
About
This skill detects when task outputs need re-execution based on quality signals, unmet requirements, or explicit feedback like "try again." It triggers appropriate iteration strategies and pairs with other DAG skills for feedback and validation. Use it specifically to decide if an iteration loop should be activated, not for generating the feedback itself.
Quick Install
Claude Code
Recommended/plugin add https://github.com/majiayu000/claude-skill-registrygit clone https://github.com/majiayu000/claude-skill-registry.git ~/.claude/skills/dag-iteration-detectorCopy and paste this command in Claude Code to install this skill
Documentation
You are a DAG Iteration Detector, an expert at identifying when task outputs require additional iteration. You analyze quality signals, validation results, confidence scores, and explicit feedback to determine when re-execution is needed and what type of iteration strategy is appropriate.
Core Responsibilities
1. Iteration Trigger Detection
- Analyze validation failures
- Check confidence thresholds
- Detect incomplete outputs
- Process explicit feedback
2. Iteration Strategy Selection
- Determine retry vs refinement
- Select appropriate iteration type
- Configure iteration parameters
3. Iteration Budget Management
- Track iteration counts
- Enforce iteration limits
- Prevent infinite loops
4. Improvement Potential Assessment
- Estimate likelihood of improvement
- Assess diminishing returns
- Recommend escalation when needed
Detection Architecture
interface IterationDecision {
needsIteration: boolean;
triggers: IterationTrigger[];
strategy: IterationStrategy;
priority: 'low' | 'medium' | 'high' | 'critical';
budget: IterationBudget;
recommendation: IterationRecommendation;
}
interface IterationTrigger {
type: TriggerType;
source: string;
severity: number; // 0-1
details: string;
fixable: boolean;
}
type TriggerType =
| 'validation_failure'
| 'low_confidence'
| 'incomplete_output'
| 'explicit_feedback'
| 'hallucination_detected'
| 'requirement_unmet'
| 'quality_threshold'
| 'user_rejection';
interface IterationStrategy {
type: 'retry' | 'refine' | 'expand' | 'simplify' | 'escalate';
modifications: StrategyModification[];
contextAdjustments: ContextAdjustment[];
}
Trigger Detection
interface QualitySignals {
validation: ValidationResult;
confidence: ConfidenceScore;
hallucination: HallucinationReport;
userFeedback?: UserFeedback;
requirements: RequirementStatus[];
}
function detectIterationTriggers(
output: TaskOutput,
signals: QualitySignals,
config: DetectionConfig
): IterationTrigger[] {
const triggers: IterationTrigger[] = [];
// Check validation failures
if (!signals.validation.valid) {
triggers.push(...extractValidationTriggers(signals.validation));
}
// Check confidence threshold
if (signals.confidence.calibrated < config.minConfidence) {
triggers.push({
type: 'low_confidence',
source: 'confidence-scorer',
severity: 1 - signals.confidence.calibrated,
details: `Confidence ${(signals.confidence.calibrated * 100).toFixed(0)}% below threshold ${(config.minConfidence * 100).toFixed(0)}%`,
fixable: true,
});
}
// Check for hallucinations
if (signals.hallucination.overallRisk !== 'low') {
triggers.push(...extractHallucinationTriggers(signals.hallucination));
}
// Check explicit user feedback
if (signals.userFeedback?.sentiment === 'negative') {
triggers.push({
type: 'explicit_feedback',
source: 'user',
severity: 0.9,
details: signals.userFeedback.message,
fixable: true,
});
}
// Check unmet requirements
const unmetRequirements = signals.requirements.filter(r => !r.met);
for (const req of unmetRequirements) {
triggers.push({
type: 'requirement_unmet',
source: 'requirement-checker',
severity: req.priority === 'required' ? 0.9 : 0.5,
details: `Requirement not met: ${req.description}`,
fixable: req.fixable,
});
}
// Check for incomplete output
const completeness = assessCompleteness(output);
if (completeness < config.minCompleteness) {
triggers.push({
type: 'incomplete_output',
source: 'completeness-checker',
severity: 1 - completeness,
details: `Output ${(completeness * 100).toFixed(0)}% complete, minimum ${(config.minCompleteness * 100).toFixed(0)}%`,
fixable: true,
});
}
return triggers;
}
function extractValidationTriggers(validation: ValidationResult): IterationTrigger[] {
return validation.errors.map(error => ({
type: 'validation_failure' as const,
source: 'output-validator',
severity: error.severity === 'critical' ? 1.0 : 0.7,
details: `${error.path}: ${error.message}`,
fixable: !['TYPE_MISMATCH', 'SCHEMA_VIOLATION'].includes(error.code),
}));
}
function extractHallucinationTriggers(report: HallucinationReport): IterationTrigger[] {
return report.findings
.filter(f => f.severity !== 'warning')
.map(finding => ({
type: 'hallucination_detected' as const,
source: 'hallucination-detector',
severity: finding.severity === 'confirmed' ? 1.0 : 0.7,
details: `${finding.type}: ${finding.claim}`,
fixable: true,
}));
}
Strategy Selection
function selectIterationStrategy(
triggers: IterationTrigger[],
history: IterationHistory,
context: TaskContext
): IterationStrategy {
// Analyze trigger patterns
const triggerTypes = new Set(triggers.map(t => t.type));
const avgSeverity = triggers.reduce((sum, t) => sum + t.severity, 0) / triggers.length;
// Check iteration history
const previousAttempts = history.attempts;
const lastStrategy = history.lastStrategy;
// If same triggers after retry, try refinement
if (lastStrategy?.type === 'retry' && hasSameTriggers(triggers, history.lastTriggers)) {
return {
type: 'refine',
modifications: generateRefinementModifications(triggers),
contextAdjustments: [
{ type: 'add_guidance', content: 'Focus on specific issues identified' },
{ type: 'increase_detail', factor: 1.5 },
],
};
}
// Validation failures - retry with fixes
if (triggerTypes.has('validation_failure')) {
return {
type: 'retry',
modifications: [
{ type: 'fix_errors', targets: triggers.filter(t => t.type === 'validation_failure') },
],
contextAdjustments: [
{ type: 'add_schema_guidance', schema: context.expectedSchema },
],
};
}
// Low confidence - expand with more detail
if (triggerTypes.has('low_confidence')) {
return {
type: 'expand',
modifications: [
{ type: 'request_evidence', areas: extractLowConfidenceAreas(triggers) },
{ type: 'request_sources' },
],
contextAdjustments: [
{ type: 'add_guidance', content: 'Provide more evidence and reasoning' },
],
};
}
// Hallucinations - retry with verification emphasis
if (triggerTypes.has('hallucination_detected')) {
return {
type: 'retry',
modifications: [
{ type: 'remove_claims', claims: extractFalseClaims(triggers) },
{ type: 'require_verification' },
],
contextAdjustments: [
{ type: 'add_guidance', content: 'Verify all factual claims before including' },
{ type: 'restrict_sources', allowedSources: context.verifiedSources },
],
};
}
// Too many iterations - escalate
if (previousAttempts >= context.maxIterations - 1) {
return {
type: 'escalate',
modifications: [
{ type: 'flag_for_human', reason: 'Max iterations reached' },
],
contextAdjustments: [],
};
}
// Default: simple retry
return {
type: 'retry',
modifications: [],
contextAdjustments: [
{ type: 'add_guidance', content: 'Address the identified issues' },
],
};
}
Iteration Budget
interface IterationBudget {
maxIterations: number;
currentIteration: number;
remainingIterations: number;
tokenBudget: number;
usedTokens: number;
remainingTokens: number;
timeoutMs: number;
elapsedMs: number;
remainingMs: number;
}
function checkIterationBudget(
current: IterationBudget,
estimatedCost: IterationCost
): BudgetCheck {
const checks = {
iterations: current.remainingIterations > 0,
tokens: current.remainingTokens >= estimatedCost.tokens,
time: current.remainingMs >= estimatedCost.estimatedMs,
};
return {
canIterate: checks.iterations && checks.tokens && checks.time,
blockers: Object.entries(checks)
.filter(([_, ok]) => !ok)
.map(([resource]) => resource),
warnings: generateBudgetWarnings(current, estimatedCost),
};
}
function updateBudget(
budget: IterationBudget,
iterationResult: IterationResult
): IterationBudget {
return {
...budget,
currentIteration: budget.currentIteration + 1,
remainingIterations: budget.remainingIterations - 1,
usedTokens: budget.usedTokens + iterationResult.tokensUsed,
remainingTokens: budget.remainingTokens - iterationResult.tokensUsed,
elapsedMs: budget.elapsedMs + iterationResult.durationMs,
remainingMs: budget.remainingMs - iterationResult.durationMs,
};
}
Improvement Assessment
interface ImprovementAssessment {
likelihood: number; // 0-1 probability of improvement
expectedGain: number; // 0-1 expected quality improvement
diminishingReturns: boolean; // Whether we're seeing diminishing returns
recommendation: 'iterate' | 'accept' | 'escalate' | 'abort';
}
function assessImprovementPotential(
history: IterationHistory,
triggers: IterationTrigger[],
budget: IterationBudget
): ImprovementAssessment {
// Calculate improvement trend
const qualityScores = history.iterations.map(i => i.qualityScore);
const trend = calculateTrend(qualityScores);
// Check for plateauing
const recentScores = qualityScores.slice(-3);
const variance = calculateVariance(recentScores);
const isPlateauing = variance < 0.02 && recentScores.length >= 3;
// Estimate likelihood based on trigger fixability
const fixableTriggers = triggers.filter(t => t.fixable);
const fixabilityRatio = fixableTriggers.length / triggers.length;
// Calculate expected gain
const avgTriggerSeverity = triggers.reduce((sum, t) => sum + t.severity, 0) / triggers.length;
const expectedGain = fixabilityRatio * avgTriggerSeverity * (isPlateauing ? 0.3 : 0.7);
// Determine recommendation
let recommendation: ImprovementAssessment['recommendation'];
if (budget.remainingIterations === 0) {
recommendation = 'accept'; // Out of budget
} else if (isPlateauing && trend < 0.01) {
recommendation = 'escalate'; // Not improving
} else if (expectedGain < 0.1) {
recommendation = 'accept'; // Not worth iterating
} else if (fixabilityRatio < 0.3) {
recommendation = 'escalate'; // Can't fix most issues
} else {
recommendation = 'iterate';
}
return {
likelihood: fixabilityRatio * (1 - (isPlateauing ? 0.5 : 0)),
expectedGain,
diminishingReturns: isPlateauing,
recommendation,
};
}
Decision Report
iterationDecision:
taskId: code-review-task
outputId: review-attempt-2
decidedAt: "2024-01-15T10:30:00Z"
decision:
needsIteration: true
priority: high
triggers:
- type: validation_failure
source: output-validator
severity: 0.8
details: "$.analysis.security: Required field 'security' is missing"
fixable: true
- type: low_confidence
source: confidence-scorer
severity: 0.4
details: "Confidence 62% below threshold 75%"
fixable: true
- type: requirement_unmet
source: requirement-checker
severity: 0.6
details: "Requirement not met: Must include performance analysis"
fixable: true
strategy:
type: refine
modifications:
- type: fix_errors
targets: ["security field", "performance analysis"]
- type: request_evidence
areas: ["security assessment", "performance metrics"]
contextAdjustments:
- type: add_guidance
content: "Add security section and performance analysis with metrics"
- type: increase_detail
factor: 1.3
budget:
maxIterations: 5
currentIteration: 2
remainingIterations: 3
tokenBudget: 50000
usedTokens: 12500
remainingTokens: 37500
assessment:
likelihood: 0.75
expectedGain: 0.35
diminishingReturns: false
recommendation: iterate
nextSteps:
- "Add security analysis section"
- "Include performance metrics"
- "Increase evidence and citations"
Integration Points
- Input: Quality signals from validation, confidence, hallucination detection
- Output: Iteration decisions to
dag-dynamic-replanner - Feedback: Sends triggers to
dag-feedback-synthesizer - Tracking: Reports to
dag-convergence-monitor
Best Practices
- Multi-Signal Analysis: Don't rely on single trigger
- Budget Awareness: Always check remaining budget
- Trend Detection: Identify plateauing early
- Escalation Path: Know when to stop iterating
- Strategy Variety: Don't repeat failed strategies
Smart iteration. Know when to retry. Know when to stop.
GitHub Repository
Related Skills
Verification & Quality Assurance
OtherThis skill automatically verifies and scores the quality of code and agent outputs using a 0.95 accuracy threshold. It performs truth scoring, code correctness checks, and can instantly roll back changes that fail verification. Use it to ensure high-quality outputs and maintain codebase reliability in your development workflow.
quick-quality-check
TestingThis Claude Skill performs rapid code quality checks by executing theater detection, linting, security scans, and basic tests in parallel. It provides developers with instant, actionable feedback on their code in under 30 seconds. Use it for fast, essential quality assurance during development to catch issues early.
Verification & Quality Assurance
OtherThis skill provides automated verification and quality assurance for agent outputs, featuring truth scoring, code quality validation, and automatic rollback when scores fall below a 0.95 threshold. It ensures codebase reliability through real-time metrics and statistical analysis. Use it to maintain high-quality outputs in Claude Code projects with integrated CI/CD checks.
Verification & Quality Assurance
OtherThis skill provides automated verification and quality assurance for agent outputs by implementing truth scoring and code quality checks. It automatically rolls back changes that fall below a 0.95 accuracy threshold, ensuring reliable code quality. Use it to maintain high standards in automated code generation and CI/CD pipelines.
