前言¶
在 DeepSeek Harness(DSH)里做智能体时,工具输出会直接进入模型上下文。像 bash、job_output 这类工具,有时会返回很长的命令输出;如果原样交给模型,会明显增加 token 和上下文占用,但也可能丢掉退出码、超时、信号等状态信息。
dsh-rtk-filter 的处理方式是:当工具结果满足条件时,把正文交给外部 rtk CLI 精简,再把 RTK 的输出作为模型可见内容。它不改写工具的 canonical value,也保留末尾状态标记;外部依赖不可用或失败时,会静默回退到原始输出。
DSH 插件生态中的社区目录是独立站点,不是 DeepSeek 或幻方的官方应用商店。
这是什么¶
dsh-rtk-filter 是一个 DSH 插件,由 Aeternus123 维护,许可证为 MIT。
它的作用是:把过大的命令输出通过外部 rtk CLI 管道处理,然后把 RTK 精简后的文本交给模型,而不是把原始大段文本直接放进模型上下文。它注册的是 tools/post-execute result transformer,在工具 dispatch 之后、lossless materialization 之前替换模型可见内容。
它依赖外部 rtk CLI。若 rtk 不存在、执行失败、超时、被取消、没有输出或输出无变化,插件会保留原始输出。
核心功能¶
- 只处理符合条件的结果:
accept决策、非失败结果、工具名在配置列表中、内容为纯文本、字节数不低于minBytes。 - 注册
tools/post-executeresult transformer,替换的是模型可见内容,不改工具 canonical value。 - 保留末尾状态标记,例如:
[exit code: N][killed by signal: ...][timed out after Nms][sandbox: ...][status: ...]- 当
rtk缺失、非零退出、超时、被取消、无输出或输出未变化时,静默降级为原始输出。 - 支持裸命令名。若配置里写
rtk,插件会探测候选目录,例如: ~/.cargo/bin/opt/homebrew/bin/usr/local/bin/opt/local/bin~/.local/bin- 支持
rtk pipe模式,也支持可选 filter,例如-f cargo-test。
安装与启用¶
准备 rtk¶
先确认本机已经安装 rtk。例如:
brew install rtk
如果未安装,插件会静默降级,不会让命令执行失败。
GitHub 安装¶
用 DSH CLI 安装:
dsh plugin --profile web add github:Aeternus123/dsh-rtk-filter
这条命令以 web profile 为例。安装后,包内自带的 cordis.patch.yml 会自动生效。
本地挂载¶
如果是本地开发,也可以把插件挂到 profile 的 node_modules 里:
mkdir -p ~/.dsh/profiles/web/node_modules
ln -s /path/to/dsh-rtk-filter ~/.dsh/profiles/web/node_modules/dsh-rtk-filter
然后在 profile 的 cordis.patch.yml 里追加挂载配置。
挂载配置¶
以下是一个基本配置示例:
- insert:
- id: rtk-filter
name: dsh-rtk-filter
config:
command: /opt/homebrew/bin/rtk
args: ['pipe']
minBytes: 2048
这段配置做了三件事:
- 指定
rtk可执行文件路径。 - 使用
pipe模式,即 stdin 进原始文本,stdout 出精简文本。 - 设置
minBytes: 2048,低于该字节数的输出直接放行。
DSH 的 bash 工具使用非登录 shell,可能不会继承终端里的 PATH。因此推荐写 rtk 的绝对路径,例如 /opt/homebrew/bin/rtk。如果写裸名 rtk,插件会尝试探测上面列出的候选目录。
典型用法¶
通用 pipe 模式¶
最直接的配置是使用 pipe:
- insert:
- id: rtk-filter
name: dsh-rtk-filter
config:
command: /opt/homebrew/bin/rtk
args: ['pipe']
minBytes: 2048
pipe 模式对应“stdin 进原始文本,stdout 出精简文本”的使用方式。
指定 filter¶
如果主要处理某类输出,可以给 rtk pipe 指定 filter:
- insert:
- id: rtk-filter
name: dsh-rtk-filter
config:
command: /opt/homebrew/bin/rtk
args: ['pipe', '-f', 'cargo-test']
minBytes: 2048
这里使用 -f cargo-test,适合主要处理 cargo 测试输出的工作流。
需要注意:rtk pipe 只会在输入匹配指定 -f filter 时才真正压缩;不匹配的输入会原样透传。插件检测到输出无变化时,也不会追加额外提示。
适用场景与注意¶
适合使用 dsh-rtk-filter 的场景:
- 智能体经常执行
bash、job_output等命令,输出经常偏大。 - 希望减少模型上下文占用,但保留退出码、超时、信号等状态标记。
- 已有
rtkCLI,并希望通过 DSH 插件统一管理输出精简逻辑。
使用前需要注意:
- 插件依赖外部
rtkCLI。rtk不可用或执行失败时,插件保留原始输出。 - 插件只改模型可见内容,不改工具的 canonical value。
rtk pipe配合-ffilter 时,不匹配输入会原样透传。- DSH bash 工具可能不继承终端 PATH,建议配置
rtk绝对路径。 - 插件以当前 DSH 进程权限运行。安装前应检查源码与 MIT 许可证。
- 运行环境要求 Node
>=20。 - Peer dependencies 包括:
@deepseek-ai/cordis ^4.0.0@deepseek-ai/dsh-llm ^0.1.0-rc.6@deepseek-ai/dsh-tools ^0.1.0-rc.6@deepseek-ai/schemastery ^3.18.0
链接¶
- GitHub:
https://github.com/Aeternus123/dsh-rtk-filter - 目录页:本文资料未提供已核实 URL;可按插件名
dsh-rtk-filter在社区目录中检索。