feat: render summarization/compact user message (#736)

This commit is contained in:
jnjpng
2026-01-28 18:16:50 -08:00
committed by GitHub
parent bbfb56ab84
commit af1f2df260
3 changed files with 47 additions and 11 deletions

View File

@@ -5,7 +5,11 @@ import type {
Message,
TextContent,
} from "@letta-ai/letta-client/resources/agents/messages";
import { SYSTEM_REMINDER_CLOSE, SYSTEM_REMINDER_OPEN } from "../../constants";
import {
COMPACTION_SUMMARY_HEADER,
SYSTEM_REMINDER_CLOSE,
SYSTEM_REMINDER_OPEN,
} from "../../constants";
import type { Buffers } from "./accumulator";
/**
@@ -81,7 +85,7 @@ function truncateSystemReminder(text: string, maxLength: number): string {
* Check if a user message is a compaction summary (system_alert with summary content).
* Returns the summary text if found, null otherwise.
*/
function extractCompactionSummary(text: string): string | null {
export function extractCompactionSummary(text: string): string | null {
try {
const parsed = JSON.parse(text);
if (
@@ -182,17 +186,12 @@ export function backfillBuffers(buffers: Buffers, history: Message[]): void {
// Check if this is a compaction summary message (system_alert with summary)
const compactionSummary = extractCompactionSummary(rawText);
if (compactionSummary) {
// Render as a synthetic tool call showing the compaction
// Render as a user message with context header and summary
const exists = buffers.byId.has(lineId);
buffers.byId.set(lineId, {
kind: "tool_call",
kind: "user",
id: lineId,
toolCallId: `compaction-${lineId}`,
name: "Compact",
argsText: "messages[...]",
resultText: compactionSummary,
resultOk: true,
phase: "finished",
text: `${COMPACTION_SUMMARY_HEADER}\n\n${compactionSummary}`,
});
if (!exists) buffers.order.push(lineId);
break;