DeepSeek Harness 能力三角色

2026-09-08 00:00    #AI   #工具   #DeepSeek  

官方文档常出现 Service DefinitionService ProviderConsumer 三个词,它们合在一起构成一项能力的 seam(可替换的能力接口)。

完整能力构成其 seam;任何单一角色都不是 seam。

三种角色各是什么

当一项能力足够通用、需要支持可替换的提供方时(例如 Bash 执行),harness 会把能力拆成三种角色:

角色负责什么以 Bash 为例
Service Definition 接口 + 类型定义 Cordis 服务,以及请求 Request 和结果 Result 的类型dsh-shell(注册为 ctx.shell
Service Provider 实现真正实现该能力,通常针对一种运行环境dsh-bash-local(本地执行)
Consumer 面向模型的工具把能力公开为模型可调用的工具dsh-tool-bash(bash 工具)

三个角色可以放在同一个包里,也可以拆进不同包。判断标准只有一个:这些角色是否需要独立演进或替换

三角色关系

三个角色都依赖 Definition,而 Provider 与 Consumer 互不依赖。Definition 在中间,Provider 继承实现 Definition,Consumer 通过 inject: ['shell'] 依赖它。因此换 Provider 时,Definition 和 Consumer 一行都不用改

以 Bash 为例:ctx.shell 的三角色

ctx 键角色DefinitionProviderConsumer
ctx.shellseamshellbash-local / bash-sandbox / pwsh-localtool-bash / tool-pwsh / hooks-claude-code / hooks-codex

消费方还包括 hooks-claude-codehooks-codex 两个钩子桥接插件,它们和 tool-bash 一样只认 ctx.shell 接口,不关心背后是哪个执行器。

在 Bash seam 里,面向模型的请求 ShellExecRequest(workdir、timeoutMs 可选)与执行器实际使用的完全解析后的规格 ShellExecSpec(字段必填)被分开。工具层在二者之间调用 ctx.shell.resolve(request),这就是「包边界处显式优于隐式」。

为什么要拆成三个角色

好处一:提供方可替换。同一个 Service Definition 可以有多个提供方,通过 cordis.yml 选择:

1# 文件路径:cordis.yml
2# 本地执行
3- name: '@deepseek-ai/dsh-bash-local'
4
5# 想换提供方时,替换上面这一行即可
6# - name: '@deepseek-ai/dsh-bash-sandbox'

好处二:三个角色可以独立演进

角色独立演进的自由度
Service Definition一旦调用方开始依赖它的约定,就很少改动
Service Provider可以独立优化性能和安全性
Consumer可以调整能力向模型呈现的方式

好处三:依赖解耦

依赖关系是否成立
Provider → Definition
Consumer → Definition
Provider → Consumer
Consumer → Provider

动手梳理已有 seam

按三步梳理任意熟悉的 seam(如 ctx.fsctx.llm):①找出 Definition 包;②找出 Provider 包;③找出 Consumer。

要点