kiosapi 0.1.24 → 0.1.25
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/agent/run.js +25 -2
- package/package.json +1 -1
package/dist/agent/run.js
CHANGED
|
@@ -56,9 +56,32 @@ function trimContext(messages) {
|
|
|
56
56
|
const dropped = clean.length - tail.length;
|
|
57
57
|
if (dropped <= 0)
|
|
58
58
|
return [system, ...clean];
|
|
59
|
+
// Collect baca_file paths from the dropped messages so the model knows which files it
|
|
60
|
+
// already has context for — prevents it from re-orienting by re-reading config/schema files.
|
|
61
|
+
const droppedHead = clean.slice(0, clean.length - tail.length + skip);
|
|
62
|
+
const droppedPaths = [];
|
|
63
|
+
for (const msg of droppedHead) {
|
|
64
|
+
if (msg.role === 'assistant' && msg.tool_calls) {
|
|
65
|
+
for (const tc of msg.tool_calls) {
|
|
66
|
+
if (tc.function?.name === 'baca_file') {
|
|
67
|
+
try {
|
|
68
|
+
const a = JSON.parse(tc.function.arguments ?? '{}');
|
|
69
|
+
if (a.path)
|
|
70
|
+
droppedPaths.push(a.path);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
/* ignore */
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const filesNote = droppedPaths.length > 0
|
|
80
|
+
? ` File sudah dibaca (tak lagi di window): ${[...new Set(droppedPaths)].join(', ')}. JANGAN baca ulang — gunakan cari untuk mencari teks spesifik.`
|
|
81
|
+
: '';
|
|
59
82
|
const note = {
|
|
60
83
|
role: 'system',
|
|
61
|
-
content: `[Kiosapi: ${dropped} pesan awal dihapus dari konteks
|
|
84
|
+
content: `[Kiosapi: ${dropped} pesan awal dihapus dari konteks.${filesNote}]`,
|
|
62
85
|
};
|
|
63
86
|
return [system, note, ...tail];
|
|
64
87
|
}
|
|
@@ -452,7 +475,7 @@ export async function runTurn(s, userText) {
|
|
|
452
475
|
// other calls (daftar src, baca ...) appear between the repeating call.
|
|
453
476
|
const callCounts = new Map();
|
|
454
477
|
const lastSigs = []; // last 3 sigs for consecutive detection
|
|
455
|
-
const COUNT_LIMIT =
|
|
478
|
+
const COUNT_LIMIT = 6; // same tool+args called 6× total → loop (higher because cache now returns content)
|
|
456
479
|
const CONSEC_LIMIT = 3; // same sig 3× in a row → loop
|
|
457
480
|
// Read-only tool cache: on 2nd+ identical call, return the previous result with a warning
|
|
458
481
|
// instead of re-running. This gives the model early feedback so it can self-correct before
|