Skip to content

Commit 948df6d

Browse files
committed
cleanup summarization service chat history logging
1 parent 9a0fa3a commit 948df6d

1 file changed

Lines changed: 22 additions & 27 deletions

File tree

packages/core/src/services/summarizer.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,24 @@ export class SummarizationService {
5454
}
5555
}
5656

57-
try {
58-
await fs.writeFile(
59-
'summarize_tool_prompt.txt',
60-
JSON.stringify(userParts, null, 2),
61-
);
62-
debugLogger.log(
63-
'[DEBUG] Summarized tool output saved to summarize_tool_prompt.txt',
64-
);
65-
} catch (error) {
66-
debugLogger.error(
67-
'[DEBUG] Failed to save summarized tool output to summarize_tool_prompt.txt:',
68-
error,
69-
);
70-
}
71-
7257
const chat = new OllamaChat(
7358
modelConfig as OllamaModelConfig,
7459
SUMMARIZER_SYSTEM_PROMPT,
7560
);
7661

62+
let fileContents = 'Summarizer Service Chat History\n\n';
63+
fileContents += `--- ROLE: system ---\n${SUMMARIZER_SYSTEM_PROMPT}\n---\n\n`;
64+
await this._writeChatHistoryToFile(fileContents);
65+
7766
const toolCallJson = JSON.stringify(userParts);
7867
const userPrompt = SUMMARIZER_USER_PROMPT.replace(
7968
'{{objective}}',
8069
objective,
8170
).replace('{{toolcall}}', toolCallJson);
8271

72+
fileContents += `--- ROLE: user ---\n${userPrompt}\n---\n\n`;
73+
await this._writeChatHistoryToFile(fileContents);
74+
8375
const messageParams = {
8476
message: [{ text: userPrompt }],
8577
};
@@ -90,6 +82,8 @@ export class SummarizationService {
9082
);
9183

9284
let textResponse = '';
85+
fileContents += `--- ROLE: model ---\n`;
86+
await this._writeChatHistoryToFile(fileContents);
9387

9488
for await (const resp of responseStream) {
9589
if (resp.type === StreamEventType.CHUNK) {
@@ -103,18 +97,8 @@ export class SummarizationService {
10397
}
10498
}
10599
}
106-
107-
try {
108-
await fs.writeFile('summarized_tool_output.txt', textResponse);
109-
debugLogger.log(
110-
'[DEBUG] Summarized tool output saved to summarized_tool_output.txt',
111-
);
112-
} catch (error) {
113-
debugLogger.error(
114-
'[DEBUG] Failed to save summarized tool output to summarized_tool_output.txt:',
115-
error,
116-
);
117-
}
100+
fileContents += `${textResponse}\n---\n\n`;
101+
await this._writeChatHistoryToFile(fileContents);
118102

119103
// Just return the raw text response from the summarizer model.
120104
return textResponse;
@@ -123,4 +107,15 @@ export class SummarizationService {
123107
throw new Error('Summarization using Gemini Model is not implemented.');
124108
}
125109
}
110+
111+
private async _writeChatHistoryToFile(content: string): Promise<void> {
112+
try {
113+
await fs.writeFile(`summarizer_chat_history.txt`, content);
114+
} catch (error) {
115+
debugLogger.error(
116+
'[DEBUG] Failed to write to summarizer_chat_history.txt:',
117+
error,
118+
);
119+
}
120+
}
126121
}

0 commit comments

Comments
 (0)