@linnlabs/linnkit 0.37.3 → 0.37.5

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cli.cjs +2 -1
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +2 -1
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager/profiles/agent/context/config.d.cts +2 -2
  7. package/dist/context-manager/profiles/agent/context/config.d.ts +2 -2
  8. package/dist/context-manager.cjs +36 -24
  9. package/dist/context-manager.cjs.map +1 -1
  10. package/dist/context-manager.js +36 -24
  11. package/dist/context-manager.js.map +1 -1
  12. package/dist/contracts/contextPolicy.d.cts +2 -0
  13. package/dist/contracts/contextPolicy.d.ts +2 -0
  14. package/dist/contracts/events.d.cts +7 -7
  15. package/dist/contracts/events.d.ts +7 -7
  16. package/dist/contracts.cjs +1 -0
  17. package/dist/contracts.cjs.map +1 -1
  18. package/dist/contracts.js +1 -0
  19. package/dist/contracts.js.map +1 -1
  20. package/dist/index.cjs +2 -1
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.js +2 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/quickstart.cjs +2 -1
  25. package/dist/quickstart.cjs.map +1 -1
  26. package/dist/quickstart.js +2 -1
  27. package/dist/quickstart.js.map +1 -1
  28. package/dist/runtime-kernel/events.cjs +1 -0
  29. package/dist/runtime-kernel/events.cjs.map +1 -1
  30. package/dist/runtime-kernel/events.js +1 -0
  31. package/dist/runtime-kernel/events.js.map +1 -1
  32. package/dist/runtime-kernel.cjs +2 -1
  33. package/dist/runtime-kernel.cjs.map +1 -1
  34. package/dist/runtime-kernel.js +2 -1
  35. package/dist/runtime-kernel.js.map +1 -1
  36. package/dist/testkit.cjs +2 -1
  37. package/dist/testkit.cjs.map +1 -1
  38. package/dist/testkit.js +2 -1
  39. package/dist/testkit.js.map +1 -1
  40. package/docs/integration/context-engineering.md +7 -1
  41. package/docs/integration/llm-provider.md +5 -0
  42. package/docs/integration/tool-history.md +23 -0
  43. package/package.json +2 -2
@@ -266,9 +266,15 @@ contextPolicy: {
266
266
  | `workingMemory.minToolInteractionsToKeep` | `2` | compressed 历史工具摘要的预算兜底组数 | ✅ AgentSpec + runtime |
267
267
  | `workingMemory.maxRecentToolRuns` | `2` | 原始 tool_calls 形态保护的最近工具 turn 数 | ✅ AgentSpec + runtime |
268
268
  | `workingMemory.maxRecentToolInteractions` | `2` | Deprecated alias,兼容旧配置;新配置请用 `maxRecentToolRuns` | ⚠️ 兼容保留 |
269
- | `workingMemory.toolPairingSearchRange` | `10` | 搜工具配对的窗口范围 | ✅ AgentSpec + runtime |
269
+ | `workingMemory.toolPairingSearchRange` | `10` | 工具配对距离,只计非本批结果消息;相邻结果为 `1`,同批结果不消耗窗口 | ✅ AgentSpec + runtime |
270
270
  | P1-P3 优先级数字 | `1/2/3` | 优先级编号 | ❌ 不开放|
271
271
 
272
+ 工具组按 `call_id` 配对,不限制单个 assistant 批次的调用数量。配对只在该 assistant
273
+ 之后、下一条 `user_input` 或 assistant 消息之前进行;系统或 Host context 提示可以插入,
274
+ 但受上面的间隔距离限制。完整组要求唯一的调用 ID、每个调用恰好一条结果,显式工具名不得冲突;
275
+ 成功与错误回执同等参与配对。孤儿结果不会补入其他批次,缺失、重复或身份冲突的组不会作为
276
+ 完整组进入工作记忆。详见 [工具历史的批次边界](./tool-history.md#工具批次的配对边界)。
277
+
272
278
  <a id="automatic-context-compaction"></a>
273
279
 
274
280
  ### 5.3 自动上下文压缩 —— Context Manager 纯计划,Graph tick 执行(✅)
@@ -25,6 +25,11 @@ Host 拥有:
25
25
 
26
26
  Provider SDK 不得执行工具、开启自动 multi-step、自行重试或决定切模型。
27
27
 
28
+ 同模型重试由 Host 的 `LlmCaller` 配置控制:`maxRetries` 是首次调用失败后的重试次数,
29
+ 并受总调用预算 `maxTotalAttempts` 约束。普通可重试错误的等待时间取 `retryDelayMs`
30
+ 与分类器建议的较大值,Host 配置因此是等待下限,不会覆盖更长的错误建议。
31
+ 限流错误仍沿用已有指数退避与上限;不可重试错误、用户取消及禁用客户端重试的策略不受此等待配置影响。
32
+
28
33
  ## 2. 请求与流事件
29
34
 
30
35
  Canonical request 只携带 Linnkit 已经决定的事实:模型 ID、resolved messages、可移植 JSON Schema 工具、tool choice、sampling、AbortSignal 和 invocation identity。可选 `cache_policy` 只声明 system prompt 与 history summary 稳定前缀的 canonical message 结束位置;它不承载厂商 TTL、cache key 或 wire 字段。Host adapter 可将断点投影为 Provider 原生语义,不支持的 codec 必须忽略,cache miss 不得改变推理语义。API key、base URL、Provider 对象和 Provider 重试参数不能进入 Linnkit。
@@ -60,6 +60,29 @@ Working memory 阶段还会再用同一个 `maxInteractionGroups` 控制最终 p
60
60
  工具结果附件没有独立保留策略。图片与其他附件都随其 `tool_output` 所属的完整工具交互组一起进入、删除或压缩;
61
61
  不能只删附件,也不能因为工具组含图就绕过 `toolHistory`。退出活动上下文不会删除 durable 工具事实或资源。
62
62
 
63
+ ### 工具批次的配对边界
64
+
65
+ 一个 `assistant.tool_calls` 与其所有 `tool_output` 是一个原子组,按 `call_id` 配对,
66
+ 批次内结果可以乱序到达,回放仍保留实际消息顺序与原文 observation。错误结果和成功结果
67
+ 同样完成调用;重复参数的新调用仍按自己的 ID 和实际结果回放,不做参数缓存或结果去重。
68
+
69
+ - 下一条 `user_input` 或 assistant 消息关闭当前批次;后续结果不能跨过这个边界补全旧组。
70
+ - 系统与 Host context 提示不关闭批次。工作记忆的 `toolPairingSearchRange` 默认仍为 `10`,
71
+ 其距离只计非本批结果消息:紧邻结果距离为 `1`,插入一个提示后的结果距离为 `2`。
72
+ 批次大小不消耗窗口,因此 11、12 或更多条完整结果不会因数量被丢弃。
73
+ - 完整组要求每个调用 ID 唯一、每个调用恰好一条结果;结果显式提供工具名时必须同名。
74
+ RuntimeEvent 投影始终提供工具名,低层 AiMessage 仍允许省略。同一 user turn 内重复声明的 ID、
75
+ 重复结果和工具名冲突都会使相关组不完整;没有当前批次调用的孤儿结果不进入该组。
76
+ - 历史删除、历史摘要和自动 compaction 复用相同的身份与轮次边界。不完整组不能充当完整的
77
+ 压缩单元。自动 compaction 仍按自己的最近组、must-keep 和附件保护规则选择整组。
78
+ - 当前受保护组即使超出工作记忆预算,也原样保留并暴露超额;Graph 的压缩与容量门禁决定
79
+ 后续处理,不能用遗漏批次回执的方式制造“预算内”的请求。
80
+
81
+ 这修正了旧实现把所有消息都计入配对距离的行为:相同配置现在允许完整大批次,但仍限制
82
+ 非结果间隔;增大窗口也不能再穿过新的用户或助手消息。没有删除配置字段或改变默认数值。
83
+ 配对扫描通过 ID 索引完成,时间复杂度为消息数与调用数之和(另加参数、输出序列化的字节量),
84
+ 空间复杂度为消息数与调用数之和;不对每条结果反复扫描整批调用。
85
+
63
86
  ## 5. `AgentSpecContextPolicy.toolHistory` 字段
64
87
 
65
88
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linnlabs/linnkit",
3
- "version": "0.37.3",
3
+ "version": "0.37.5",
4
4
  "type": "module",
5
5
  "description": "A fine-grained context engineering framework for Agent applications — control every token sent to the model, with clear run lifecycle, audit records, and testable protocol boundaries.",
6
6
  "license": "MIT",
@@ -109,7 +109,7 @@
109
109
  "vitest": "^4.1.11"
110
110
  },
111
111
  "linnkit": {
112
- "phase": "development (0.37.3 — durable working history)",
112
+ "phase": "development (0.37.5 — Host retry delay floor)",
113
113
  "sourceOfTruth": "CHANGELOG.md",
114
114
  "notes": [
115
115
  "子入口 ./runtime-kernel/events 是 browser-safe slim seam:仅暴露 events governance 纯函数,禁止扩展任何 Node-only 依赖(如 node:async_hooks / crypto / fs)",