@tjamescouch/gro 1.3.14 → 1.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/memory/advanced-memory.js +35 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -20,7 +20,7 @@ export class AdvancedMemory extends AgentMemory {
|
|
|
20
20
|
this.highRatio = Math.min(0.95, Math.max(0.55, args.highRatio ?? 0.70));
|
|
21
21
|
this.lowRatio = Math.min(this.highRatio - 0.05, Math.max(0.35, args.lowRatio ?? 0.50));
|
|
22
22
|
this.summaryRatio = Math.min(0.50, Math.max(0.15, args.summaryRatio ?? 0.35));
|
|
23
|
-
this.avgCharsPerToken = Math.max(1.5, Number(args.avgCharsPerToken ??
|
|
23
|
+
this.avgCharsPerToken = Math.max(1.5, Number(args.avgCharsPerToken ?? 2.8));
|
|
24
24
|
this.keepRecentPerLane = Math.max(1, Math.floor(args.keepRecentPerLane ?? 4));
|
|
25
25
|
this.keepRecentTools = Math.max(0, Math.floor(args.keepRecentTools ?? 3));
|
|
26
26
|
}
|
|
@@ -42,6 +42,40 @@ export class AdvancedMemory extends AgentMemory {
|
|
|
42
42
|
createdAt: new Date().toISOString(),
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Return messages for the API, with hard truncation as a safety net.
|
|
47
|
+
* Even if background summarization hasn't caught up, this ensures we never
|
|
48
|
+
* send more than the configured context budget to the driver.
|
|
49
|
+
*/
|
|
50
|
+
messages() {
|
|
51
|
+
const budget = this.budgetTokens();
|
|
52
|
+
const all = [...this.messagesBuffer];
|
|
53
|
+
const estTok = this.estimateTokens(all);
|
|
54
|
+
// If under budget, return everything (common case)
|
|
55
|
+
if (estTok <= budget)
|
|
56
|
+
return all;
|
|
57
|
+
// Hard truncation: keep system prompt + most recent messages that fit
|
|
58
|
+
const result = [];
|
|
59
|
+
let usedTok = 0;
|
|
60
|
+
// Always keep the system prompt (first message if system role)
|
|
61
|
+
if (all.length > 0 && all[0].role === "system") {
|
|
62
|
+
result.push(all[0]);
|
|
63
|
+
usedTok = this.estimateTokens(result);
|
|
64
|
+
}
|
|
65
|
+
// Walk backwards from the end, adding messages until we hit budget
|
|
66
|
+
const toAdd = [];
|
|
67
|
+
for (let i = all.length - 1; i >= (result.length > 0 ? 1 : 0); i--) {
|
|
68
|
+
const candidate = [all[i], ...toAdd];
|
|
69
|
+
const candidateTok = this.estimateTokens(candidate);
|
|
70
|
+
if (usedTok + candidateTok <= budget) {
|
|
71
|
+
toAdd.unshift(all[i]);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
break; // No more room
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return [...result, ...toAdd];
|
|
78
|
+
}
|
|
45
79
|
async onAfterAdd() {
|
|
46
80
|
const budget = this.budgetTokens();
|
|
47
81
|
const estTok = this.estimateTokens(this.messagesBuffer);
|
package/dist/package.json
CHANGED