@iinm/plain-agent 1.14.0 → 1.14.2
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/README.md +1 -1
- package/config/config.predefined.json +85 -17
- package/package.json +1 -1
- package/src/agentLoop.mjs +26 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Plain Agent
|
|
2
2
|
|
|
3
3
|
[](https://github.com/iinm/plain-agent/actions/workflows/github-code-scanning/codeql)
|
|
4
|
-
[](https://socket.dev/npm/package/@iinm/plain-agent)
|
|
5
5
|
[](https://packagephobia.com/result?p=@iinm/plain-agent)
|
|
6
6
|
|
|
7
7
|
A lightweight terminal-based coding agent focused on safety and low token cost
|
|
@@ -496,7 +496,11 @@
|
|
|
496
496
|
}
|
|
497
497
|
},
|
|
498
498
|
"autoCompact": {
|
|
499
|
-
"inputTokensKeys": [
|
|
499
|
+
"inputTokensKeys": [
|
|
500
|
+
"input_tokens",
|
|
501
|
+
"cache_read_input_tokens",
|
|
502
|
+
"cache_creation_input_tokens"
|
|
503
|
+
]
|
|
500
504
|
}
|
|
501
505
|
},
|
|
502
506
|
{
|
|
@@ -526,7 +530,11 @@
|
|
|
526
530
|
}
|
|
527
531
|
},
|
|
528
532
|
"autoCompact": {
|
|
529
|
-
"inputTokensKeys": [
|
|
533
|
+
"inputTokensKeys": [
|
|
534
|
+
"input_tokens",
|
|
535
|
+
"cache_read_input_tokens",
|
|
536
|
+
"cache_creation_input_tokens"
|
|
537
|
+
]
|
|
530
538
|
}
|
|
531
539
|
},
|
|
532
540
|
{
|
|
@@ -557,7 +565,11 @@
|
|
|
557
565
|
}
|
|
558
566
|
},
|
|
559
567
|
"autoCompact": {
|
|
560
|
-
"inputTokensKeys": [
|
|
568
|
+
"inputTokensKeys": [
|
|
569
|
+
"input_tokens",
|
|
570
|
+
"cache_read_input_tokens",
|
|
571
|
+
"cache_creation_input_tokens"
|
|
572
|
+
]
|
|
561
573
|
}
|
|
562
574
|
},
|
|
563
575
|
{
|
|
@@ -588,7 +600,11 @@
|
|
|
588
600
|
}
|
|
589
601
|
},
|
|
590
602
|
"autoCompact": {
|
|
591
|
-
"inputTokensKeys": [
|
|
603
|
+
"inputTokensKeys": [
|
|
604
|
+
"input_tokens",
|
|
605
|
+
"cache_read_input_tokens",
|
|
606
|
+
"cache_creation_input_tokens"
|
|
607
|
+
]
|
|
592
608
|
}
|
|
593
609
|
},
|
|
594
610
|
{
|
|
@@ -619,7 +635,11 @@
|
|
|
619
635
|
}
|
|
620
636
|
},
|
|
621
637
|
"autoCompact": {
|
|
622
|
-
"inputTokensKeys": [
|
|
638
|
+
"inputTokensKeys": [
|
|
639
|
+
"input_tokens",
|
|
640
|
+
"cache_read_input_tokens",
|
|
641
|
+
"cache_creation_input_tokens"
|
|
642
|
+
]
|
|
623
643
|
}
|
|
624
644
|
},
|
|
625
645
|
{
|
|
@@ -650,7 +670,11 @@
|
|
|
650
670
|
}
|
|
651
671
|
},
|
|
652
672
|
"autoCompact": {
|
|
653
|
-
"inputTokensKeys": [
|
|
673
|
+
"inputTokensKeys": [
|
|
674
|
+
"input_tokens",
|
|
675
|
+
"cache_read_input_tokens",
|
|
676
|
+
"cache_creation_input_tokens"
|
|
677
|
+
]
|
|
654
678
|
}
|
|
655
679
|
},
|
|
656
680
|
{
|
|
@@ -681,7 +705,11 @@
|
|
|
681
705
|
}
|
|
682
706
|
},
|
|
683
707
|
"autoCompact": {
|
|
684
|
-
"inputTokensKeys": [
|
|
708
|
+
"inputTokensKeys": [
|
|
709
|
+
"input_tokens",
|
|
710
|
+
"cache_read_input_tokens",
|
|
711
|
+
"cache_creation_input_tokens"
|
|
712
|
+
]
|
|
685
713
|
}
|
|
686
714
|
},
|
|
687
715
|
{
|
|
@@ -712,7 +740,11 @@
|
|
|
712
740
|
}
|
|
713
741
|
},
|
|
714
742
|
"autoCompact": {
|
|
715
|
-
"inputTokensKeys": [
|
|
743
|
+
"inputTokensKeys": [
|
|
744
|
+
"input_tokens",
|
|
745
|
+
"cache_read_input_tokens",
|
|
746
|
+
"cache_creation_input_tokens"
|
|
747
|
+
]
|
|
716
748
|
}
|
|
717
749
|
},
|
|
718
750
|
|
|
@@ -742,7 +774,11 @@
|
|
|
742
774
|
}
|
|
743
775
|
},
|
|
744
776
|
"autoCompact": {
|
|
745
|
-
"inputTokensKeys": [
|
|
777
|
+
"inputTokensKeys": [
|
|
778
|
+
"input_tokens",
|
|
779
|
+
"cache_read_input_tokens",
|
|
780
|
+
"cache_creation_input_tokens"
|
|
781
|
+
]
|
|
746
782
|
}
|
|
747
783
|
},
|
|
748
784
|
{
|
|
@@ -771,7 +807,11 @@
|
|
|
771
807
|
}
|
|
772
808
|
},
|
|
773
809
|
"autoCompact": {
|
|
774
|
-
"inputTokensKeys": [
|
|
810
|
+
"inputTokensKeys": [
|
|
811
|
+
"input_tokens",
|
|
812
|
+
"cache_read_input_tokens",
|
|
813
|
+
"cache_creation_input_tokens"
|
|
814
|
+
]
|
|
775
815
|
}
|
|
776
816
|
},
|
|
777
817
|
{
|
|
@@ -801,7 +841,11 @@
|
|
|
801
841
|
}
|
|
802
842
|
},
|
|
803
843
|
"autoCompact": {
|
|
804
|
-
"inputTokensKeys": [
|
|
844
|
+
"inputTokensKeys": [
|
|
845
|
+
"input_tokens",
|
|
846
|
+
"cache_read_input_tokens",
|
|
847
|
+
"cache_creation_input_tokens"
|
|
848
|
+
]
|
|
805
849
|
}
|
|
806
850
|
},
|
|
807
851
|
{
|
|
@@ -831,7 +875,11 @@
|
|
|
831
875
|
}
|
|
832
876
|
},
|
|
833
877
|
"autoCompact": {
|
|
834
|
-
"inputTokensKeys": [
|
|
878
|
+
"inputTokensKeys": [
|
|
879
|
+
"input_tokens",
|
|
880
|
+
"cache_read_input_tokens",
|
|
881
|
+
"cache_creation_input_tokens"
|
|
882
|
+
]
|
|
835
883
|
}
|
|
836
884
|
},
|
|
837
885
|
{
|
|
@@ -861,7 +909,11 @@
|
|
|
861
909
|
}
|
|
862
910
|
},
|
|
863
911
|
"autoCompact": {
|
|
864
|
-
"inputTokensKeys": [
|
|
912
|
+
"inputTokensKeys": [
|
|
913
|
+
"input_tokens",
|
|
914
|
+
"cache_read_input_tokens",
|
|
915
|
+
"cache_creation_input_tokens"
|
|
916
|
+
]
|
|
865
917
|
}
|
|
866
918
|
},
|
|
867
919
|
{
|
|
@@ -891,7 +943,11 @@
|
|
|
891
943
|
}
|
|
892
944
|
},
|
|
893
945
|
"autoCompact": {
|
|
894
|
-
"inputTokensKeys": [
|
|
946
|
+
"inputTokensKeys": [
|
|
947
|
+
"input_tokens",
|
|
948
|
+
"cache_read_input_tokens",
|
|
949
|
+
"cache_creation_input_tokens"
|
|
950
|
+
]
|
|
895
951
|
}
|
|
896
952
|
},
|
|
897
953
|
{
|
|
@@ -921,7 +977,11 @@
|
|
|
921
977
|
}
|
|
922
978
|
},
|
|
923
979
|
"autoCompact": {
|
|
924
|
-
"inputTokensKeys": [
|
|
980
|
+
"inputTokensKeys": [
|
|
981
|
+
"input_tokens",
|
|
982
|
+
"cache_read_input_tokens",
|
|
983
|
+
"cache_creation_input_tokens"
|
|
984
|
+
]
|
|
925
985
|
}
|
|
926
986
|
},
|
|
927
987
|
{
|
|
@@ -951,7 +1011,11 @@
|
|
|
951
1011
|
}
|
|
952
1012
|
},
|
|
953
1013
|
"autoCompact": {
|
|
954
|
-
"inputTokensKeys": [
|
|
1014
|
+
"inputTokensKeys": [
|
|
1015
|
+
"input_tokens",
|
|
1016
|
+
"cache_read_input_tokens",
|
|
1017
|
+
"cache_creation_input_tokens"
|
|
1018
|
+
]
|
|
955
1019
|
}
|
|
956
1020
|
},
|
|
957
1021
|
|
|
@@ -1820,7 +1884,11 @@
|
|
|
1820
1884
|
}
|
|
1821
1885
|
},
|
|
1822
1886
|
"autoCompact": {
|
|
1823
|
-
"inputTokensKeys": [
|
|
1887
|
+
"inputTokensKeys": [
|
|
1888
|
+
"inputTokens",
|
|
1889
|
+
"cacheReadInputTokens",
|
|
1890
|
+
"cacheWriteInputTokens"
|
|
1891
|
+
]
|
|
1824
1892
|
}
|
|
1825
1893
|
}
|
|
1826
1894
|
]
|
package/package.json
CHANGED
package/src/agentLoop.mjs
CHANGED
|
@@ -109,6 +109,7 @@ export function createAgentLoop({
|
|
|
109
109
|
let thinkingLoops = 0;
|
|
110
110
|
const maxThinkingLoops = 5;
|
|
111
111
|
let turnsAfterCompactPrompt = -1;
|
|
112
|
+
let turnsSinceSubagentReminder = 0;
|
|
112
113
|
while (true) {
|
|
113
114
|
// Check if auto-approve was paused by Ctrl-C during tool execution
|
|
114
115
|
if (pauseSignal.isPaused()) {
|
|
@@ -262,6 +263,9 @@ export function createAgentLoop({
|
|
|
262
263
|
stateManager.appendMessages([{ role: "user", content: toolResults }]);
|
|
263
264
|
}
|
|
264
265
|
|
|
266
|
+
// Subagent reminder: every 5 turns, remind the model of its subagent role
|
|
267
|
+
let autoCompactFired = false;
|
|
268
|
+
|
|
265
269
|
// Auto-compact: insert prompt if context exceeds soft limit
|
|
266
270
|
if (contextSoftLimit && inputTokensKeys && providerTokenUsage) {
|
|
267
271
|
const inputTokens = extractInputTokenCount(
|
|
@@ -286,6 +290,7 @@ export function createAgentLoop({
|
|
|
286
290
|
},
|
|
287
291
|
]);
|
|
288
292
|
turnsAfterCompactPrompt = 0;
|
|
293
|
+
autoCompactFired = true;
|
|
289
294
|
console.error(
|
|
290
295
|
styleText(
|
|
291
296
|
"yellow",
|
|
@@ -295,6 +300,27 @@ export function createAgentLoop({
|
|
|
295
300
|
}
|
|
296
301
|
}
|
|
297
302
|
}
|
|
303
|
+
|
|
304
|
+
if (!subagentManager.isSubagentActive()) {
|
|
305
|
+
turnsSinceSubagentReminder = 0;
|
|
306
|
+
} else if (!autoCompactFired) {
|
|
307
|
+
turnsSinceSubagentReminder += 1;
|
|
308
|
+
// Inject reminder every 5 turns (fires when counter reaches 5, 10, 15, ...)
|
|
309
|
+
if (turnsSinceSubagentReminder % 5 === 0) {
|
|
310
|
+
const activeSubagent = subagentManager.getActiveSubagent();
|
|
311
|
+
stateManager.appendMessages([
|
|
312
|
+
{
|
|
313
|
+
role: "user",
|
|
314
|
+
content: [
|
|
315
|
+
{
|
|
316
|
+
type: "text",
|
|
317
|
+
text: `System: You are subagent "${activeSubagent?.name}". Call "switch_to_main_agent" when your goal is done.`,
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
},
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
298
324
|
}
|
|
299
325
|
}
|
|
300
326
|
|