DeepSeek Harness
DeepSeek Harness Tools、Sessions 与 Model Adapter
理解三类运行时表面如何把模型响应变成持久化、可调用工具的 Agent 任务。

你将学会
- Tools combine schemas, scoped registration, and guarded execution.
- The append-only session log is the source of model-visible context.
- LLM adapters expose a provider seam and streaming interception point.
开始前需要
- Basic HTTP and API knowledge
Leave with a concrete implementation checklist and a testable starting point.
先看结论
- Tools 结合 schema、作用域注册和受保护执行。
- append-only Session Log 是模型上下文来源。
- LLM Adapter 提供 Provider 接缝和流式扩展点。
Tools 是受保护的流水线
Tools 子系统是有作用域的注册表和受保护执行流水线。模型工具注册到 ctx.tools,schema 进入提示词组装,执行依次经过 pre-execute、execute 和 post-execute。
这种分层让策略监听器可以检查或拒绝调用,而不用修改 Agent Loop;也便于记录工具耗时、失败和审批决定。
Session 是事实来源
Session Log 以 append-only Event 保存模型可见事实。deriveMessages 从日志投影模型历史,assistant chunk 则保留重放和 UI 所需的细节。
任何进入模型请求的新信息都必须能从日志重建。这样比写一条 debug 日志更严格,但可以避免隐藏上下文导致结果无法复现。
LLM Adapter 是替换接缝
LLM Runtime 是 Adapter 注册表和流式模型调用 API。Provider 注册路由,运行时解析模型元数据,并让 prepared call 在能力查询和派发期间保持同一个注册。
`llm/stream` 是重试、重放和路由的扩展点。适配器错误可以转为终止 chunk,而 middleware 与 consumer 错误仍会抛出。
如何选择
| 比较维度 | 方案 A | 方案 B |
|---|---|---|
| Best when | You need predictable behavior and easy auditing | You need adaptive optimization and have reliable telemetry |
| Main risk | May leave performance on the table | Can become difficult to explain or debug |
实施步骤
- 1
定位工具注册和执行阶段。
- 2
追踪模型可见事实进入 Session Log。
- 3
定位 Adapter 路由和能力查询。
- 4
在 trace 中分别测量工具和上游失败。
可复制示例
ctx.tools -> prompt schema -> tools/pre-execute
-> tools/execute -> tools/post-execute
ctx.llm -> prepareCall -> llm/stream -> provider adapter常见问题
工具可以绕过 Session Log 吗?
模型可见事实应表示为 Session Event,才能保持历史和重放可重建。
资料来源
- DeepSeek Harness tools subsystem来源核查 2026-08-27
- DeepSeek Harness session subsystem来源核查 2026-08-27
- DeepSeek Harness LLM streaming subsystem来源核查 2026-08-27