Skip to content

Commit a53abda

Browse files
committed
refactor(scout-agent): only include compaction tool when warning is injected
The compact_conversation tool is now only available when the token threshold is exceeded and the warning message is injected. This keeps the tool list clean when compaction is not needed. Updated tests to verify: - Tool is NOT available when under threshold - Tool IS available when warning is injected - Tool is NOT available when compaction is disabled
1 parent 9701d4d commit a53abda

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/scout-agent/lib/core.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ describe("coder integration", () => {
954954
});
955955

956956
describe("compaction", () => {
957-
test("buildStreamTextParams includes compaction tool by default", async () => {
957+
test("buildStreamTextParams does not include compaction tool when under threshold", async () => {
958958
const agent = new blink.Agent<Message>();
959959
const scout = new Scout({
960960
agent,
@@ -973,8 +973,8 @@ describe("compaction", () => {
973973
model: newMockModel({ textResponse: "test" }),
974974
});
975975

976-
// Verify compaction tool is included
977-
expect(params.tools[COMPACT_CONVERSATION_TOOL_NAME]).toBeDefined();
976+
// Verify compaction tool is NOT included when under threshold
977+
expect(params.tools[COMPACT_CONVERSATION_TOOL_NAME]).toBeUndefined();
978978
});
979979

980980
test("buildStreamTextParams applies existing compaction summary", async () => {
@@ -1106,6 +1106,9 @@ describe("compaction", () => {
11061106
m.content.includes("CONTEXT LIMIT WARNING")
11071107
);
11081108
expect(lastUserMessage).toBeDefined();
1109+
1110+
// Verify compaction tool IS available when warning is injected
1111+
expect(params.tools[COMPACT_CONVERSATION_TOOL_NAME]).toBeDefined();
11091112
});
11101113

11111114
test("buildStreamTextParams respects compaction: false to disable", async () => {
@@ -1136,8 +1139,8 @@ describe("compaction", () => {
11361139
compaction: false,
11371140
});
11381141

1139-
// Compaction tool should still be available (for manual use)
1140-
expect(params.tools[COMPACT_CONVERSATION_TOOL_NAME]).toBeDefined();
1142+
// Compaction tool should NOT be available when compaction is disabled
1143+
expect(params.tools[COMPACT_CONVERSATION_TOOL_NAME]).toBeUndefined();
11411144

11421145
// No warning should be logged even with messages
11431146
const warningLog = warnLogs.find((l) =>

packages/scout-agent/lib/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ export class Scout {
530530
}
531531

532532
const tools = {
533-
...createCompactionTool(),
533+
...(compactionWarningInjected ? createCompactionTool() : {}),
534534
...(this.webSearch.config
535535
? createWebSearchTools({ exaApiKey: this.webSearch.config.exaApiKey })
536536
: {}),

0 commit comments

Comments
 (0)