DeepSeek Harness 源码解析:一次 Agent 请求是怎样完成的DeepSeek Harness: How One Agent Request Runs
本文基于 deepseek-harness 仓库当前检出的源码(
0.1.0-rc.5)。文中的文件路径以这份源码为准;项目仍在快速演化,内部 API 可能变化。
DeepSeek Harness(下面简称 dsh)是一套 Agent 运行时。它做的事情并不神秘:接收用户输入,请求模型,执行模型要求的工具,把工具结果交回模型,直到得到最终回答。真正值得读源码的地方,是它怎样把这条流程变成可以恢复、回放和替换的程序。
本文只跟踪一个小任务:用户要求运行 echo hello。先把这个任务跑通,再解释它经过的 agent-loop、Session 日志、工具调度器、LLM 适配器和 Cordis 插件系统。这样读到后面的类型和事件时,都能知道它们在解决哪个具体问题。
1 | 用户输入 |
This article is based on the checked-out source of deepseek-harness (
0.1.0-rc.5). File paths refer to this checkout; the project is still evolving quickly, so internal APIs may change.
DeepSeek Harness, abbreviated as dsh below, is an Agent runtime. Its job is straightforward: accept user input, call the model, run the tools requested by the model, feed the results back, and stop when a final answer is available. The interesting part in the source is how this ordinary loop becomes recoverable, replayable, and replaceable.
This article follows one small task from beginning to end: the user asks the Agent to run echo hello. We first make that task concrete, then explain the agent-loop, Session log, tool scheduler, LLM adapter, and Cordis plugin system it passes through. That way, every type and event later in the article has a concrete problem to solve.
1 | user input |


大黑山