Skip to content

docs(tokenless): document compression trigger conditions and thresholds - #2600

Open
Forrest-ly wants to merge 2 commits into
alibaba:mainfrom
Forrest-ly:chore/tokenless-compression-trigger-thresholds
Open

docs(tokenless): document compression trigger conditions and thresholds#2600
Forrest-ly wants to merge 2 commits into
alibaba:mainfrom
Forrest-ly:chore/tokenless-compression-trigger-thresholds

Conversation

@Forrest-ly

Copy link
Copy Markdown
Collaborator

改动说明

为 tokenless 用户文档补充「压缩触发阈值」说明(客户反馈:文档缺少对压缩何时触发、阈值多大的解释)。现有文档只在 CLI 参考和框架集成中零散提到阈值数字,没有集中说明压缩的触发条件;本次将其汇总为用户手册中的独立小节,并补充交叉引用。

变更内容

  • docs/user-guide/{zh,en}/token-saving/tokenless/user-manual.md
    • 新增小节「压缩的触发条件与阈值 / Compression trigger conditions and thresholds」:
      • 响应压缩实际生效的 5 个前提条件(压缩未停用、非内容读取类工具、达到最小响应长度、合法 JSON、结果严格小于原文);
      • 三层工具分类阈值表(内容读取类跳过;Shell/exec:65,536 字符 / 128 项 / 深度 8;其他结构化:1,048,576 字符 / 65,536 项 / 深度 32),并注明阈值来源 tool_categories.json 及安全回退;
      • 阈值语义(字符串截断、数组保留上限、深度折叠,及与 Stash 取回的关系);
      • 路径差异:独立 CLI 默认值(4,096 / 32 / 8)及覆盖参数、Codex 额外跳过任务管理类工具且 4,000 字符门槛、OpenClaw skip_tools/shell_tools 覆盖、TOON 独立触发判断、AgentScope 按模式选择阈值。
    • 「按任务查找文档 / Find documentation by task」表新增对应条目。
  • docs/user-guide/{zh,en}/token-saving/tokenless/cli-reference.mdcompress-response 阈值说明处补充指向新小节的交叉引用。
  • docs/user-guide/{zh,en}/token-saving/tokenless/framework-integration.md:「Adapter 处理规则 / Adapter processing rules」末尾补充指向新小节的交叉引用。

所有数字均逐一对照当前代码实现核实:common/hooks/compress_response_hook.pycommon/hooks/compress_toon_hook.py(最小 200 字符、严格变小保护)、codex/scripts/compress-response(500 / 4,000 字符)、common/hooks/tool_categories.jsonhook_utils.py(三层阈值)、openclaw/index.ts(200 字符、分类覆盖)、tokenless-schema/src/response_compressor.rs(CLI 默认 4096/32/8)。

测试情况

测试范围与实际执行的命令(本次为纯文档变更,共 6 个 Markdown 文件,无代码改动):

  1. bash scripts/docs-lint.sh(CI Docs 门禁:中文命名规范 + en/zh 目录树镜像)— 通过:✓ Naming convention OK✓ en/zh tree parity OK
  2. python3 scripts/docs-link-check.py(CI 相对链接检查)— 通过:✓ All relative links resolve
  3. 手工核对新增/修改链接的锚点均存在(#压缩的触发条件与阈值#compression-trigger-conditions-and-thresholds 等,GitHub 锚点规则下成立)
  4. 文档中全部阈值数字与源码逐项比对(见上文「改动说明」列出的文件),与实现一致

环境概要:Linux x86_64;Python 3.8;git/gh CLI。

结果汇总:2 个 CI 门禁脚本全部通过,0 失败;锚点核对通过;数字与源码一致。

未运行项及原因

  • cargo check / cargo test:未运行 — 本次无任何 Rust/代码改动,仅文档。
  • 各 Adapter 的运行时端到端触发验证:未运行 — 本次不改变运行时行为,文档数值均来自对现有源码的核对。

@Forrest-ly
Forrest-ly requested a review from casparant as a code owner August 17, 2026 05:12
@github-actions github-actions Bot added the scope:documentation ./docs/|./*.md|./NOTICE label Aug 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82232111ee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

1. Compression is not switched off. With `compression_enabled=false` or `TOKENLESS_COMPRESSION_ENABLED=0` the run becomes a dry-run: statistics are still calculated, but the original text is returned (see the previous section).
2. The tool is not a content-retrieval tool. Read/Glob/Grep/LSP/NotebookRead and their aliases skip response compression so their content stays intact.
3. The response reaches the minimum length. The shared response hook, OpenClaw, and Hermes skip responses shorter than 200 characters; Codex skips responses shorter than 500 characters. Length is counted in characters, not bytes.
4. The content is valid JSON. Response compression only handles JSON; plain text passes through unchanged. The shared paths additionally skip skill-like text with YAML frontmatter.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Document Codex's plain-text compression exception

For Codex responses of at least 500 characters, plain text does not pass through unchanged: adapters/tokenless/codex/scripts/compress-response wraps non-JSON text as {"stdout": raw_text} and runs both response compression and TOON encoding (lines 328–380), potentially appending the result once the original reaches 4,000 characters. Qualify this JSON requirement as applying only to the shared/OpenClaw/Hermes paths, or add the Codex exception, so Codex users are not told that large plain-text shell output bypasses compression.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — adopted and fixed in dfe1cbe. Verified against the source: src/tokenless/adapters/tokenless/codex/scripts/compress-response computes is_json on the raw text and, when it is not JSON, wraps it as {"stdout": raw_text} before running both compress-response and compress-toon, so Codex plain-text responses that reach the 500-character minimum are compressed too (with the compressed content added to context only for responses of at least 4,000 characters).

Item 4 in both the en and zh user manuals now scopes the plain-text passthrough statement to the shared response hook, OpenClaw, and Hermes paths, calls out the Codex wrapping exception explicitly, and notes that OpenClaw/Hermes frameworks wrap shell output in JSON themselves (e.g. {"stdout": ...}), so that output is still compressed. The YAML-frontmatter sentence now also names the three paths that apply the skip (the Codex hook has no such skip).

@qoderai qoderai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本次仅发现 1 处文档行为描述与 Codex 特殊路径存在轻微偏差,已在英文用户手册对应位置留下建议性注释。未发现其他会影响压缩触发或阈值理解的具体问题。


🤖 Generated by QoderView workflow run

1. Compression is not switched off. With `compression_enabled=false` or `TOKENLESS_COMPRESSION_ENABLED=0` the run becomes a dry-run: statistics are still calculated, but the original text is returned (see the previous section).
2. The tool is not a content-retrieval tool. Read/Glob/Grep/LSP/NotebookRead and their aliases skip response compression so their content stays intact.
3. The response reaches the minimum length. The shared response hook, OpenClaw, and Hermes skip responses shorter than 200 characters; Codex skips responses shorter than 500 characters. Length is counted in characters, not bytes.
4. The content is valid JSON. Response compression only handles JSON; plain text passes through unchanged. The shared paths additionally skip skill-like text with YAML frontmatter.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] JSON 规则需明确 Codex 例外
第 4 条将“响应压缩只处理 JSON;纯文本直接透传”描述为通用行为,但 Codex 路径会先把纯文本封装为 {"stdout": ...} 再参与压缩。建议在此补充 Codex 例外或限定该规则仅适用于共享/OpenClaw/Hermes/独立 CLI 路径,避免 Codex 用户误解大体纯文本输出不会被压缩。


🤖 Generated by QoderFix in Qoder

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — adopted and fixed in dfe1cbe. Verified against the source: src/tokenless/adapters/tokenless/codex/scripts/compress-response computes is_json on the raw text and, when it is not JSON, wraps it as {"stdout": raw_text} before running both compress-response and compress-toon, so Codex plain-text responses that reach the 500-character minimum are compressed too (with the compressed content added to context only for responses of at least 4,000 characters).

Item 4 in both the en and zh user manuals now scopes the plain-text passthrough statement to the shared response hook, OpenClaw, and Hermes paths, calls out the Codex wrapping exception explicitly, and notes that OpenClaw/Hermes frameworks wrap shell output in JSON themselves (e.g. {"stdout": ...}), so that output is still compressed. The YAML-frontmatter sentence now also names the three paths that apply the skip (the Codex hook has no such skip).

Forrest-ly added a commit to Forrest-ly/anolisa that referenced this pull request Aug 17, 2026
…ore/tokenless-doc-compress-rate-scenarios

Bring in the user-manual anchor (#compression-trigger-conditions-and-thresholds)
that measuring-savings references, so PR alibaba#2601 passes the website link check
before PR alibaba#2600 is merged. Cross-PR dependency fix for CI.
Forrest-ly and others added 2 commits August 17, 2026 16:40
Co-authored-by: multica-agent <github@multica.ai>
…eption

The Codex response hook wraps non-JSON text as {"stdout": ...} before
compression, so plain-text responses that reach the minimum length are
compressed there too. Scope the "plain text passes through unchanged"
statement to the shared response hook, OpenClaw, and Hermes paths, and
note that OpenClaw/Hermes frameworks wrap shell output in JSON
themselves. Also spell out that the YAML-frontmatter skip applies to
the shared response hook, OpenClaw, and Hermes (not Codex).

Co-authored-by: multica-agent <github@multica.ai>
@Forrest-ly
Forrest-ly force-pushed the chore/tokenless-compression-trigger-thresholds branch from dfe1cbe to a5a9fa3 Compare August 17, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:documentation ./docs/|./*.md|./NOTICE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant