Liking cljdoc? Tell your friends :D

im.ttalk.agent.tokens

token 粗估(零依赖)——上下文压缩(filter.compaction)、工具结果截断 (filter.tool-output)与模型审阅者的证据预算共用一份口径。

口径(宁高勿低:低估会让压缩来不及触发,高估只是早压一点):

  • ASCII 每 4 个字符 1 token(英文/代码的经验值);
  • 非 ASCII 每字符 1 token(CJK 实测约 0.6–1.2,取保守端);
  • 每条消息 +4(角色/分隔开销);
  • 工具调用 = 名字 + 参数 pr-str;
  • 图片 / 文件部件按固定值(image-tokens / document-tokens,同 Keelson CompactionBudget:⛔ 按 base64 长度算——那会把一张图算成几万 token)。

设计见 designs/runtime-borrow.md §1。

token 粗估(零依赖)——上下文压缩(`filter.compaction`)、工具结果截断
(`filter.tool-output`)与模型审阅者的证据预算共用一份口径。

口径(宁高勿低:低估会让压缩来不及触发,高估只是早压一点):
- ASCII 每 4 个字符 1 token(英文/代码的经验值);
- 非 ASCII 每字符 1 token(CJK 实测约 0.6–1.2,取保守端);
- 每条消息 +4(角色/分隔开销);
- 工具调用 = 名字 + 参数 `pr-str`;
- 图片 / 文件部件按固定值(`image-tokens` / `document-tokens`,同 Keelson
  `CompactionBudget`:⛔ 按 base64 长度算——那会把一张图算成几万 token)。

设计见 designs/runtime-borrow.md §1。
raw docstring

document-tokensclj

一个非图片文件部件折多少 token(12000 字符 / 4)。

一个非图片文件部件折多少 token(12000 字符 / 4)。
sourceraw docstring

estimate-contentclj

(estimate-content c)

消息 :content 的 token 数:字符串或多模态部件向量。

消息 `:content` 的 token 数:字符串或多模态部件向量。
sourceraw docstring

estimate-messageclj

(estimate-message m)

一条中立消息的 token 数(内容 + 工具调用 + 固定开销)。

一条中立消息的 token 数(内容 + 工具调用 + 固定开销)。
sourceraw docstring

estimate-messagesclj

(estimate-messages msgs)

消息序列的 token 总数。

消息序列的 token 总数。
sourceraw docstring

estimate-requestclj

(estimate-request msgs {:keys [system-prompt tools]})

整包估算:消息 + system prompt + 工具 schema(都占窗口)。

整包估算:消息 + system prompt + 工具 schema(都占窗口)。
sourceraw docstring

estimate-textclj

(estimate-text s)

一段文本的近似 token 数(nil → 0)。

一段文本的近似 token 数(nil → 0)。
sourceraw docstring

image-tokensclj

一张图片折多少 token(Codex:7373 字节 ≈ 1844 token)。

一张图片折多少 token(Codex:7373 字节 ≈ 1844 token)。
sourceraw docstring

message-overheadclj

每条消息的固定开销。

每条消息的固定开销。
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close