kiosapi 0.1.22 → 0.1.24
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 +27 -5
- package/package.json +1 -1
package/dist/agent/run.js
CHANGED
|
@@ -550,10 +550,23 @@ export async function runTurn(s, userText) {
|
|
|
550
550
|
if (count > 1 && READ_ONLY_TOOLS.has(call.function.name) && toolCache.has(sig)) {
|
|
551
551
|
const toolName = call.function.name;
|
|
552
552
|
const cachedOut = toolCache.get(sig) ?? '';
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
553
|
+
// Always include the cached content so the model has the data it needs even after
|
|
554
|
+
// trimContext drops old messages from its window. The escalating warning text
|
|
555
|
+
// discourages repetition; withholding the content at count=3+ only causes the model
|
|
556
|
+
// to keep retrying — counter-productive to stopping the loop.
|
|
557
|
+
const stopNote = count >= COUNT_LIMIT - 1
|
|
558
|
+
? `\n\n⚠ STOP (ke-${count}): JANGAN panggil "${toolName}" lagi dengan argumen yang sama. Gunakan tool "selesai" dan jelaskan kendalanya, atau gunakan cari/baca_file dengan path/range BERBEDA.`
|
|
559
|
+
: `\n\n⚠ Cache ke-${count}: "${toolName}" sudah dipanggil ${count}× dengan argumen sama. Gunakan cari atau baca_file(path, mulai=N) untuk bagian berbeda.`;
|
|
560
|
+
const warn = `[Cache ke-${count}]\n${cachedOut}${stopNote}`;
|
|
561
|
+
const cachePathHint = (() => {
|
|
562
|
+
try {
|
|
563
|
+
return ` ${JSON.parse(call.function.arguments).path ?? ''}`;
|
|
564
|
+
}
|
|
565
|
+
catch {
|
|
566
|
+
return '';
|
|
567
|
+
}
|
|
568
|
+
})();
|
|
569
|
+
console.log(dim(` ↩ ${toolName}${cachePathHint} (cache ke-${count})`));
|
|
557
570
|
s.messages.push({ role: 'tool', content: warn, tool_call_id: call.id });
|
|
558
571
|
continue;
|
|
559
572
|
}
|
|
@@ -567,8 +580,17 @@ export async function runTurn(s, userText) {
|
|
|
567
580
|
? `${result.output.slice(0, MAX_STORED_RESULT)}\n…[dipotong — gunakan baca_file(path, baris_lanjutan) untuk membaca sisa file]`
|
|
568
581
|
: result.output;
|
|
569
582
|
s.messages.push({ role: 'tool', content: stored, tool_call_id: call.id });
|
|
570
|
-
if (result.modifiedPath)
|
|
583
|
+
if (result.modifiedPath) {
|
|
571
584
|
stepModified.add(result.modifiedPath);
|
|
585
|
+
// Invalidate cached reads for the modified file so the model can verify
|
|
586
|
+
// its own edits without getting stale content or spurious loop warnings.
|
|
587
|
+
for (const cacheSig of [...toolCache.keys()]) {
|
|
588
|
+
if (cacheSig.includes(result.modifiedPath)) {
|
|
589
|
+
toolCache.delete(cacheSig);
|
|
590
|
+
callCounts.delete(cacheSig);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
572
594
|
if (READ_ONLY_TOOLS.has(call.function.name))
|
|
573
595
|
toolCache.set(sig, stored);
|
|
574
596
|
if (result.done) {
|