mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-05 08:10:14 +00:00
[Condense] Add isAutomaticTrigger to condense telemetry (#3798)
This commit is contained in:
parent
329ef4ff0f
commit
ea2fdd5500
4 changed files with 20 additions and 6 deletions
|
|
@ -60,6 +60,7 @@ export type SummarizeResponse = {
|
|||
* @param {ApiHandler} apiHandler - The API handler to use for token counting.
|
||||
* @param {string} systemPrompt - The system prompt for API requests, which should be considered in the context token count
|
||||
* @param {string} taskId - The task ID for the conversation, used for telemetry
|
||||
* @param {boolean} isAutomaticTrigger - Whether the summarization is triggered automatically
|
||||
* @returns {SummarizeResponse} - The result of the summarization operation (see above)
|
||||
*/
|
||||
export async function summarizeConversation(
|
||||
|
|
@ -67,8 +68,9 @@ export async function summarizeConversation(
|
|||
apiHandler: ApiHandler,
|
||||
systemPrompt: string,
|
||||
taskId: string,
|
||||
isAutomaticTrigger?: boolean,
|
||||
): Promise<SummarizeResponse> {
|
||||
telemetryService.captureContextCondensed(taskId)
|
||||
telemetryService.captureContextCondensed(taskId, isAutomaticTrigger ?? false)
|
||||
const response: SummarizeResponse = { messages, cost: 0, summary: "" }
|
||||
const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(0, -N_MESSAGES_TO_KEEP))
|
||||
if (messagesToSummarize.length <= 1) {
|
||||
|
|
|
|||
|
|
@ -525,7 +525,13 @@ describe("truncateConversationIfNeeded", () => {
|
|||
})
|
||||
|
||||
// Verify summarizeConversation was called with the right parameters
|
||||
expect(summarizeSpy).toHaveBeenCalledWith(messagesWithSmallContent, mockApiHandler, "System prompt", taskId)
|
||||
expect(summarizeSpy).toHaveBeenCalledWith(
|
||||
messagesWithSmallContent,
|
||||
mockApiHandler,
|
||||
"System prompt",
|
||||
taskId,
|
||||
true,
|
||||
)
|
||||
|
||||
// Verify the result contains the summary information
|
||||
expect(result).toMatchObject({
|
||||
|
|
@ -663,7 +669,13 @@ describe("truncateConversationIfNeeded", () => {
|
|||
})
|
||||
|
||||
// Verify summarizeConversation was called with the right parameters
|
||||
expect(summarizeSpy).toHaveBeenCalledWith(messagesWithSmallContent, mockApiHandler, "System prompt", taskId)
|
||||
expect(summarizeSpy).toHaveBeenCalledWith(
|
||||
messagesWithSmallContent,
|
||||
mockApiHandler,
|
||||
"System prompt",
|
||||
taskId,
|
||||
true,
|
||||
)
|
||||
|
||||
// Verify the result contains the summary information
|
||||
expect(result).toMatchObject({
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ export async function truncateConversationIfNeeded({
|
|||
const contextPercent = (100 * prevContextTokens) / contextWindow
|
||||
if (contextPercent >= autoCondenseContextPercent || prevContextTokens > allowedTokens) {
|
||||
// Attempt to intelligently condense the context
|
||||
const result = await summarizeConversation(messages, apiHandler, systemPrompt, taskId)
|
||||
const result = await summarizeConversation(messages, apiHandler, systemPrompt, taskId, true)
|
||||
if (result.summary) {
|
||||
return { ...result, prevContextTokens }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ class TelemetryService {
|
|||
this.captureEvent(PostHogClient.EVENTS.TASK.CHECKPOINT_RESTORED, { taskId })
|
||||
}
|
||||
|
||||
public captureContextCondensed(taskId: string): void {
|
||||
this.captureEvent(PostHogClient.EVENTS.TASK.CONTEXT_CONDENSED, { taskId })
|
||||
public captureContextCondensed(taskId: string, isAutomaticTrigger: boolean): void {
|
||||
this.captureEvent(PostHogClient.EVENTS.TASK.CONTEXT_CONDENSED, { taskId, isAutomaticTrigger })
|
||||
}
|
||||
|
||||
public captureSlidingWindowTruncation(taskId: string): void {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue