phase completion justification

This commit is contained in:
overcuriousity
2025-08-11 08:57:16 +02:00
parent 9e42b2a98d
commit d043bba17f
2 changed files with 115 additions and 28 deletions

View File

@@ -1046,7 +1046,7 @@ class ImprovedMicroTaskAIPipeline {
const phaseStart = Date.now();
const phaseQuery = phaseQueryTemplates[phase.id] || `forensic ${phase.name.toLowerCase()} tools methods`;
console.log('[AI-PIPELINE] Starting phase completion micro-task for:', phase.id);
console.log('[AI-PIPELINE] Starting enhanced phase completion micro-task for:', phase.id);
try {
const phaseResults = await embeddingsService.findSimilar(phaseQuery, 20, 0.2);
@@ -1083,42 +1083,96 @@ class ImprovedMicroTaskAIPipeline {
return;
}
const prompt = AI_PROMPTS.generatePhaseCompletionPrompt(originalQuery, phase, phaseTools, phaseConcepts);
const response = await this.callAI(prompt, 800);
const selection = this.safeParseJSON(response, { selectedTools: [], selectedConcepts: [] });
// Step 1: AI selection of tools for completion
const selectionPrompt = AI_PROMPTS.generatePhaseCompletionPrompt(originalQuery, phase, phaseTools, phaseConcepts);
const selectionResult = await this.callMicroTaskAI(selectionPrompt, context, 800);
if (!selectionResult.success) {
console.error('[AI-PIPELINE] Phase completion selection failed for:', phase.id);
return;
}
const selection = this.safeParseJSON(selectionResult.content, {
selectedTools: [],
selectedConcepts: [],
completionReasoning: ''
});
const validTools = selection.selectedTools
.map((name: string) => phaseTools.find((t: any) => t && t.name === name))
.filter((tool: any): tool is NonNullable<any> => tool !== undefined && tool !== null)
.slice(0, 2);
validTools.forEach((tool: any) => {
console.log('[AI-PIPELINE] Adding phase completion tool:', tool.name, 'for', phase.id);
if (validTools.length === 0) {
console.log('[AI-PIPELINE] No valid tools selected for phase completion:', phase.id);
return;
}
// Step 2: Generate detailed reasoning for each selected tool
for (const tool of validTools) {
console.log('[AI-PIPELINE] Generating reasoning for phase completion tool:', tool.name);
const reasoningPrompt = getPrompt(
'phaseCompletionReasoning',
originalQuery,
phase,
tool.name,
tool,
selection.completionReasoning || 'Nachergänzung zur Vervollständigung der Phasenabdeckung'
);
const reasoningResult = await this.callMicroTaskAI(reasoningPrompt, context, 400);
let detailedJustification: string;
if (reasoningResult.success) {
detailedJustification = reasoningResult.content.trim();
} else {
detailedJustification = `Nachträglich hinzugefügt zur Vervollständigung der ${phase.name}-Phase. Die ursprüngliche KI-Auswahl war zu spezifisch und hat wichtige Tools für diese Phase übersehen.`;
}
this.addToolToSelection(
context,
tool,
phase.id,
'medium',
`Hinzugefügt zur Vervollständigung der ${phase.name}-Phase`,
detailedJustification,
75,
['Via phasenspezifische semantische Suche hinzugefügt']
['Nachträgliche Ergänzung via semantische Phasensuche']
);
});
console.log('[AI-PIPELINE] Added phase completion tool with reasoning:', tool.name);
}
this.addAuditEntry(
context,
'validation',
'phase-completion',
{ phase: phase.id, phaseQuery, candidatesFound: phaseTools.length },
{ toolsAdded: validTools.length, addedTools: validTools.map((t: any) => t.name) },
{
phase: phase.id,
phaseQuery,
candidatesFound: phaseTools.length,
selectionReasoning: selection.completionReasoning
},
{
toolsAdded: validTools.length,
addedTools: validTools.map((t: any) => ({
name: t.name,
type: t.type,
reasoning: 'Generated via micro-task'
}))
},
validTools.length > 0 ? 80 : 40,
phaseStart,
{ phaseCompletion: true, semanticSearch: true }
{
phaseCompletion: true,
semanticSearch: true,
microTaskReasoning: true,
contextualExplanation: true
}
);
} catch (error) {
console.error('[AI-PIPELINE] Phase completion failed for:', phase.id, error);
console.error('[AI-PIPELINE] Enhanced phase completion failed for:', phase.id, error);
this.addAuditEntry(
context,