@kernel4632/agent-core 0.30.2 → 0.30.4

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 CHANGED
@@ -374,7 +374,7 @@ const agent = Agent.create({ config: { ...config, system: ['你是一个助手
374
374
  ├── notify.js ← 所有回调的统一出口
375
375
  ├── schema.js ← 工具参数格式归一化(scan 和 adopt 共用)
376
376
  ├── shape.js ← 工具返回值变成输出块(内存工具用;子进程里有一份副本)
377
- └── tokens.js ← 上下文 token 估算:字符数 × 每字符 token 比,比例由真实 usage 自校准
377
+ └── tokens.js ← 上下文 token 估算:文字按字符数 × 每字符 token 比(比例由真实 usage 自校准),媒体按块计
378
378
  ```
379
379
 
380
380
  `tool.js` 和 `tool-process.js` 是同一件事的两半,所以放在一起:前者在主线程里找工具、管工具进程,
@@ -1156,7 +1156,7 @@ const { messages, token } = Agent.context.build({
1156
1156
  tools: tools.schema,
1157
1157
  })
1158
1158
  // messages → 可以直接传给 LLM.chat 的消息数组
1159
- // token → 估算的 token 数(不装分词器:字符数 × 每字符 token 比,比例由 Loop 从真实 usage 自校准)
1159
+ // token → 估算的 token 数(不装分词器:文字按字符数 × 每字符 token 比,比例由 Loop 从真实 usage 自校准;媒体按块计,不看 base64 长度)
1160
1160
  ```
1161
1161
 
1162
1162
  裁剪的最小单位是**回合**,不是消息。一个回合 = 模型的一次响应 + 它发起的全部工具调用 + 这些调用的结果,
@@ -1393,6 +1393,8 @@ const agent = Agent.create({ config: { /* ... */ }, tools })
1393
1393
 
1394
1394
  **上下文 token 怎么估**:不装分词器,用"字符数 × 每字符多少 token"。这个比例是**会自校准**的——每轮模型都会回 `usage.inputTokens`(这次请求真实的输入 token 数),拿它反推这个模型真实的"每字符 token 比"记下来给下一轮。换模型(`config.compact` 的压缩模型、`send` 时覆盖 `model`、换 provider)就换一条记录,越用越准,也不怕分词器对不上模型。
1395
1395
 
1396
+ **图片 / 音频 / 视频 / 文件不按 base64 字符数算。** 媒体块在 JSON 里可能有几百万字符,但模型为它付的 token 只取决于尺寸和解码方式,所以每块按固定值(`MEDIA_TOKENS`,1200)估,校准时会先把这部分从真实用量里扣掉。不这么做的话,一张截图就能让估算从 14 万跳到 80 万,上下文还很空就触发压缩(实战踩过:JSON 从 100 万字符涨到 4700 万字符)。
1397
+
1396
1398
  **压缩只往 `agent.history` 里追加一条总结,永远不删任何东西。** `history` 是唯一权威数据来源,该保留多少由持有它的你来决定——压缩控制的是"这一轮发给模型的内容有多大",不是"历史能留多少"。
1397
1399
 
1398
1400
  **压缩可以另配一套模型。** 总结不需要主模型那么聪明,用便宜的小模型就够,写在 `config.compact` 里: