teapot-coding-agent 0.37.122 → 0.37.123
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/agent.js
CHANGED
|
@@ -8,7 +8,7 @@ import { createCatalog } from "./tool-catalog.js";
|
|
|
8
8
|
import { resetToolCatalog, executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, isRequestNodeLimit, hasRunningBgShells, hasRunningBgShellsFor, killBgShells, runningBgShellCount } from "./tools.js";
|
|
9
9
|
import { effortChoosable } from "./llm.js";
|
|
10
10
|
import { turnAnchor } from "./timing.js";
|
|
11
|
-
import { claimsContextLimit, usageLine } from "./context-claim.js";
|
|
11
|
+
import { claimsContextLimit, claimsOwnLimit, usageLine } from "./context-claim.js";
|
|
12
12
|
import { namesBlocker } from "./blocker.js";
|
|
13
13
|
import { mcp } from "./mcp-registry.js";
|
|
14
14
|
import { flattenToolName } from "./mcp-registry.js";
|
|
@@ -248,6 +248,14 @@ export class Agent {
|
|
|
248
248
|
lastTurnEndedAt = null;
|
|
249
249
|
/** the last assistant text, so the loop can tell a context-limit stop from a real one (#201) */
|
|
250
250
|
lastAssistantText = "";
|
|
251
|
+
/**
|
|
252
|
+
* The last turn's REASONING.
|
|
253
|
+
*
|
|
254
|
+
* The claim usually lives here, not in the visible text: akku1139/teapot#201's follow-up shows a turn whose
|
|
255
|
+
* reasoning reads "My context is nearly exhausted … let me give a final status and stop" while the message it
|
|
256
|
+
* sends is an ordinary status. Checking only the message missed exactly the case that was reported.
|
|
257
|
+
*/
|
|
258
|
+
lastReasoning = "";
|
|
251
259
|
/** how many times this stale round has been answered — bounded so the answer cannot become the loop */
|
|
252
260
|
contextClaimNudges = 0;
|
|
253
261
|
/** #200: a finish(false) that names no blocker is questioned once, never twice */
|
|
@@ -264,16 +272,29 @@ export class Agent {
|
|
|
264
272
|
* (#201) or inside `finish(goalComplete=false)`'s summary, which is how it actually arrived three times in
|
|
265
273
|
* `mediapad-t5-root-attempt-2-2601e254` (#200 is the same event seen as a stopping habit).
|
|
266
274
|
*/
|
|
275
|
+
/**
|
|
276
|
+
* The answer to "I have run out of context".
|
|
277
|
+
*
|
|
278
|
+
* ONE answer for both things that get said this way: the (false) claim that the window is full, and the real
|
|
279
|
+
* stuck-in-my-own-reasoning case. They are hard to tell apart from the text — "どっちのパターンでも同じようなこと
|
|
280
|
+
* 喋るから混同してる可能性もある" — so the answer does not try: it states the MEASURED window and asks for a new
|
|
281
|
+
* perspective, which is the useful half of both.
|
|
282
|
+
*/
|
|
267
283
|
contextClaimAnswer(where) {
|
|
268
|
-
|
|
269
|
-
(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
`
|
|
273
|
-
|
|
274
|
-
`
|
|
275
|
-
`
|
|
276
|
-
`
|
|
284
|
+
const head = where === "finish"
|
|
285
|
+
? "That finish() was refused: it gives the context window as the blocker, and the window is not yours to run out of."
|
|
286
|
+
: "You stopped, giving the context window as the reason.";
|
|
287
|
+
return (`${this.timeAnchor()}\n[harness] ${head} The numbers above are MEASURED, compaction is automatic and has ` +
|
|
288
|
+
`just run — so how much window is left is not something you have to guess, and continuing the same way ` +
|
|
289
|
+
`would land you here again in a few turns. Change the perspective instead:\n` +
|
|
290
|
+
`1. Write down what you have LEARNED (add_memory) and what is LEFT (set_todo), so nothing depends on ` +
|
|
291
|
+
`holding this conversation in your head.\n` +
|
|
292
|
+
`2. Name the exact question you cannot answer ("I cannot tell whether X, because Y") and call ask_user with ` +
|
|
293
|
+
`it — or list what you have already ruled out and pick a different mechanism that produces the same evidence.\n` +
|
|
294
|
+
`3. Choose the SMALLEST next step that produces evidence — one experiment, not a longer version of the same ` +
|
|
295
|
+
`attempt.\n` +
|
|
296
|
+
`If this is a FALSE POSITIVE (you were quoting the phrase), say so and carry on. finish(goalComplete=false) ` +
|
|
297
|
+
`only with a blocker that is NOT the context size.`);
|
|
277
298
|
}
|
|
278
299
|
timeAnchor() {
|
|
279
300
|
const clock = turnAnchor({
|
|
@@ -1456,14 +1477,24 @@ export class Agent {
|
|
|
1456
1477
|
* carry on. Bounded, and reset by any round that does actual work, so the answer cannot become its own
|
|
1457
1478
|
* spin.
|
|
1458
1479
|
*/
|
|
1480
|
+
/**
|
|
1481
|
+
* Either claim — "the window is full" (false, and corrected with numbers) or "I cannot see the next
|
|
1482
|
+
* step" (real, and answered with a new perspective) — takes the same route. They are too similar in the
|
|
1483
|
+
* text to separate safely, and the one answer covers both.
|
|
1484
|
+
*/
|
|
1485
|
+
const windowClaim = claimsContextLimit(this.lastAssistantText) ||
|
|
1486
|
+
claimsContextLimit(this.lastReasoning) ||
|
|
1487
|
+
claimsOwnLimit(this.lastAssistantText) ||
|
|
1488
|
+
claimsOwnLimit(this.lastReasoning);
|
|
1459
1489
|
if (this.contextClaimNudges < 2 &&
|
|
1460
1490
|
!this.awaitingUser &&
|
|
1461
|
-
|
|
1491
|
+
windowClaim) {
|
|
1462
1492
|
this.contextClaimNudges += 1;
|
|
1463
1493
|
await this.log.append("system_note", this.currentSession, this.currentBranch, {
|
|
1464
1494
|
event: "context-claim-answered",
|
|
1465
1495
|
attempt: this.contextClaimNudges,
|
|
1466
|
-
|
|
1496
|
+
via: "stop",
|
|
1497
|
+
detail: "the agent stopped blaming its remaining capacity — the harness compacted and answered with the measured window plus a fresh-perspective instruction (#201)",
|
|
1467
1498
|
});
|
|
1468
1499
|
await this.maybeCompact(true);
|
|
1469
1500
|
const msg = this.contextClaimAnswer("stop");
|
|
@@ -1599,7 +1630,10 @@ export class Agent {
|
|
|
1599
1630
|
if (fin.goalComplete !== true &&
|
|
1600
1631
|
!this.awaitingUser &&
|
|
1601
1632
|
this.contextClaimNudges < 2 &&
|
|
1602
|
-
claimsContextLimit(String(fin.summary ?? ""))
|
|
1633
|
+
(claimsContextLimit(String(fin.summary ?? "")) ||
|
|
1634
|
+
claimsContextLimit(this.lastReasoning) ||
|
|
1635
|
+
claimsOwnLimit(String(fin.summary ?? "")) ||
|
|
1636
|
+
claimsOwnLimit(this.lastReasoning))) {
|
|
1603
1637
|
this.contextClaimNudges += 1;
|
|
1604
1638
|
await this.log.append("system_note", this.currentSession, this.currentBranch, {
|
|
1605
1639
|
event: "context-claim-answered",
|
|
@@ -2063,6 +2097,7 @@ export class Agent {
|
|
|
2063
2097
|
reasoning: res.reasoning,
|
|
2064
2098
|
});
|
|
2065
2099
|
this.lastAssistantText = m.content ?? "";
|
|
2100
|
+
this.lastReasoning = res.reasoning ?? "";
|
|
2066
2101
|
/**
|
|
2067
2102
|
* Reset the "stop was questioned" counters only on REAL work.
|
|
2068
2103
|
*
|
|
@@ -26,6 +26,11 @@ const STOP_PATTERNS = [
|
|
|
26
26
|
/上下文[^。\n]{0,10}(?:快|即将|要)?(?:用满|耗尽|不足)/,
|
|
27
27
|
/(?:token|上下文)[^。\n]{0,12}(?:预算|额度)[^。\n]{0,12}(?:不足|耗尽)/,
|
|
28
28
|
/(?:context|token)s?[\s-]*(?:window|limit)[^.\n]{0,40}(?:stop|halt|end|paus|abort)/i,
|
|
29
|
+
// the reasoning-side phrasing measured in akku1139/teapot#201's follow-up report
|
|
30
|
+
/context (?:is |was )?(?:nearly |almost )?(?:exhausted|full|gone|out)/i,
|
|
31
|
+
/out of context (?:to|for)/i,
|
|
32
|
+
/can'?t reliably continue/i,
|
|
33
|
+
/context[- ]blocked/i,
|
|
29
34
|
// deepseek-ai/DeepSeek-V3#1737 / #1744: the web product's own wording, reproduced by the model
|
|
30
35
|
/le?ngth\s*limit[^.\n]{0,20}(?:reached|exceeded|hit)/i,
|
|
31
36
|
/(?:your )?chat limit (?:has )?(?:finished|been reached|reached)/i,
|
|
@@ -74,3 +79,30 @@ export function usageLine(used, budget) {
|
|
|
74
79
|
const pct = Math.max(0, Math.min(100, Math.round((used / budget) * 100)));
|
|
75
80
|
return `context ${pct}% (${fmt(used)}/${fmt(budget)} tokens)`;
|
|
76
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* …and the OTHER thing that gets reported as "context is exhausted": the model has run out of its own ideas.
|
|
84
|
+
*
|
|
85
|
+
* "コンテキストが尽きたっていうのがコンテキストウィンドウが尽きたと勘違いしてるパターンと、自力の推論の限界に達した
|
|
86
|
+
* 場合がありそう" — two different problems with different answers. The window case is false and gets corrected with
|
|
87
|
+
* numbers; being STUCK is real, and telling the model to continue would just spin. What a stuck agent needs is to
|
|
88
|
+
* name the question it cannot answer and hand it over (ask_user) or change angle — not another turn of the same.
|
|
89
|
+
*/
|
|
90
|
+
const OWN_LIMIT_PATTERNS = [
|
|
91
|
+
/(?:reasoning|analysis|own) (?:limit|limits|capacity)s?\b/i,
|
|
92
|
+
/reached (?:the )?limits? of my (?:reasoning|analysis|understanding)/i,
|
|
93
|
+
/can'?t (?:reason|figure|work) (?:this |it )?out (?:any (?:further|longer))?/i,
|
|
94
|
+
/no (?:further|more) (?:ideas|approaches|options|progress)/i,
|
|
95
|
+
/(?:推論|思考|自力)[^。\n]{0,12}(?:限界|行き詰|手詰)/,
|
|
96
|
+
/(?:打つ手|手立て|これ以上)[^。\n]{0,10}(?:ない|尽きた|思いつかない)/,
|
|
97
|
+
/行き詰ま(?:った|り)/,
|
|
98
|
+
/(?:无法再|想不出|推理到极限)/,
|
|
99
|
+
];
|
|
100
|
+
export function claimsOwnLimit(text) {
|
|
101
|
+
const raw = String(text ?? "");
|
|
102
|
+
if (!raw.trim())
|
|
103
|
+
return false;
|
|
104
|
+
const t = withoutQuotedBlocks(raw);
|
|
105
|
+
if (!t.trim())
|
|
106
|
+
return false;
|
|
107
|
+
return OWN_LIMIT_PATTERNS.some((re) => re.test(t));
|
|
108
|
+
}
|