feat(tui): add self modes to /compact (#1119)
Co-authored-by: Amy Guan <amy@letta.com>
This commit is contained in:
4
bun.lock
4
bun.lock
@@ -5,7 +5,7 @@
|
||||
"": {
|
||||
"name": "@letta-ai/letta-code",
|
||||
"dependencies": {
|
||||
"@letta-ai/letta-client": "^1.7.8",
|
||||
"@letta-ai/letta-client": "^1.7.9",
|
||||
"glob": "^13.0.0",
|
||||
"ink-link": "^5.0.0",
|
||||
"open": "^10.2.0",
|
||||
@@ -93,7 +93,7 @@
|
||||
|
||||
"@isaacs/brace-expansion": ["@isaacs/brace-expansion@5.0.0", "", { "dependencies": { "@isaacs/balanced-match": "^4.0.1" } }, "sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA=="],
|
||||
|
||||
"@letta-ai/letta-client": ["@letta-ai/letta-client@1.7.8", "", {}, "sha512-l7BGsAZOI8b+H1RO2IMzMv3P0VXj6Of2wXLCg5LZejOk0dHLLBi2me4WspLg+6zWPGIRJwMRsxmfp4kV9Zzh6g=="],
|
||||
"@letta-ai/letta-client": ["@letta-ai/letta-client@1.7.9", "", {}, "sha512-ZoUH71/c5t7/7H5DF52lduAKGCet/UoAe2PZTwKCt7CpENdyVlAsM1gV3q8xABmu4RZ1zmwiOjbQT8yWty6w3g=="],
|
||||
|
||||
"@types/bun": ["@types/bun@1.3.7", "", { "dependencies": { "bun-types": "1.3.7" } }, "sha512-lmNuMda+Z9b7tmhA0tohwy8ZWFSnmQm1UDWXtH5r9F7wZCfkeO3Jx7wKQ1EOiKq43yHts7ky6r8SDJQWRNupkA=="],
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
"dependencies": {
|
||||
"@letta-ai/letta-client": "^1.7.8",
|
||||
"@letta-ai/letta-client": "^1.7.9",
|
||||
"glob": "^13.0.0",
|
||||
"ink-link": "^5.0.0",
|
||||
"open": "^10.2.0",
|
||||
|
||||
@@ -7689,11 +7689,16 @@ export default function App({
|
||||
}
|
||||
|
||||
// Special handling for /compact command - summarize conversation history
|
||||
// Supports: /compact, /compact all, /compact sliding_window
|
||||
// Supports: /compact, /compact all, /compact sliding_window, /compact self_compact_all, /compact self_compact_sliding_window
|
||||
if (msg.trim().startsWith("/compact")) {
|
||||
const parts = msg.trim().split(/\s+/);
|
||||
const rawModeArg = parts[1];
|
||||
const validModes = ["all", "sliding_window"];
|
||||
const validModes = [
|
||||
"all",
|
||||
"sliding_window",
|
||||
"self_compact_all",
|
||||
"self_compact_sliding_window",
|
||||
];
|
||||
|
||||
if (rawModeArg === "help") {
|
||||
const cmd = commandRunner.start(
|
||||
@@ -7709,13 +7714,20 @@ export default function App({
|
||||
" /compact — compact with default mode",
|
||||
" /compact all — compact all messages",
|
||||
" /compact sliding_window — compact with sliding window",
|
||||
" /compact self_compact_all — compact with self compact all",
|
||||
" /compact self_compact_sliding_window — compact with self compact sliding window",
|
||||
" /compact help — show this help",
|
||||
].join("\n");
|
||||
cmd.finish(output, true);
|
||||
return { submitted: true };
|
||||
}
|
||||
|
||||
const modeArg = rawModeArg as "all" | "sliding_window" | undefined;
|
||||
const modeArg = rawModeArg as
|
||||
| "all"
|
||||
| "sliding_window"
|
||||
| "self_compact_all"
|
||||
| "self_compact_sliding_window"
|
||||
| undefined;
|
||||
|
||||
// Validate mode if provided
|
||||
if (modeArg && !validModes.includes(modeArg)) {
|
||||
@@ -7753,23 +7765,15 @@ export default function App({
|
||||
|
||||
const client = await getClient();
|
||||
|
||||
// Compute model handle from llmConfig
|
||||
const modelHandle =
|
||||
llmConfig?.model_endpoint_type && llmConfig?.model
|
||||
? `${llmConfig.model_endpoint_type}/${llmConfig.model}`
|
||||
: llmConfig?.model || null;
|
||||
|
||||
// Build compaction settings if mode was specified
|
||||
// Pass mode-specific prompt to override any agent defaults
|
||||
const compactParams =
|
||||
modeArg && modelHandle
|
||||
? {
|
||||
compaction_settings: {
|
||||
mode: modeArg,
|
||||
model: modelHandle,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
// On server side, if mode changed, summarize function will use corresponding default prompt for new mode
|
||||
const compactParams = modeArg
|
||||
? {
|
||||
compaction_settings: {
|
||||
mode: modeArg,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
// Use agent-level compact API for "default" conversation,
|
||||
// otherwise use conversation-level API
|
||||
|
||||
@@ -448,7 +448,7 @@ export const commands: Record<string, Command> = {
|
||||
},
|
||||
"/compact": {
|
||||
desc: "Summarize conversation history (compaction) with optional mode",
|
||||
args: "[all|sliding_window]",
|
||||
args: "[all|sliding_window|self_compact_all|self_compact_sliding_window]",
|
||||
handler: () => {
|
||||
// Handled specially in App.tsx to access client and agent ID
|
||||
return "Compacting conversation...";
|
||||
|
||||
Reference in New Issue
Block a user