diff --git a/packages/orchestration-service/src/services/summarization.js b/packages/orchestration-service/src/services/summarization.js index 186200e..54a1118 100644 --- a/packages/orchestration-service/src/services/summarization.js +++ b/packages/orchestration-service/src/services/summarization.js @@ -14,13 +14,13 @@ function buildSummaryPrompt(episodes, existingSummary = null) { .join('\n\n'); const instruction = existingSummary - ? `You have a previous summary of this conversation. Update it to include the new exchanges below. Keep it concise — plain prose, no markdown, no headers, third person, max 200 words. + ? `Update this summary to include the new conversation exchanges below. Output only the updated summary — do not continue the conversation. Previous summary: ${existingSummary} New exchanges to incorporate:` - : `Summarise this conversation. Be concise — plain prose, no markdown, no headers, third person, max 200 words. Preserve key decisions, facts, named entities, and unresolved questions. + : `Summarise this conversation. Output only the summary — do not continue the conversation or give recommendations. Conversation:`; @@ -88,8 +88,12 @@ async function maybeSummarize(session, allEpisodes) { const totalEpisodeTokens = allEpisodes.reduce((sum, ep) => sum + (ep.token_count || 0), 0); // 5. Generate summary — pass existing content if updating + const episodesToSummarize = latest + ? allEpisodes.filter(ep => ep.id > lastCoveredId) + : allEpisodes; + const content = await generateSummary( - allEpisodes, + episodesToSummarize, latest && latest.content.length < MAX_SUMMARY_TOKENS ? latest.content : null // if existing summary is already large, treat as fresh rather than appending to a huge blob );