anchor-ai-sdk 0.9.0 → 0.10.1
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 +18 -0
- package/dist/engine/events.d.ts +12 -2
- package/dist/engine/events.d.ts.map +1 -1
- package/dist/engine/guardrails.d.ts +15 -0
- package/dist/engine/guardrails.d.ts.map +1 -1
- package/dist/engine/guardrails.js +31 -1
- package/dist/engine/guardrails.js.map +1 -1
- package/dist/engine/inbox.d.ts +36 -8
- package/dist/engine/inbox.d.ts.map +1 -1
- package/dist/engine/inbox.js +12 -1
- package/dist/engine/inbox.js.map +1 -1
- package/dist/engine/loop.d.ts.map +1 -1
- package/dist/engine/loop.js +141 -4
- package/dist/engine/loop.js.map +1 -1
- package/dist/engine/types.d.ts +6 -0
- package/dist/engine/types.d.ts.map +1 -1
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -0
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/openai-compatible.d.ts +7 -0
- package/dist/llm/openai-compatible.d.ts.map +1 -1
- package/dist/llm/openai-compatible.js +4 -0
- package/dist/llm/openai-compatible.js.map +1 -1
- package/dist/llm/types.d.ts +12 -0
- package/dist/llm/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -620,6 +620,23 @@ else console.log(result.reason); // e.g. "budget_exhausted"
|
|
|
620
620
|
`reason: "budget_exhausted"`.
|
|
621
621
|
- `ask_questions` is refused, and so is `EngineOptions.inbox`: a workflow run is one-shot.
|
|
622
622
|
|
|
623
|
+
### Messages while a run works: the inbox
|
|
624
|
+
|
|
625
|
+
Pass `inbox: { store, channel }` (a `MemoryInboxStore`, or your own `InboxStore`)
|
|
626
|
+
and `runAgent` becomes a chain: messages that arrive while a run is working are
|
|
627
|
+
delivered one of three ways, chosen per message by `delivery`:
|
|
628
|
+
|
|
629
|
+
| `delivery` | What happens | Use it to |
|
|
630
|
+
| --- | --- | --- |
|
|
631
|
+
| `steer` | Delivered into the **same run** at its next turn boundary, as an engine user message. The run is never ended. | **Nudge** a running worker: "speed up", "2 minutes left". |
|
|
632
|
+
| `interject` | Ends the running run at its next turn boundary; the chain continues with the message. | **Correct or stop** it. |
|
|
633
|
+
| `queue` | Leaves the running run alone; the message becomes the next run's task. | **Hand it more work.** |
|
|
634
|
+
|
|
635
|
+
`claimSteers(channel)` is an optional `InboxStore` method; a store without it
|
|
636
|
+
treats a `steer` message as `queue`. A steer that arrives after the run's last
|
|
637
|
+
turn boundary is not lost: it is part of the next run's `claimAll` batch. The
|
|
638
|
+
engine emits `inbox_steer` (`{ count }`) when it delivers steers.
|
|
639
|
+
|
|
623
640
|
## Configure the runtime, not another loop
|
|
624
641
|
|
|
625
642
|
| Capability | Your controls |
|
|
@@ -628,6 +645,7 @@ else console.log(result.reason); // e.g. "budget_exhausted"
|
|
|
628
645
|
| **Reasoning budget** | Per-run `reasoningEffort` (`minimal`–`max`) or an agent-bundle default, sent in the provider's native shape (`reasoning.effort` on OpenRouter, `reasoning_effort` on OpenAI). |
|
|
629
646
|
| **Prompt caching** | Opt-in `promptCache` breakpoints for Anthropic-style providers, with stable-prefix selection and `cachedTokens` accounting. See [docs/prompt-caching.md](docs/prompt-caching.md). |
|
|
630
647
|
| **Composition** | `createAnchor` for reusable model/agent/sandbox/thread wiring, exported coding prompt components, and `view_image` for text-only agents. See [docs/composition.md](docs/composition.md). |
|
|
648
|
+
| **Messages mid-run** | A consumer-owned inbox with `steer` (nudge), `interject` (correct), and `queue` (more work) deliveries, chained by the engine. |
|
|
631
649
|
| **Context and memory** | Catalog-derived or explicit compaction, supplied thread stores, agent-authored notes, and best-effort output spill. |
|
|
632
650
|
| **Revival and resume** | Opt-in budget warnings, `request_revival`, `planRevival`, and `ThreadBudget`. Your app persists state and decides whether to fund or enqueue another run. |
|
|
633
651
|
| **Snapshots and lifecycle** | Git-backed or custom snapshot hooks, optional push, phase-boundary pauses, heartbeats, and cancellation. |
|
package/dist/engine/events.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { LLMMessage, LLMToolCall, LLMUsage } from "../llm/types.js";
|
|
10
10
|
import type { CompactionHandoff } from "./compaction.js";
|
|
11
|
+
import type { InboxDelivery } from "./inbox.js";
|
|
11
12
|
import type { ProgressLedger } from "../ledger/types.js";
|
|
12
13
|
/** What a budget-limited run says it still needs — see EngineOptions.revival. */
|
|
13
14
|
export interface RevivalRequest {
|
|
@@ -145,7 +146,7 @@ type AgentEventBody = {
|
|
|
145
146
|
type: "inbox_delivered";
|
|
146
147
|
messages: Array<{
|
|
147
148
|
id: string;
|
|
148
|
-
delivery:
|
|
149
|
+
delivery: InboxDelivery;
|
|
149
150
|
}>;
|
|
150
151
|
} | {
|
|
151
152
|
/**
|
|
@@ -153,6 +154,13 @@ type AgentEventBody = {
|
|
|
153
154
|
* Which messages caused it is reported by the next `inbox_delivered`.
|
|
154
155
|
*/
|
|
155
156
|
type: "inbox_interject";
|
|
157
|
+
} | {
|
|
158
|
+
/**
|
|
159
|
+
* Pending `steer` messages were delivered into this run at a turn
|
|
160
|
+
* boundary, as engine user messages. The run was not ended.
|
|
161
|
+
*/
|
|
162
|
+
type: "inbox_steer";
|
|
163
|
+
count: number;
|
|
156
164
|
} | {
|
|
157
165
|
type: "guardrail";
|
|
158
166
|
kind: "loop_detected" | "budget_exceeded" | "finish_rejected" | "transition_rejected" | "check_overridden";
|
|
@@ -185,7 +193,7 @@ type AgentEventBody = {
|
|
|
185
193
|
/** Non-blocking runtime guidance (e.g. the materialization advisory).
|
|
186
194
|
* Advisory events never gate actions or end runs. */
|
|
187
195
|
type: "advisory";
|
|
188
|
-
kind: "materialization_nudge" | "budget_warning" | "child_wrap_up" | "snapshot_failed" | "output_truncated" | "output_cap_continue" | "verbose_turn" | "assistant_text_elided" | "tool_results_elided" | "prose_checkpoint" | "repeated_call" | "empty_turn" | "effect_without_journal" | "operation_settle_failed" | "verifier_failed";
|
|
196
|
+
kind: "materialization_nudge" | "budget_warning" | "child_wrap_up" | "snapshot_failed" | "output_truncated" | "output_cap_continue" | "verbose_turn" | "assistant_text_elided" | "tool_results_elided" | "prose_checkpoint" | "repeated_call" | "empty_turn" | "reasoning_limit" | "leaked_tool_call" | "effect_without_journal" | "operation_settle_failed" | "verifier_failed";
|
|
189
197
|
detail: string;
|
|
190
198
|
} | {
|
|
191
199
|
/** The dying run's handoff: what it still needs, for a consumer that may
|
|
@@ -219,6 +227,8 @@ type AgentEventBody = {
|
|
|
219
227
|
steps: number;
|
|
220
228
|
usage: LLMUsage;
|
|
221
229
|
reason: "finished" | "max_steps" | "budget_exceeded" | "budget_exhausted" | "stalled" | "error" | "paused" | "cancelled" | "interrupted" | "recovery_required";
|
|
230
|
+
/** The run can be retried on the same thread without recovery. */
|
|
231
|
+
retryable?: boolean;
|
|
222
232
|
/** Set when the run concluded via finish() with a consumer-shaped handoff. */
|
|
223
233
|
handoff?: Record<string, unknown>;
|
|
224
234
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/engine/events.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,KAAK,cAAc,GACf;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,yDAAyD;IACzD,IAAI,EAAE,MAAM,CA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"}
|
|
@@ -17,6 +17,12 @@ export interface CourseCorrection {
|
|
|
17
17
|
kind: AdvisoryKind;
|
|
18
18
|
detail: string;
|
|
19
19
|
content: string;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the model's next prose turn is a checkpoint rather than an answer.
|
|
22
|
+
* Default true; a forced-action continuation sets false so a concise answer
|
|
23
|
+
* after the nudge ends the run instead of costing another call.
|
|
24
|
+
*/
|
|
25
|
+
proseCheckpoint?: boolean;
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
28
|
* The shared mechanic. Callers own the policy; this only records the advisory,
|
|
@@ -57,5 +63,14 @@ export declare function repeatedCallNudge(limit: number, hasFinish: boolean): st
|
|
|
57
63
|
* user turn, so it cannot be mistaken for work.
|
|
58
64
|
*/
|
|
59
65
|
export declare function wrapUpNudge(stepsLeft: number, reason: string): string;
|
|
66
|
+
/** Whether a reply with no structured tool call carries a tool call written as text. */
|
|
67
|
+
export declare function leakedToolCall(text: string): boolean;
|
|
68
|
+
export declare function leakedToolCallNudge(hasFinish: boolean): string;
|
|
60
69
|
export declare function emptyTurnNudge(hasFinish: boolean): string;
|
|
70
|
+
/**
|
|
71
|
+
* A reasoning model that spent its whole output budget thinking and produced
|
|
72
|
+
* no action. The ceiling is a turn condition, not the end of the run: the
|
|
73
|
+
* model is told to stop thinking and act, and the engine forces a tool call.
|
|
74
|
+
*/
|
|
75
|
+
export declare function reasoningLimitNudge(hasFinish: boolean): string;
|
|
61
76
|
//# sourceMappingURL=guardrails.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guardrails.d.ts","sourceRoot":"","sources":["../../src/engine/guardrails.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,MAAM,YAAY,GAAG,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CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAQjC;IAED,sCAAsC;IACtC,KAAK,IAAI,IAAI,CAEZ;CACF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAE3D;AAUD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAM1E;AAED,wBAAgB,eAAe,IAAI,MAAM,CAOxC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAQ3E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOrE;AAYD,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAO9D;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAMzD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAM9D"}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export function createCourseCorrect(args) {
|
|
8
8
|
return async (correction) => {
|
|
9
|
-
|
|
9
|
+
if (correction.proseCheckpoint !== false)
|
|
10
|
+
args.markProseCheck();
|
|
10
11
|
args.emit({
|
|
11
12
|
type: "advisory",
|
|
12
13
|
kind: correction.kind,
|
|
@@ -95,9 +96,38 @@ export function wrapUpNudge(stepsLeft, reason) {
|
|
|
95
96
|
`Stop exploring. Answer what you can now, list what is unfinished, and hand back — ` +
|
|
96
97
|
`a partial result stated clearly is worth more than a complete one you never deliver.`);
|
|
97
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* The model's own tool-call syntax, written into the reply as text: the provider did not translate it into a
|
|
101
|
+
* structured call. The markers are each model family's call delimiters, not words a reply would use.
|
|
102
|
+
*/
|
|
103
|
+
const LEAKED_TOOL_CALL_MARKERS = [
|
|
104
|
+
/<|DSML|\s*(calls|invoke)\b/, // DeepSeek's DSML call blocks
|
|
105
|
+
/<|tool▁calls?▁begin|>/, // DeepSeek's earlier call tokens
|
|
106
|
+
/<tool_call>\s*\{/, // Hermes/Qwen-style JSON calls
|
|
107
|
+
];
|
|
108
|
+
/** Whether a reply with no structured tool call carries a tool call written as text. */
|
|
109
|
+
export function leakedToolCall(text) {
|
|
110
|
+
return LEAKED_TOOL_CALL_MARKERS.some((marker) => marker.test(text));
|
|
111
|
+
}
|
|
112
|
+
export function leakedToolCallNudge(hasFinish) {
|
|
113
|
+
return ("Your last turn wrote a tool call as text (call markup in the reply) instead of calling the tool, so nothing ran " +
|
|
114
|
+
"and it was not accepted as an answer. Make the call again through the tool interface, with its arguments as " +
|
|
115
|
+
"separate, valid JSON fields" +
|
|
116
|
+
callFinishHint(hasFinish));
|
|
117
|
+
}
|
|
98
118
|
export function emptyTurnNudge(hasFinish) {
|
|
99
119
|
return ("Your last turn had no visible text and no tool call, so it was not accepted. " +
|
|
100
120
|
"A reasoning-only turn does not count. Your next turn must include a tool call" +
|
|
101
121
|
callFinishHint(hasFinish));
|
|
102
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* A reasoning model that spent its whole output budget thinking and produced
|
|
125
|
+
* no action. The ceiling is a turn condition, not the end of the run: the
|
|
126
|
+
* model is told to stop thinking and act, and the engine forces a tool call.
|
|
127
|
+
*/
|
|
128
|
+
export function reasoningLimitNudge(hasFinish) {
|
|
129
|
+
return ("You have reached the reasoning limit. Stop reasoning and take the next action now: " +
|
|
130
|
+
"call a tool (e.g. write the task) or return a concise answer." +
|
|
131
|
+
(hasFinish ? " If the work is already complete, call `finish`." : ""));
|
|
132
|
+
}
|
|
103
133
|
//# sourceMappingURL=guardrails.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guardrails.js","sourceRoot":"","sources":["../../src/engine/guardrails.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"guardrails.js","sourceRoot":"","sources":["../../src/engine/guardrails.ts"],"names":[],"mappings":"AA2BA;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAKnC;IACC,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE;QAC1B,IAAI,UAAU,CAAC,eAAe,KAAK,KAAK;YAAE,IAAI,CAAC,cAAc,EAAE,CAAC;QAChE,IAAI,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,MAAM,EAAE,UAAU,CAAC,MAAM;SAC1B,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,UAAU,CAAC,OAAO;SAC5B,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,MAAM,OAAO,aAAa;IAGK,KAAK;IAFjB,IAAI,GAAa,EAAE,CAAC;IAErC,YAA6B,KAAqB;qBAArB,KAAK;IAAmB,CAAC;IAEtD,oEAAoE;IACpE,MAAM,CAAC,SAAiB;QACtB,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1B,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAA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+E;QAC/E,cAAc,CAAC,SAAS,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAkB;IACpD,OAAO,CACL,qFAAqF;QACrF,+DAA+D;QAC/D,CAAC,SAAS,CAAC,CAAC,CAAC,kDAAkD,CAAC,CAAC,CAAC,EAAE,CAAC,CACtE,CAAC;AACJ,CAAC"}
|
package/dist/engine/inbox.d.ts
CHANGED
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A run owns one task at a time, and the chat protocol forbids splicing a new
|
|
5
5
|
* user turn into the middle of an assistant/tool exchange. So an arriving
|
|
6
|
-
* message has
|
|
6
|
+
* message has three honest destinations:
|
|
7
7
|
*
|
|
8
8
|
* - `queue` — leave the running run alone. The message becomes (part of)
|
|
9
9
|
* the next run's task.
|
|
10
10
|
* - `interject` — end the running run at its next turn boundary, then start
|
|
11
11
|
* the next run with this message.
|
|
12
|
+
* - `steer` — deliver into the SAME run at its next turn boundary, as an
|
|
13
|
+
* engine user message. It never ends the run: use it to
|
|
14
|
+
* nudge a worker (a time notice, "speed up"), not to correct
|
|
15
|
+
* or stop it.
|
|
16
|
+
*
|
|
17
|
+
* When to use which: nudge a running worker — `steer`; correct or stop it —
|
|
18
|
+
* `interject`; hand it more work — `queue`.
|
|
12
19
|
*
|
|
13
20
|
* The store is the consumer's: a database in production, `MemoryInboxStore`
|
|
14
21
|
* for tests and single-process apps. The package owns *when* to look and what
|
|
@@ -18,11 +25,14 @@
|
|
|
18
25
|
* Ordering is part of the contract, not a hint: a claim returns pending
|
|
19
26
|
* interjections first (newest first — the latest correction supersedes the
|
|
20
27
|
* older ones), then queued messages oldest-first. A store that cannot express
|
|
21
|
-
* that ordering cannot implement this interface.
|
|
28
|
+
* that ordering cannot implement this interface. Pending `steer` messages join
|
|
29
|
+
* the queued ones in that second group, oldest-first: a steer the run never
|
|
30
|
+
* reached (it arrived after the last turn boundary, or an interjection ended
|
|
31
|
+
* the run first) is NOT lost — it rides the next run's batch.
|
|
22
32
|
*/
|
|
23
33
|
import type { ImageAttachment, LLMMessage, LLMUsage } from "../llm/types.js";
|
|
24
34
|
import type { FinishReason } from "./types.js";
|
|
25
|
-
export type InboxDelivery = "queue" | "interject";
|
|
35
|
+
export type InboxDelivery = "queue" | "interject" | "steer";
|
|
26
36
|
/** One message waiting for (or claimed by) a run. */
|
|
27
37
|
export interface InboxMessage {
|
|
28
38
|
/**
|
|
@@ -66,15 +76,32 @@ export interface InboxStore {
|
|
|
66
76
|
/**
|
|
67
77
|
* Is there a pending interjection for this channel? Called at every turn
|
|
68
78
|
* boundary of a run, so it must be cheap (an indexed existence check, not a
|
|
69
|
-
* full scan of the inbox).
|
|
79
|
+
* full scan of the inbox). Only `interject` rows count: `steer` and `queue`
|
|
80
|
+
* rows must be IGNORED, or a nudge would end the run it was meant to speed up.
|
|
70
81
|
*/
|
|
71
82
|
hasInterject(channel: string): Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* Atomically claim the pending `steer` messages of the channel, oldest
|
|
85
|
+
* first, and nothing else (never an `interject` or `queue` row). Same
|
|
86
|
+
* contract as `claimAll`: a claimed row is invisible to other claims until
|
|
87
|
+
* `release`d, and `complete` retires it for good.
|
|
88
|
+
*
|
|
89
|
+
* Optional. The engine calls it at every turn boundary of a running chain
|
|
90
|
+
* (after the interjection probe, which wins), so it must be cheap: one
|
|
91
|
+
* indexed query. When a store does not implement it, a `steer` message is
|
|
92
|
+
* simply treated as `queue` — it waits for the run to end and rides the next
|
|
93
|
+
* run's `claimAll` batch.
|
|
94
|
+
*/
|
|
95
|
+
claimSteers?(channel: string): Promise<InboxMessage[]>;
|
|
72
96
|
/**
|
|
73
97
|
* Atomically claim every pending message for the channel: interjections
|
|
74
|
-
* first (newest first), then queued
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
98
|
+
* first (newest first), then queued and steer messages together
|
|
99
|
+
* (oldest first). A `steer` still pending at this point (it arrived after
|
|
100
|
+
* the last turn boundary, or an interjection ended the run first) is part of
|
|
101
|
+
* the batch — it is never lost. A claimed message must not be returned by
|
|
102
|
+
* another claim until it is released — in a database that means
|
|
103
|
+
* `FOR UPDATE SKIP LOCKED` (plus a lease timeout, so a crashed worker's
|
|
104
|
+
* claim is recoverable).
|
|
78
105
|
*/
|
|
79
106
|
claimAll(channel: string): Promise<InboxMessage[]>;
|
|
80
107
|
/** The claimed batch was delivered into a run. Never return it again. */
|
|
@@ -89,6 +116,7 @@ export declare class MemoryInboxStore implements InboxStore {
|
|
|
89
116
|
push(message: InboxMessage): Promise<"queued" | "duplicate">;
|
|
90
117
|
hasPending(channel: string): Promise<boolean>;
|
|
91
118
|
hasInterject(channel: string): Promise<boolean>;
|
|
119
|
+
claimSteers(channel: string): Promise<InboxMessage[]>;
|
|
92
120
|
claimAll(channel: string): Promise<InboxMessage[]>;
|
|
93
121
|
complete(ids: string[]): Promise<void>;
|
|
94
122
|
release(ids: string[]): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox.d.ts","sourceRoot":"","sources":["../../src/engine/inbox.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"inbox.d.ts","sourceRoot":"","sources":["../../src/engine/inbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,WAAW,GAAG,OAAO,CAAC;AAE5D,qDAAqD;AACrD,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IACX,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,IAAI,EAAE,M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AEE,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,WAAW,CAAC,CAkBjE;IAEK,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAElD;IAEK,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CASpD;IAEK,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAa1D;IAEK,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAgBvD;IAEK,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3C;IAEK,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1C;IAED,oEAAoE;IACpE,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKpC;IAED,6EAA6E;IAC7E,OAAO,CAAC,SAAS;CAMlB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG;IACzD,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAaA"}
|
package/dist/engine/inbox.js
CHANGED
|
@@ -34,6 +34,17 @@ export class MemoryInboxStore {
|
|
|
34
34
|
return true;
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
|
+
async claimSteers(channel) {
|
|
38
|
+
return [...this.rows.values()]
|
|
39
|
+
.filter((row) => row.status === "pending" &&
|
|
40
|
+
row.message.channel === channel &&
|
|
41
|
+
row.message.delivery === "steer")
|
|
42
|
+
.sort((a, b) => a.seq - b.seq)
|
|
43
|
+
.map((row) => {
|
|
44
|
+
row.status = "claimed";
|
|
45
|
+
return { ...row.message };
|
|
46
|
+
});
|
|
47
|
+
}
|
|
37
48
|
async claimAll(channel) {
|
|
38
49
|
const pending = [...this.rows.values()].filter((row) => row.status === "pending" && row.message.channel === channel);
|
|
39
50
|
if (pending.length === 0)
|
|
@@ -42,7 +53,7 @@ export class MemoryInboxStore {
|
|
|
42
53
|
.filter((row) => row.message.delivery === "interject")
|
|
43
54
|
.sort((a, b) => b.seq - a.seq);
|
|
44
55
|
const queued = pending
|
|
45
|
-
.filter((row) => row.message.delivery
|
|
56
|
+
.filter((row) => row.message.delivery !== "interject")
|
|
46
57
|
.sort((a, b) => a.seq - b.seq);
|
|
47
58
|
const batch = [...interjects, ...queued].map((row) => {
|
|
48
59
|
row.status = "claimed";
|
package/dist/engine/inbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox.js","sourceRoot":"","sources":["../../src/engine/inbox.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inbox.js","sourceRoot":"","sources":["../../src/engine/inbox.ts"],"names":[],"mappings":"AAoHA,mEAAmE;AACnE,MAAM,OAAO,gBAAgB;IACnB,GAAG,GAAG,CAAC,CAAC;IACC,IAAI,GAAG,IAAI,GAAG,EAG5B,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,OAAqB;QAC9B,IAAI,CAAC,OAAO,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,CAAC,OAAO;YAClB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,SAAS,OAAO,CAAC,EAAE,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpC,sEAAsE;QACtE,sEAAsE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,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC9D,CAAC,CAAC;QACH,GAAG,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;KACvC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/engine/loop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/engine/loop.ts"],"names":[],"mappings":"AA4HA,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,WAAW,EAIZ,MAAM,YAAY,CAAC;AAUpB,YAAY,EACV,QAAQ,EACR,aAAa,EACb,WAAW,EACX,YAAY,EACZ,eAAe,EACf,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAmyFtC,gFAAgF;AAChF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CASpE;AAgID,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,WAAW,CAAC,CAStB"}
|
package/dist/engine/loop.js
CHANGED
|
@@ -11,7 +11,7 @@ import { renderInboxTurn, } from "./inbox.js";
|
|
|
11
11
|
import { defineTool } from "../tools/types.js";
|
|
12
12
|
import { gitSnapshot } from "./snapshot.js";
|
|
13
13
|
import { createTeamTools } from "../teams/delegate.js";
|
|
14
|
-
import { steerDirective } from "../teams/steer.js";
|
|
14
|
+
import { normalizeDirective, steerDirective, } from "../teams/steer.js";
|
|
15
15
|
import { TraceFanout } from "../trace/sink.js";
|
|
16
16
|
import { budgetWarning, revivalBlock, warnPercent as revivalWarnPercent, } from "./revival.js";
|
|
17
17
|
import { phaseDisciplineBlock } from "./phase-discipline.js";
|
|
@@ -20,7 +20,7 @@ import { addRequirement, compileLedger, createLedger, ledgerGate, linkEvidence,
|
|
|
20
20
|
import { llmJudge } from "../verify/index.js";
|
|
21
21
|
import { dispatchToolCalls, } from "./dispatch.js";
|
|
22
22
|
import { mintOperationId, reconcilePendingOperations, settleFromResult, } from "./operations.js";
|
|
23
|
-
import { RepeatTracker, cappedReplyNudge, createCourseCorrect, emptyTurnNudge, proseCheckpoint as proseCheckpointMessage, repeatedCallNudge, silentNudge, verboseNudge, visibleOutputTokens, wrapUpNudge, } from "./guardrails.js";
|
|
23
|
+
import { RepeatTracker, cappedReplyNudge, createCourseCorrect, emptyTurnNudge, leakedToolCall, leakedToolCallNudge, proseCheckpoint as proseCheckpointMessage, reasoningLimitNudge, repeatedCallNudge, silentNudge, verboseNudge, visibleOutputTokens, wrapUpNudge, } from "./guardrails.js";
|
|
24
24
|
import { CANCEL_GRACE, DEFAULT_CANCEL_GRACE_MS, DEFAULT_STALL_AFTER_MS, waitWithCancelGrace, } from "./supervision.js";
|
|
25
25
|
import { pollBackgroundJobs, renderBackgroundResult, renderLostJob, waitForBackgroundJobs, } from "./background.js";
|
|
26
26
|
export { userTurn } from "./types.js";
|
|
@@ -41,6 +41,18 @@ const LEDGER_TOOL_NAMES = new Set([
|
|
|
41
41
|
"add_failure",
|
|
42
42
|
"clear_failure",
|
|
43
43
|
]);
|
|
44
|
+
/** Corrections a run gets for a tool call written as text before it stalls. */
|
|
45
|
+
const LEAKED_CALL_RETRIES = 2;
|
|
46
|
+
/**
|
|
47
|
+
* A reasoning model can spend the whole output cap thinking and emit no text
|
|
48
|
+
* or tool call. That is a turn condition, not a dead run: continue with a
|
|
49
|
+
* forced action this many times before handing the thread back retryable.
|
|
50
|
+
*/
|
|
51
|
+
const REASONING_LIMIT_CONTINUATIONS = 3;
|
|
52
|
+
/** The reduced per-call output budget on a forced-action continuation. */
|
|
53
|
+
const REASONING_LIMIT_MAX_OUTPUT_TOKENS = 8_000;
|
|
54
|
+
/** The reduced reasoning effort on a forced-action continuation. */
|
|
55
|
+
const REASONING_LIMIT_EFFORT = "low";
|
|
44
56
|
/** The child's most recent visible prose, for a budget-exhausted hand-back. */
|
|
45
57
|
function lastAssistantText(messages) {
|
|
46
58
|
for (let index = messages.length - 1; index >= 0; index--) {
|
|
@@ -1075,6 +1087,13 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1075
1087
|
// An empty turn (no text, no tool call) gets one correction. The flag is
|
|
1076
1088
|
// how the next empty turn is recognized as "after the advisory."
|
|
1077
1089
|
let emptyNudged = false;
|
|
1090
|
+
// A reasoning-only turn at the output cap is a turn condition. Each forced
|
|
1091
|
+
// continuation asks for a tool call and lowers the budget; after the limit
|
|
1092
|
+
// the run pauses with `retryable`, so the thread is kept and can be resumed.
|
|
1093
|
+
let reasoningLimitContinues = 0;
|
|
1094
|
+
let forceAction = false;
|
|
1095
|
+
// A tool call written as text gets this many corrections before the run stalls: it is never an answer.
|
|
1096
|
+
let leakedCallNudges = 0;
|
|
1078
1097
|
// A delegated child is told to wrap up once, at its soft cap. The hard cap
|
|
1079
1098
|
// still ends the loop; the flag keeps the directive one-shot.
|
|
1080
1099
|
let softCapNudged = false;
|
|
@@ -1506,7 +1525,19 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1506
1525
|
return false;
|
|
1507
1526
|
}
|
|
1508
1527
|
};
|
|
1528
|
+
// Steers claimed at a boundary and appended to the transcript, not yet seen
|
|
1529
|
+
// by a model call. Settled at the call, or released by whichever exit comes
|
|
1530
|
+
// first (`conclude`), so a run that dies in between loses nothing.
|
|
1531
|
+
let claimedSteers = [];
|
|
1532
|
+
const settleSteers = async (settle) => {
|
|
1533
|
+
if (claimedSteers.length === 0 || !chain.steers)
|
|
1534
|
+
return;
|
|
1535
|
+
const ids = claimedSteers;
|
|
1536
|
+
claimedSteers = [];
|
|
1537
|
+
await chain.steers[settle](ids).catch(() => undefined);
|
|
1538
|
+
};
|
|
1509
1539
|
const conclude = async (reason, extra) => {
|
|
1540
|
+
await settleSteers("release");
|
|
1510
1541
|
// Snapshots are a persistence concern, not a phase the model must enter.
|
|
1511
1542
|
// Avoid empty commits, especially for reviews and simple conversation.
|
|
1512
1543
|
if (opts.sandbox && opts.snapshot !== false) {
|
|
@@ -1558,6 +1589,7 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1558
1589
|
steps,
|
|
1559
1590
|
usage,
|
|
1560
1591
|
reason,
|
|
1592
|
+
...(extra.retryable ? { retryable: true } : {}),
|
|
1561
1593
|
...(extra.handoff !== undefined ? { handoff: extra.handoff } : {}),
|
|
1562
1594
|
});
|
|
1563
1595
|
const persisted = await persist(reason !== "paused", extra.handoff !== undefined
|
|
@@ -1787,6 +1819,22 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1787
1819
|
});
|
|
1788
1820
|
}
|
|
1789
1821
|
}
|
|
1822
|
+
// The inbox's steers land at the same boundary, after the interjection
|
|
1823
|
+
// probe (an interjection wins; the steers stay pending and ride the next
|
|
1824
|
+
// run's batch). Never a tool result, and never a stop.
|
|
1825
|
+
if (chain.steers) {
|
|
1826
|
+
const steers = await chain.steers.claim().catch(() => []);
|
|
1827
|
+
if (steers.length > 0) {
|
|
1828
|
+
for (const steer of steers) {
|
|
1829
|
+
const content = normalizeDirective(steer.text);
|
|
1830
|
+
if (content === "")
|
|
1831
|
+
continue;
|
|
1832
|
+
messages.push({ role: "user", origin: "engine", content });
|
|
1833
|
+
}
|
|
1834
|
+
claimedSteers.push(...steers.map((steer) => steer.id));
|
|
1835
|
+
emit({ type: "inbox_steer", count: steers.length });
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1790
1838
|
// Soft cap: a child is told to wrap up at 80% of its own budget, once.
|
|
1791
1839
|
// It is a nudge, not a stop — the child can still hand back an answer.
|
|
1792
1840
|
if (chain.child &&
|
|
@@ -1959,8 +2007,21 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1959
2007
|
// fold. A job that finished since the previous turn (including one
|
|
1960
2008
|
// carried in from a previous run) rides this call, not the one after.
|
|
1961
2009
|
await pollJobs();
|
|
2010
|
+
await settleSteers("complete");
|
|
1962
2011
|
steps++;
|
|
1963
2012
|
emit({ type: "llm_call_started", ...phaseTag(), step: steps });
|
|
2013
|
+
// A forced-action continuation is one call only: consume the flag here,
|
|
2014
|
+
// so a real action or answer returns the run to normal sampling.
|
|
2015
|
+
const forcingAction = forceAction;
|
|
2016
|
+
forceAction = false;
|
|
2017
|
+
const callMaxOutputTokens = forcingAction
|
|
2018
|
+
? Math.min(maxOutputTokens ?? REASONING_LIMIT_MAX_OUTPUT_TOKENS, REASONING_LIMIT_MAX_OUTPUT_TOKENS)
|
|
2019
|
+
: maxOutputTokens;
|
|
2020
|
+
const callReasoningEffort = forcingAction
|
|
2021
|
+
? reasoningEffort === "minimal"
|
|
2022
|
+
? "minimal"
|
|
2023
|
+
: REASONING_LIMIT_EFFORT
|
|
2024
|
+
: reasoningEffort;
|
|
1964
2025
|
const modelMessages = forModel();
|
|
1965
2026
|
const response = await waitWithCancelGrace(opts.llm.stream({
|
|
1966
2027
|
messages: modelMessages,
|
|
@@ -1969,14 +2030,23 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1969
2030
|
type: "function",
|
|
1970
2031
|
function: tool.definition,
|
|
1971
2032
|
})),
|
|
1972
|
-
...(
|
|
2033
|
+
...(callMaxOutputTokens !== undefined
|
|
2034
|
+
? { maxTokens: callMaxOutputTokens }
|
|
2035
|
+
: {}),
|
|
1973
2036
|
...(opts.sampling?.temperature !== undefined
|
|
1974
2037
|
? { temperature: opts.sampling.temperature }
|
|
1975
2038
|
: {}),
|
|
1976
2039
|
...(opts.sampling?.seed !== undefined
|
|
1977
2040
|
? { seed: opts.sampling.seed }
|
|
1978
2041
|
: {}),
|
|
1979
|
-
...(
|
|
2042
|
+
...(callReasoningEffort !== undefined
|
|
2043
|
+
? { reasoningEffort: callReasoningEffort }
|
|
2044
|
+
: {}),
|
|
2045
|
+
...(forcingAction &&
|
|
2046
|
+
opts.llm.supportsToolChoice === true &&
|
|
2047
|
+
available.size > 0
|
|
2048
|
+
? { toolChoice: "required" }
|
|
2049
|
+
: {}),
|
|
1980
2050
|
}, (text) => emit({ type: "llm_text_delta", text }), {
|
|
1981
2051
|
signal,
|
|
1982
2052
|
onReasoning: (text) => emit({ type: "llm_reasoning_delta", text }),
|
|
@@ -2048,6 +2118,45 @@ async function runOne(input, opts, chain = {}) {
|
|
|
2048
2118
|
}
|
|
2049
2119
|
if (!response.toolCalls.length) {
|
|
2050
2120
|
if (!response.text.trim()) {
|
|
2121
|
+
// Reasoning can consume the whole output cap and leave no visible
|
|
2122
|
+
// turn. That is a turn condition, not a dead run: ask for an action,
|
|
2123
|
+
// force a tool call, and lower the budget on the continuation. The
|
|
2124
|
+
// same shape applies to an empty turn that follows a forced action,
|
|
2125
|
+
// even if the provider no longer reports "length".
|
|
2126
|
+
const reasoningTokens = response.usage.reasoningTokens ?? 0;
|
|
2127
|
+
const hitOutputCap = outputCapped ||
|
|
2128
|
+
(maxOutputTokens !== undefined &&
|
|
2129
|
+
(response.usage.completionTokens >= maxOutputTokens ||
|
|
2130
|
+
reasoningTokens >= maxOutputTokens));
|
|
2131
|
+
if (forcingAction || hitOutputCap) {
|
|
2132
|
+
if (reasoningLimitContinues < REASONING_LIMIT_CONTINUATIONS) {
|
|
2133
|
+
reasoningLimitContinues += 1;
|
|
2134
|
+
forceAction = true;
|
|
2135
|
+
const spent = reasoningTokens > 0
|
|
2136
|
+
? `${reasoningTokens} reasoning tokens`
|
|
2137
|
+
: "the whole output budget";
|
|
2138
|
+
const why = forcingAction
|
|
2139
|
+
? "returned neither text nor a tool call after a forced action"
|
|
2140
|
+
: `spent ${spent} and returned neither text nor a tool call`;
|
|
2141
|
+
await courseCorrect({
|
|
2142
|
+
kind: "reasoning_limit",
|
|
2143
|
+
detail: `step ${steps} ${why} — forced action ` +
|
|
2144
|
+
`${reasoningLimitContinues}/${REASONING_LIMIT_CONTINUATIONS}`,
|
|
2145
|
+
content: reasoningLimitNudge(available.has("finish")),
|
|
2146
|
+
// A concise answer after the forced action is the run's result,
|
|
2147
|
+
// not a checkpoint that costs another call.
|
|
2148
|
+
proseCheckpoint: false,
|
|
2149
|
+
});
|
|
2150
|
+
continue;
|
|
2151
|
+
}
|
|
2152
|
+
return conclude("paused", {
|
|
2153
|
+
ok: false,
|
|
2154
|
+
retryable: true,
|
|
2155
|
+
error: `reasoning limit reached: the model returned neither text nor tool calls ` +
|
|
2156
|
+
`after ${REASONING_LIMIT_CONTINUATIONS} forced-action continuations. ` +
|
|
2157
|
+
`The thread is intact; retry this run on the same thread.`,
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2051
2160
|
// Flag, not a message scan: the advisory is already in the
|
|
2052
2161
|
// conversation, but the stop decision is this boolean.
|
|
2053
2162
|
if (!emptyNudged) {
|
|
@@ -2064,6 +2173,24 @@ async function runOne(input, opts, chain = {}) {
|
|
|
2064
2173
|
error: "model returned neither text nor tool calls",
|
|
2065
2174
|
});
|
|
2066
2175
|
}
|
|
2176
|
+
reasoningLimitContinues = 0;
|
|
2177
|
+
// The model wrote its call as text and the provider passed it through: nothing ran. Ending the run on it
|
|
2178
|
+
// would hand the call markup to the reader as the result, so ask for the real call, a bounded number of times.
|
|
2179
|
+
if (leakedToolCall(response.text)) {
|
|
2180
|
+
if (leakedCallNudges < LEAKED_CALL_RETRIES) {
|
|
2181
|
+
leakedCallNudges++;
|
|
2182
|
+
await courseCorrect({
|
|
2183
|
+
kind: "leaked_tool_call",
|
|
2184
|
+
detail: `step ${steps} wrote a tool call as text with no structured call — asked to make the call`,
|
|
2185
|
+
content: leakedToolCallNudge(available.has("finish")),
|
|
2186
|
+
});
|
|
2187
|
+
continue;
|
|
2188
|
+
}
|
|
2189
|
+
return conclude("stalled", {
|
|
2190
|
+
ok: false,
|
|
2191
|
+
error: "model kept writing tool calls as text instead of calling the tool",
|
|
2192
|
+
});
|
|
2193
|
+
}
|
|
2067
2194
|
// An unfinished sentence is not an answer. A reply cut off by the cap
|
|
2068
2195
|
// must never be accepted as the run's result. It also must not end a
|
|
2069
2196
|
// run that was still working (#79): same shape as a nudge — inject
|
|
@@ -2152,6 +2279,7 @@ async function runOne(input, opts, chain = {}) {
|
|
|
2152
2279
|
});
|
|
2153
2280
|
}
|
|
2154
2281
|
pendingProseCheck = false;
|
|
2282
|
+
reasoningLimitContinues = 0;
|
|
2155
2283
|
let declared;
|
|
2156
2284
|
let runaway = false;
|
|
2157
2285
|
const dispatched = await waitWithCancelGrace(dispatchToolCalls({
|
|
@@ -2416,6 +2544,15 @@ async function runChain(input, opts) {
|
|
|
2416
2544
|
jobs,
|
|
2417
2545
|
delivered,
|
|
2418
2546
|
interrupt: () => store.hasInterject(channel),
|
|
2547
|
+
...(store.claimSteers
|
|
2548
|
+
? {
|
|
2549
|
+
steers: {
|
|
2550
|
+
claim: () => store.claimSteers(channel),
|
|
2551
|
+
complete: (ids) => store.complete(ids),
|
|
2552
|
+
release: (ids) => store.release(ids),
|
|
2553
|
+
},
|
|
2554
|
+
}
|
|
2555
|
+
: {}),
|
|
2419
2556
|
...(store.hasPending
|
|
2420
2557
|
? { hasPending: () => store.hasPending(channel) }
|
|
2421
2558
|
: {}),
|