anchor-ai-sdk 0.10.0 → 0.10.3
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 +10 -9
- package/dist/engine/events.d.ts +3 -1
- 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/loop.d.ts.map +1 -1
- package/dist/engine/loop.js +102 -3
- 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 +3 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +2 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/openai-compatible.d.ts +34 -3
- package/dist/llm/openai-compatible.d.ts.map +1 -1
- package/dist/llm/openai-compatible.js +73 -2
- 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
|
@@ -105,8 +105,8 @@ the same tools and no ledger or completion gate.
|
|
|
105
105
|
Ledger operations are one tool each: `add_requirement` adds a commitment,
|
|
106
106
|
`set_requirement_status` changes its status, `link_evidence` attaches a tool
|
|
107
107
|
result with a required claim, and `verify_requirement` links and marks it
|
|
108
|
-
verified in one call. The
|
|
109
|
-
|
|
108
|
+
verified in one call. The old `update_ledger` shim was removed in 0.8.6; use
|
|
109
|
+
the split tools. Phase transitions verify the outgoing
|
|
110
110
|
phase; a rejection names each unmet requirement and its probability. After the
|
|
111
111
|
configured rejection limit the transition is forced, but the requirement stays
|
|
112
112
|
open and still blocks `finish`.
|
|
@@ -642,10 +642,11 @@ engine emits `inbox_steer` (`{ count }`) when it delivers steers.
|
|
|
642
642
|
| Capability | Your controls |
|
|
643
643
|
| --- | --- |
|
|
644
644
|
| **Budgets and correction** | Step/token/known-dollar budgets, per-child crew budgets with a wrap-up nudge and a hard cap, repeated-call detection, silent-tool and visible-verbosity nudges, prose checkpoints, and per-call output requests. |
|
|
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). |
|
|
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). Reasoning-only turns and leaked tool calls are handled as turn conditions. See [docs/reasoning.md](docs/reasoning.md). |
|
|
646
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). |
|
|
647
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. |
|
|
648
|
+
| **Messages mid-run** | A consumer-owned inbox with `steer` (nudge), `interject` (correct), and `queue` (more work) deliveries, chained by the engine. See [docs/inbox.md](docs/inbox.md). |
|
|
649
|
+
| **Thread checkpoints** | An append-only thread log and checkpoint pointers, with deterministic event keys and pure replay/stale-write rules. See [docs/checkpoints.md](docs/checkpoints.md). |
|
|
649
650
|
| **Context and memory** | Catalog-derived or explicit compaction, supplied thread stores, agent-authored notes, and best-effort output spill. |
|
|
650
651
|
| **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. |
|
|
651
652
|
| **Snapshots and lifecycle** | Git-backed or custom snapshot hooks, optional push, phase-boundary pauses, heartbeats, and cancellation. |
|
|
@@ -815,18 +816,18 @@ and an extraction failure, not the full benchmark or a general superiority claim
|
|
|
815
816
|
|
|
816
817
|
## Status and contributing
|
|
817
818
|
|
|
818
|
-
**Early alpha, 0.x. Source version: 0.
|
|
819
|
+
**Early alpha, 0.x. Source version: 0.10.1; latest published release: v0.10.1.** Pin exact versions and test your
|
|
819
820
|
integration. Provider and runtime features are version-specific; the current
|
|
820
|
-
source may be ahead of the installed package. Daytona,
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
landed in each tag.
|
|
821
|
+
source may be ahead of the installed package. Daytona, context reset, MCP, and
|
|
822
|
+
consumer skill bundles remain roadmap work in the reviewed source. See the
|
|
823
|
+
[changelog](https://anchor-sdk.dev/changelog.html) for what landed in each tag.
|
|
824
824
|
|
|
825
825
|
Questions, bug reports, and provider contributions are welcome. Keep mechanics in
|
|
826
826
|
the SDK and product policy in the consumer; provider changes should include
|
|
827
827
|
conformance coverage and an honest capability declaration.
|
|
828
828
|
|
|
829
829
|
**[Issues](https://github.com/hrithikkoduri/anchor-ai-sdk/issues)** ·
|
|
830
|
+
**[Docs index](docs/README.md)** ·
|
|
830
831
|
**[Release status](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/docs/release-status.md)** ·
|
|
831
832
|
**[Completed tracker](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/TRACKER.md)** ·
|
|
832
833
|
**[Roadmap](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/ROADMAP.md)** ·
|
package/dist/engine/events.d.ts
CHANGED
|
@@ -193,7 +193,7 @@ type AgentEventBody = {
|
|
|
193
193
|
/** Non-blocking runtime guidance (e.g. the materialization advisory).
|
|
194
194
|
* Advisory events never gate actions or end runs. */
|
|
195
195
|
type: "advisory";
|
|
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" | "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";
|
|
197
197
|
detail: string;
|
|
198
198
|
} | {
|
|
199
199
|
/** The dying run's handoff: what it still needs, for a consumer that may
|
|
@@ -227,6 +227,8 @@ type AgentEventBody = {
|
|
|
227
227
|
steps: number;
|
|
228
228
|
usage: LLMUsage;
|
|
229
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;
|
|
230
232
|
/** Set when the run concluded via finish() with a consumer-shaped handoff. */
|
|
231
233
|
handoff?: Record<string, unknown>;
|
|
232
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,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,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;I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B,sCAAsC;IACtC,IAAI,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC"}
|
|
@@ -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,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C,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IAErC,YAA6B,KAAK,EAAE,MAAM,GAAG,KAAK,EAAI;IAEtD,oEAAoE;IACpE,MAAM,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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C9G,6BAA6B;QAC7B,cAAc,CAAC,SAAS,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,SAAkB;IAC/C,OAAO,CACL,+EAA+E;QAC/E,+EAA+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"}
|
|
@@ -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
|
@@ -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;
|
|
@@ -1570,6 +1589,7 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1570
1589
|
steps,
|
|
1571
1590
|
usage,
|
|
1572
1591
|
reason,
|
|
1592
|
+
...(extra.retryable ? { retryable: true } : {}),
|
|
1573
1593
|
...(extra.handoff !== undefined ? { handoff: extra.handoff } : {}),
|
|
1574
1594
|
});
|
|
1575
1595
|
const persisted = await persist(reason !== "paused", extra.handoff !== undefined
|
|
@@ -1990,6 +2010,18 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1990
2010
|
await settleSteers("complete");
|
|
1991
2011
|
steps++;
|
|
1992
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;
|
|
1993
2025
|
const modelMessages = forModel();
|
|
1994
2026
|
const response = await waitWithCancelGrace(opts.llm.stream({
|
|
1995
2027
|
messages: modelMessages,
|
|
@@ -1998,14 +2030,23 @@ async function runOne(input, opts, chain = {}) {
|
|
|
1998
2030
|
type: "function",
|
|
1999
2031
|
function: tool.definition,
|
|
2000
2032
|
})),
|
|
2001
|
-
...(
|
|
2033
|
+
...(callMaxOutputTokens !== undefined
|
|
2034
|
+
? { maxTokens: callMaxOutputTokens }
|
|
2035
|
+
: {}),
|
|
2002
2036
|
...(opts.sampling?.temperature !== undefined
|
|
2003
2037
|
? { temperature: opts.sampling.temperature }
|
|
2004
2038
|
: {}),
|
|
2005
2039
|
...(opts.sampling?.seed !== undefined
|
|
2006
2040
|
? { seed: opts.sampling.seed }
|
|
2007
2041
|
: {}),
|
|
2008
|
-
...(
|
|
2042
|
+
...(callReasoningEffort !== undefined
|
|
2043
|
+
? { reasoningEffort: callReasoningEffort }
|
|
2044
|
+
: {}),
|
|
2045
|
+
...(forcingAction &&
|
|
2046
|
+
opts.llm.supportsToolChoice === true &&
|
|
2047
|
+
available.size > 0
|
|
2048
|
+
? { toolChoice: "required" }
|
|
2049
|
+
: {}),
|
|
2009
2050
|
}, (text) => emit({ type: "llm_text_delta", text }), {
|
|
2010
2051
|
signal,
|
|
2011
2052
|
onReasoning: (text) => emit({ type: "llm_reasoning_delta", text }),
|
|
@@ -2077,6 +2118,45 @@ async function runOne(input, opts, chain = {}) {
|
|
|
2077
2118
|
}
|
|
2078
2119
|
if (!response.toolCalls.length) {
|
|
2079
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
|
+
}
|
|
2080
2160
|
// Flag, not a message scan: the advisory is already in the
|
|
2081
2161
|
// conversation, but the stop decision is this boolean.
|
|
2082
2162
|
if (!emptyNudged) {
|
|
@@ -2093,6 +2173,24 @@ async function runOne(input, opts, chain = {}) {
|
|
|
2093
2173
|
error: "model returned neither text nor tool calls",
|
|
2094
2174
|
});
|
|
2095
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
|
+
}
|
|
2096
2194
|
// An unfinished sentence is not an answer. A reply cut off by the cap
|
|
2097
2195
|
// must never be accepted as the run's result. It also must not end a
|
|
2098
2196
|
// run that was still working (#79): same shape as a nudge — inject
|
|
@@ -2181,6 +2279,7 @@ async function runOne(input, opts, chain = {}) {
|
|
|
2181
2279
|
});
|
|
2182
2280
|
}
|
|
2183
2281
|
pendingProseCheck = false;
|
|
2282
|
+
reasoningLimitContinues = 0;
|
|
2184
2283
|
let declared;
|
|
2185
2284
|
let runaway = false;
|
|
2186
2285
|
const dispatched = await waitWithCancelGrace(dispatchToolCalls({
|