(droppedMessages: MessageTurn[])
| 329 | * @returns A concise summary string, or null if nothing worth summarizing |
| 330 | */ |
| 331 | export function buildDroppedMessagesSummary(droppedMessages: MessageTurn[]): string | null { |
| 332 | if (droppedMessages.length < 5) return null; |
| 333 | |
| 334 | const toolsUsed = new Set<string>(); |
| 335 | let userMessageCount = 0; |
| 336 | |
| 337 | for (const msg of droppedMessages) { |
| 338 | if (msg.toolCalls) { |
| 339 | for (const tc of msg.toolCalls) { |
| 340 | toolsUsed.add(tc.name); |
| 341 | } |
| 342 | } |
| 343 | if (msg.role === 'user') userMessageCount++; |
| 344 | } |
| 345 | |
| 346 | const parts: string[] = []; |
| 347 | parts.push(`## Earlier Conversation Summary`); |
| 348 | parts.push(`${droppedMessages.length} earlier messages (${userMessageCount} from the user) were dropped from context.`); |
| 349 | |
| 350 | if (toolsUsed.size > 0) { |
| 351 | parts.push(`\n**Tools used earlier:** ${Array.from(toolsUsed).join(', ')}`); |
| 352 | } |
| 353 | |
| 354 | parts.push(`\nIf the user references something from earlier that you don't recall, acknowledge the context was trimmed and offer to look it up or suggest starting a new thread.`); |
| 355 | |
| 356 | return parts.join('\n'); |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Check if a request is likely to exceed context limits. |
no test coverage detected