The Reflector Phase uses a multi-iteration LLM approach to extract insights from a session. It takes a DiaryEntry, the sessionContent, and existingBullets to produce PlaybookDelta[].
To ensure high-quality insights and avoid redundancy, the process:
- Iterates up to
config.maxReflectorIterations times. - Uses a schema-driven LLM call to generate deltas.
- Deduplicates insights within a single reflection cycle using
hashDelta to ensure the same insight isn't proposed multiple times.
async function reflectOnSession(
diary: DiaryEntry,
sessionContent: string,
existingBullets: Bullet[],
config: Config
): Promise<PlaybookDelta[]> {
const allDeltas: PlaybookDelta[] = [];
const seenHashes = new Set<string>();
for (let i = 0; i < config.maxReflectorIterations; i++) {
const deltas = await llm.generateObject({
schema: DeltaSchema,
prompt: buildReflectorPrompt(diary, sessionContent, existingBullets, i)
});
for (const delta of deltas) {
const hash = hashDelta(delta);
if (!seenHashes.has(hash)) {
seenHashes.add(hash);
allDeltas.push(delta);
}
}
if (deltas.length === 0) break;
}
return allDeltas;
}