xiaohongshu
xiaohongshu
dag-iteration-detector
Identifies when task outputs require iteration based on quality signals, unmet requirements, or explicit feedback. Triggers appropriate re-execution strategies. Activate on 'needs iteration', 'retry needed', 'not good enough', 'try again', 'refine output'. NOT for feedback generation (use dag-fee...
Full skill instructions
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.
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[];
}
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,
}));
}
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' },
],
};
}
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,
};
}
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,
};
}
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"
dag-dynamic-replannerdag-feedback-synthesizerdag-convergence-monitorSmart iteration. Know when to retry. Know when to stop.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience