@linnlabs/linnkit 0.44.0 → 0.46.0
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/CHANGELOG.md +48 -0
- package/dist/cli.cjs +61 -8
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +61 -8
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +2 -1
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +2 -1
- package/dist/context-manager.js.map +1 -1
- package/dist/index.cjs +62 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -8
- package/dist/index.js.map +1 -1
- package/dist/quickstart.cjs +61 -8
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +61 -8
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.cts +3 -0
- package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.ts +3 -0
- package/dist/runtime-kernel/graph-engine/types.d.cts +1 -3
- package/dist/runtime-kernel/graph-engine/types.d.ts +1 -3
- package/dist/runtime-kernel/tools/toolContextRuntime.d.cts +1 -1
- package/dist/runtime-kernel/tools/toolContextRuntime.d.ts +1 -1
- package/dist/runtime-kernel/tools/toolExecutionContext.d.cts +10 -0
- package/dist/runtime-kernel/tools/toolExecutionContext.d.ts +10 -0
- package/dist/runtime-kernel.cjs +62 -8
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.js +62 -8
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +62 -8
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +62 -8
- package/dist/testkit.js.map +1 -1
- package/docs/integration/agent-registration-guide.md +1 -1
- package/docs/integration/context-engineering.md +5 -5
- package/docs/integration/run-supervisor.md +1 -0
- package/docs/integration/tool-development-guide.md +4 -2
- package/package.json +2 -1
|
@@ -14,6 +14,8 @@ interface ToolNodeDependencies {
|
|
|
14
14
|
telemetryPort?: TelemetryPort;
|
|
15
15
|
auditPort?: AuditPort;
|
|
16
16
|
modelInputResolver?: ToolModelInputResolverPort;
|
|
17
|
+
/** 停止信号发出后等工具自行结束的期限;默认 3 秒,超时按中断处理并丢弃迟到结果。 */
|
|
18
|
+
abortGraceMs?: number;
|
|
17
19
|
}
|
|
18
20
|
declare class ToolNode implements GraphNode {
|
|
19
21
|
id: string;
|
|
@@ -23,6 +25,7 @@ declare class ToolNode implements GraphNode {
|
|
|
23
25
|
private readonly auditPort;
|
|
24
26
|
private readonly modelInputResolver?;
|
|
25
27
|
private readonly idempotencyInFlight;
|
|
28
|
+
private readonly abortGraceMs?;
|
|
26
29
|
constructor(dependencies: ToolNodeDependencies);
|
|
27
30
|
/**
|
|
28
31
|
* B2-engine Batch 2: 上报 tool_call 事件到宿主侧 TelemetryPort。
|
|
@@ -14,6 +14,8 @@ interface ToolNodeDependencies {
|
|
|
14
14
|
telemetryPort?: TelemetryPort;
|
|
15
15
|
auditPort?: AuditPort;
|
|
16
16
|
modelInputResolver?: ToolModelInputResolverPort;
|
|
17
|
+
/** 停止信号发出后等工具自行结束的期限;默认 3 秒,超时按中断处理并丢弃迟到结果。 */
|
|
18
|
+
abortGraceMs?: number;
|
|
17
19
|
}
|
|
18
20
|
declare class ToolNode implements GraphNode {
|
|
19
21
|
id: string;
|
|
@@ -23,6 +25,7 @@ declare class ToolNode implements GraphNode {
|
|
|
23
25
|
private readonly auditPort;
|
|
24
26
|
private readonly modelInputResolver?;
|
|
25
27
|
private readonly idempotencyInFlight;
|
|
28
|
+
private readonly abortGraceMs?;
|
|
26
29
|
constructor(dependencies: ToolNodeDependencies);
|
|
27
30
|
/**
|
|
28
31
|
* B2-engine Batch 2: 上报 tool_call 事件到宿主侧 TelemetryPort。
|
|
@@ -21,8 +21,6 @@ interface ExecutorLocalState {
|
|
|
21
21
|
systemReminderPolicy?: AgentSpecSystemReminderPolicy;
|
|
22
22
|
toolObservationPolicy?: AgentSpecToolObservationGovernancePolicy;
|
|
23
23
|
runLockedModelId?: string;
|
|
24
|
-
/** 最近一次成功产生当前工具调用决策的真实 provider model。 */
|
|
25
|
-
lastSuccessfulLlmModelId?: string;
|
|
26
24
|
/**
|
|
27
25
|
* 当前这一次 LLM 调用的业务来源。
|
|
28
26
|
*
|
|
@@ -55,7 +53,7 @@ interface ExecutorLocalState {
|
|
|
55
53
|
lastCommittedFingerprint?: string;
|
|
56
54
|
};
|
|
57
55
|
}
|
|
58
|
-
type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | '
|
|
56
|
+
type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | 'contextCompaction'>>;
|
|
59
57
|
interface EngineLocalState extends Record<string, unknown> {
|
|
60
58
|
runId?: RunId;
|
|
61
59
|
parentRunId?: RunId;
|
|
@@ -21,8 +21,6 @@ interface ExecutorLocalState {
|
|
|
21
21
|
systemReminderPolicy?: AgentSpecSystemReminderPolicy;
|
|
22
22
|
toolObservationPolicy?: AgentSpecToolObservationGovernancePolicy;
|
|
23
23
|
runLockedModelId?: string;
|
|
24
|
-
/** 最近一次成功产生当前工具调用决策的真实 provider model。 */
|
|
25
|
-
lastSuccessfulLlmModelId?: string;
|
|
26
24
|
/**
|
|
27
25
|
* 当前这一次 LLM 调用的业务来源。
|
|
28
26
|
*
|
|
@@ -55,7 +53,7 @@ interface ExecutorLocalState {
|
|
|
55
53
|
lastCommittedFingerprint?: string;
|
|
56
54
|
};
|
|
57
55
|
}
|
|
58
|
-
type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | '
|
|
56
|
+
type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | 'contextCompaction'>>;
|
|
59
57
|
interface EngineLocalState extends Record<string, unknown> {
|
|
60
58
|
runId?: RunId;
|
|
61
59
|
parentRunId?: RunId;
|
|
@@ -20,7 +20,7 @@ interface ToolContextRuntimeBinding {
|
|
|
20
20
|
bindExecutionMeta(meta: ToolContextExecutionMeta): void;
|
|
21
21
|
readExecutionMeta(): Readonly<ToolContextExecutionMeta>;
|
|
22
22
|
}
|
|
23
|
-
declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId"];
|
|
23
|
+
declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "activeModelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId"];
|
|
24
24
|
declare function ensureToolContextRuntimeCapability(params: {
|
|
25
25
|
context: ToolExecutionContext;
|
|
26
26
|
persistedHistory?: ReadonlyArray<RuntimeEvent> | RuntimeEventSource;
|
|
@@ -20,7 +20,7 @@ interface ToolContextRuntimeBinding {
|
|
|
20
20
|
bindExecutionMeta(meta: ToolContextExecutionMeta): void;
|
|
21
21
|
readExecutionMeta(): Readonly<ToolContextExecutionMeta>;
|
|
22
22
|
}
|
|
23
|
-
declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId"];
|
|
23
|
+
declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "activeModelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId"];
|
|
24
24
|
declare function ensureToolContextRuntimeCapability(params: {
|
|
25
25
|
context: ToolExecutionContext;
|
|
26
26
|
persistedHistory?: ReadonlyArray<RuntimeEvent> | RuntimeEventSource;
|
|
@@ -17,6 +17,16 @@ interface ToolExecutionContext {
|
|
|
17
17
|
userQuery?: string;
|
|
18
18
|
/** 当前 run 已选定的模型 ID;需要继承模型的 child-run 从这里读取。 */
|
|
19
19
|
modelId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 工具结果接下来交给的模型 ID(由 ToolNode 在执行工具前注入)。
|
|
22
|
+
*
|
|
23
|
+
* 中文备注:
|
|
24
|
+
* - 平时等于 `modelId`;云端额度兜底后 run 锁定到兜底模型,此时是兜底模型;
|
|
25
|
+
* - 决定工具结果里放什么给模型看(如是否附图)时按它判断,不能按 `modelId`,
|
|
26
|
+
* 否则会给不能看图的兜底模型附图,下一次请求在输入预检被拒;
|
|
27
|
+
* - child-run 继承模型仍读 `modelId`。
|
|
28
|
+
*/
|
|
29
|
+
activeModelId?: string;
|
|
20
30
|
/**
|
|
21
31
|
* 当前对话 run 的唯一标识(由 host admission 注入)。
|
|
22
32
|
* 说明:工具不得把 runId 当作业务数据身份;它只服务运行链路追踪和关联。
|
|
@@ -17,6 +17,16 @@ interface ToolExecutionContext {
|
|
|
17
17
|
userQuery?: string;
|
|
18
18
|
/** 当前 run 已选定的模型 ID;需要继承模型的 child-run 从这里读取。 */
|
|
19
19
|
modelId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 工具结果接下来交给的模型 ID(由 ToolNode 在执行工具前注入)。
|
|
22
|
+
*
|
|
23
|
+
* 中文备注:
|
|
24
|
+
* - 平时等于 `modelId`;云端额度兜底后 run 锁定到兜底模型,此时是兜底模型;
|
|
25
|
+
* - 决定工具结果里放什么给模型看(如是否附图)时按它判断,不能按 `modelId`,
|
|
26
|
+
* 否则会给不能看图的兜底模型附图,下一次请求在输入预检被拒;
|
|
27
|
+
* - child-run 继承模型仍读 `modelId`。
|
|
28
|
+
*/
|
|
29
|
+
activeModelId?: string;
|
|
20
30
|
/**
|
|
21
31
|
* 当前对话 run 的唯一标识(由 host admission 注入)。
|
|
22
32
|
* 说明:工具不得把 runId 当作业务数据身份;它只服务运行链路追踪和关联。
|
package/dist/runtime-kernel.cjs
CHANGED
|
@@ -5175,13 +5175,11 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5175
5175
|
"llmCallStartedAt",
|
|
5176
5176
|
"llmResp",
|
|
5177
5177
|
"llmCallDurationMs",
|
|
5178
|
-
"executorLocalPatch",
|
|
5179
5178
|
"contextUsage"
|
|
5180
5179
|
],
|
|
5181
5180
|
async run(ctx) {
|
|
5182
5181
|
let cloudQuotaFallbackAppliedModelId;
|
|
5183
5182
|
let modelFallbackAudit;
|
|
5184
|
-
let lastSuccessfulLlmModelId;
|
|
5185
5183
|
let contextUsage;
|
|
5186
5184
|
const modelFallbackRejections = [];
|
|
5187
5185
|
const promptBudget = ctx.promptBudget;
|
|
@@ -5202,8 +5200,7 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5202
5200
|
onCloudQuotaFallbackApplied(fallbackModelId) {
|
|
5203
5201
|
cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
|
|
5204
5202
|
},
|
|
5205
|
-
onLlmAttemptSucceeded(
|
|
5206
|
-
lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
|
|
5203
|
+
onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
|
|
5207
5204
|
contextUsage = attemptContextUsage;
|
|
5208
5205
|
},
|
|
5209
5206
|
onModelFallbackApplied(info) {
|
|
@@ -5304,7 +5301,6 @@ function createExecuteLlmStage(dependencies) {
|
|
|
5304
5301
|
llmCallStartedAt,
|
|
5305
5302
|
llmResp,
|
|
5306
5303
|
llmCallDurationMs,
|
|
5307
|
-
executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
|
|
5308
5304
|
contextUsage
|
|
5309
5305
|
};
|
|
5310
5306
|
}
|
|
@@ -8213,6 +8209,7 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
|
|
|
8213
8209
|
"conversationView",
|
|
8214
8210
|
"userQuery",
|
|
8215
8211
|
"modelId",
|
|
8212
|
+
"activeModelId",
|
|
8216
8213
|
"conversationId",
|
|
8217
8214
|
"turnId",
|
|
8218
8215
|
"runId",
|
|
@@ -8546,6 +8543,12 @@ function parseToolArgs(call) {
|
|
|
8546
8543
|
};
|
|
8547
8544
|
}
|
|
8548
8545
|
}
|
|
8546
|
+
function readRunLockedModelId(local) {
|
|
8547
|
+
const executorLocal = local.executorLocal;
|
|
8548
|
+
if (!isRecord9(executorLocal)) return void 0;
|
|
8549
|
+
const lockedModelId = executorLocal.runLockedModelId;
|
|
8550
|
+
return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
|
|
8551
|
+
}
|
|
8549
8552
|
function prepareToolNodeContext(state) {
|
|
8550
8553
|
const local = state.local || {};
|
|
8551
8554
|
const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
|
|
@@ -8563,6 +8566,7 @@ function prepareToolNodeContext(state) {
|
|
|
8563
8566
|
}
|
|
8564
8567
|
});
|
|
8565
8568
|
attachWorkingHistoryView({ state, toolContext });
|
|
8569
|
+
toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
|
|
8566
8570
|
return {
|
|
8567
8571
|
state,
|
|
8568
8572
|
local,
|
|
@@ -8805,9 +8809,49 @@ function recordToolProtocolError(params) {
|
|
|
8805
8809
|
}
|
|
8806
8810
|
|
|
8807
8811
|
// src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
|
|
8812
|
+
var DEFAULT_TOOL_ABORT_GRACE_MS = 3e3;
|
|
8813
|
+
function settleToolWithinAbortGrace(input) {
|
|
8814
|
+
const { execution, signal, graceMs } = input;
|
|
8815
|
+
if (!signal) return execution;
|
|
8816
|
+
return new Promise((resolve, reject) => {
|
|
8817
|
+
let timer;
|
|
8818
|
+
const cleanup = () => {
|
|
8819
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
8820
|
+
signal.removeEventListener("abort", startGrace);
|
|
8821
|
+
};
|
|
8822
|
+
function startGrace() {
|
|
8823
|
+
timer = setTimeout(() => {
|
|
8824
|
+
cleanup();
|
|
8825
|
+
execution.catch(() => void 0);
|
|
8826
|
+
input.onAbandon?.();
|
|
8827
|
+
const error = new Error("Tool did not stop within the abort grace period; its late outcome is discarded.");
|
|
8828
|
+
error.name = "AbortError";
|
|
8829
|
+
reject(error);
|
|
8830
|
+
}, graceMs);
|
|
8831
|
+
}
|
|
8832
|
+
if (signal.aborted) startGrace();
|
|
8833
|
+
else signal.addEventListener("abort", startGrace, { once: true });
|
|
8834
|
+
execution.then(
|
|
8835
|
+
(value) => {
|
|
8836
|
+
cleanup();
|
|
8837
|
+
resolve(value);
|
|
8838
|
+
},
|
|
8839
|
+
(error) => {
|
|
8840
|
+
cleanup();
|
|
8841
|
+
reject(error);
|
|
8842
|
+
}
|
|
8843
|
+
);
|
|
8844
|
+
});
|
|
8845
|
+
}
|
|
8808
8846
|
async function executeRecoverableTool(input) {
|
|
8809
8847
|
const local = input.state.local;
|
|
8810
|
-
|
|
8848
|
+
const run = () => settleToolWithinAbortGrace({
|
|
8849
|
+
execution: input.execute(),
|
|
8850
|
+
signal: local?.signal,
|
|
8851
|
+
graceMs: input.abortGraceMs ?? DEFAULT_TOOL_ABORT_GRACE_MS,
|
|
8852
|
+
onAbandon: input.onAbandon
|
|
8853
|
+
});
|
|
8854
|
+
if (!local?.commitExecutionBoundary) return run();
|
|
8811
8855
|
if (local.executingToolCallId) {
|
|
8812
8856
|
if (local.executingToolCallId !== input.call.id) {
|
|
8813
8857
|
throw new RunRecoveryBlockedError("Pending tool identity does not match execution intent");
|
|
@@ -8820,7 +8864,7 @@ async function executeRecoverableTool(input) {
|
|
|
8820
8864
|
}
|
|
8821
8865
|
local.executingToolCallId = input.call.id;
|
|
8822
8866
|
await local.commitExecutionBoundary(input.state);
|
|
8823
|
-
const result = await
|
|
8867
|
+
const result = await run();
|
|
8824
8868
|
if (!result.success && isRunPauseSignal(local.signal)) {
|
|
8825
8869
|
const error = new Error("Tool execution paused before its outcome was confirmed");
|
|
8826
8870
|
error.name = "AbortError";
|
|
@@ -8940,7 +8984,9 @@ var ToolNode = class {
|
|
|
8940
8984
|
auditPort;
|
|
8941
8985
|
modelInputResolver;
|
|
8942
8986
|
idempotencyInFlight = /* @__PURE__ */ new Map();
|
|
8987
|
+
abortGraceMs;
|
|
8943
8988
|
constructor(dependencies) {
|
|
8989
|
+
this.abortGraceMs = dependencies.abortGraceMs;
|
|
8944
8990
|
this.toolRuntime = dependencies.toolRuntime;
|
|
8945
8991
|
this.observationPreview = dependencies.observationPreview;
|
|
8946
8992
|
this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
|
|
@@ -9158,6 +9204,13 @@ var ToolNode = class {
|
|
|
9158
9204
|
state,
|
|
9159
9205
|
call,
|
|
9160
9206
|
context: prepared.toolContext,
|
|
9207
|
+
abortGraceMs: this.abortGraceMs,
|
|
9208
|
+
onAbandon: () => logger11.warn("[ToolNode] \u5DE5\u5177\u672A\u5728\u505C\u6B62\u671F\u9650\u5185\u7ED3\u675F\uFF0C\u6309\u4E2D\u65AD\u5904\u7406\u5E76\u4E22\u5F03\u8FDF\u5230\u7ED3\u679C", {
|
|
9209
|
+
toolName: execution.toolName,
|
|
9210
|
+
toolCallId: execution.toolCallId,
|
|
9211
|
+
conversationId: prepared.conversationId,
|
|
9212
|
+
turnId: prepared.turnId
|
|
9213
|
+
}),
|
|
9161
9214
|
execute: () => executeToolWithIdempotency({
|
|
9162
9215
|
idempotencyKey: execution.idempotencyKey,
|
|
9163
9216
|
inFlight: this.idempotencyInFlight,
|
|
@@ -9779,6 +9832,7 @@ var executor = zod.z.object({
|
|
|
9779
9832
|
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9780
9833
|
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9781
9834
|
runLockedModelId: zod.z.string().optional(),
|
|
9835
|
+
// 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
|
|
9782
9836
|
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
9783
9837
|
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
9784
9838
|
llmInvocationCount: counter.optional(),
|
|
@@ -9788,7 +9842,7 @@ var executor = zod.z.object({
|
|
|
9788
9842
|
committedCount: counter,
|
|
9789
9843
|
lastCommittedFingerprint: zod.z.string().optional()
|
|
9790
9844
|
}).strict().optional()
|
|
9791
|
-
}).strict();
|
|
9845
|
+
}).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
|
|
9792
9846
|
var checkpoint = zod.z.object({
|
|
9793
9847
|
nodeId: zod.z.string().min(1),
|
|
9794
9848
|
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|