File size: 3,736 Bytes
35b8b9c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | import { Agent, ScholasticAnalysisReport, AnalysisSuggestion } from '../types';
import { ScholasticAPI } from './geminiService';
export const ScholasticAnalysisService = {
/**
* Performs a deep scholastic audit of the hive's current configuration.
*/
async conductDeepAudit(
agents: Agent[],
systemIntegrity: number,
alignmentScore: number,
): Promise<ScholasticAnalysisReport> {
try {
const simplifiedAgents = agents.map((a) => ({
name: a.name,
role: a.scholasticRole,
merit: a.meritLevel,
weight: a.weight,
accuracy: a.predictionAccuracy,
alignment: a.ethicalAlignment,
}));
const { SCHOLASTIC_BOUNDARY_START, SCHOLASTIC_BOUNDARY_END } = ScholasticAPI as any; // Hack if not directly exported, but I exported them
// Since they are exported from geminiService.ts:
const { SCHOLASTIC_BOUNDARY_START: startBound, SCHOLASTIC_BOUNDARY_END: endBound } =
await import('./geminiService');
const prompt = `Perform a Chancellor-level Scholastic Audit of the current AI Hive.
System Stats:
- Integrity: ${(systemIntegrity * 100).toFixed(1)}%
- Alignment: ${(alignmentScore * 100).toFixed(1)}%
Agent Substrates:
${JSON.stringify(simplifiedAgents, null, 2)}
Respond with a highly academic JSON report wrapped in boundaries: ${startBound} [...] ${endBound}
{
"averageMerit": 0.0-1.0,
"crossTalkNoise": 0.0-1.0,
"suggestions": [
{
"type": "WEIGHT|LOGIC|ETHICS|ALIGNMENT",
"description": "...",
"impact": 0.0-1.0
}
]
}`;
const responseText = await ScholasticAPI.chancellorDirective(
prompt,
'High Chancellor of the Lyceum Analysis Bureau',
);
const data = ScholasticAPI.parseScholasticJson<any>(responseText);
const suggestions: AnalysisSuggestion[] = (data.suggestions || []).map(
(s: {
type: 'WEIGHT' | 'LOGIC' | 'ETHICS' | 'ALIGNMENT';
description: string;
impact: number;
}) => ({
id: `SUG-${Math.random().toString(36).substring(2, 9).toUpperCase()}`,
type: s.type,
description: s.description,
impact: s.impact,
isApplied: false,
}),
);
return {
id: `REPORT-${Date.now()}`,
timestamp: new Date().toISOString(),
metrics: {
averageMerit: data.averageMerit || 0.5,
systemIntegrity,
alignmentScore,
crossTalkNoise: data.crossTalkNoise || 0.1,
},
suggestions,
status: 'Finalized',
};
} catch (error) {
console.error('Scholastic Audit Failed:', error);
throw error;
}
},
/**
* Refines the alignment score weights based on human feedback.
*/
async refineWeights(
currentWeights: Record<string, number>,
userFeedback: string,
): Promise<Record<string, number>> {
const { SCHOLASTIC_BOUNDARY_START, SCHOLASTIC_BOUNDARY_END } = await import('./geminiService');
const prompt = `Current System Weights: ${JSON.stringify(currentWeights)}
Chancellor Feedback: "${userFeedback}"
Adjust weights to reflect this feedback while maintaining academic integrity.
Respond ONLY with the updated weights JSON object wrapped in boundaries ${SCHOLASTIC_BOUNDARY_START} [...] ${SCHOLASTIC_BOUNDARY_END}.`;
const responseText = await ScholasticAPI.generateText(
prompt,
"You are the Gewicht-Alignment Protocol. You balance the Academy's priorities.",
);
return ScholasticAPI.parseScholasticJson<Record<string, number>>(responseText);
},
};
|