首页 › LLM大语言模型 › Deepseek › DeepSeek Harnrss 实战手册 › DeepSeek Harness 综合实战:搭一个属于自己的 Agent 工作台

DeepSeek Harness 综合实战:搭一个属于自己的 Agent 工作台

前面 12 章你学了安装、CLI、SDK、插件开发。这一章把它们拧成一台"机器":一个每天自动产出代码变更摘要 + 周报的个人 Agent 工作台。做完它,你就不是"会用 dsh",而是"在用它干活"了。​

​

​

​

飞书文档 - 图片

​

49%

​

​

​

飞书文档 - 图片

​

51%

​

​

​

​

​

飞书文档 - 图片

​

50%

​

​

​

飞书文档 - 图片

​

50%

​

​

13.1 目标与成品​

场景:你在维护一个仓库,希望每天自动生成一份"昨天改了什么、有什么风险点"的摘要,周五再汇总成周报。​

成品:​

一个自用插件 weekly_report(注册一个面向模型的工具);​

一个专属 profile(把插件装进去);​

一个 Python 调度脚本(每天跑一个无头任务,报告存进 reports/)。​

13.2 先搭目录骨架​

​

代码块​

Plain Text

mkdir -p agent-workbench/{workspace,sessions,my-plugin/src}​

​

三个目录各司其职:​

​

#wkTBAGocxtaM text { white-space: pre; }#wkTBAGocxtaM .fb0 { stroke: var(--N900-FG, 0.15); }#wkTBAGocxtaM .fb0 {stroke: rgba(31,35,41, 0.15)}#wkTBAGocxtaM .fx0 { stroke-miterlimit: 10; }#wkTBAGocxtaM .fx0 {stroke-miterlimit: 10}#wkTBAGocxtaM .fa1 { fill: rgb(187, 191, 196); }#wkTBAGocxtaM .fa1 {fill: rgb(187, 191, 196)}#wkTBAGocxtaM .fx1 { font: 400 12px MonospacedNumber, LarkHackSafariFont, LarkEmojiFont, LarkChineseQuote, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Tahoma, "PingFang SC", "Microsoft Yahei", Arial, "Hiragino Sans GB", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; }#wkTBAGocxtaM .fx1 {font-style: normal}#wkTBAGocxtaM .fx2 { text-anchor: middle; }#wkTBAGocxtaM .fx2 {text-anchor: middle}#wkTBAGocxtaM .fx3 { dominant-baseline: central; }#wkTBAGocxtaM .fx3 {dominant-baseline: central}#wkTBAGocxtaM .fx4 { stroke: none; }#wkTBAGocxtaM .fx4 {stroke: none}#wkTBAGocxtaM .fc0 { fill: var(--text-caption); }#wkTBAGocxtaM .fc0 {fill: #646a73}#wkTBAGocxtaM .fa2 { fill: var(--text-link-disabled); }#wkTBAGocxtaM .fa2 {fill: rgb(187, 191, 196)}#wkTBAGocxtaM .fa3 { fill: rgb(232, 239, 250); }#wkTBAGocxtaM .fa3 {fill: rgb(232, 239, 250)}#wkTBAGocxtaM .fx5 { font: 700 12px MonospacedNumber, LarkHackSafariFont, LarkEmojiFont, LarkChineseQuote, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Tahoma, "PingFang SC", "Microsoft Yahei", Arial, "Hiragino Sans GB", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; }#wkTBAGocxtaM .fx5 {font-style: normal}#wkTBAGocxtaM .fx6 { text-anchor: start; }#wkTBAGocxtaM .fx6 {text-anchor: start}#wkTBAGocxtaM .fx7 { dominant-baseline: alphabetic; }#wkTBAGocxtaM .fx7 {dominant-baseline: alphabetic}#wkTBAGocxtaM .fc1 { fill: rgb(30, 42, 58); }#wkTBAGocxtaM .fc1 {fill: rgb(30, 42, 58)}#wkTBAGocxtaM .fx8 { font: 400 12px LarkHackSafariFont, LarkEmojiFont, Consolas, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, "Noto Sans", Tahoma, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", STHeiti, SimHei, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", system-ui; }#wkTBAGocxtaM .fx8 {font-style: normal}#wkTBAGocxtaM .fc2 { fill: rgb(26, 58, 122); }#wkTBAGocxtaM .fc2 {fill: rgb(26, 58, 122)}#wkTBAGocxtaM .fx9 { font: 400 12px MonospacedNumber, LarkHackSafariFont, LarkEmojiFont, LarkChineseQuote, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Tahoma, "PingFang SC", "Microsoft Yahei", Arial, "Hiragino Sans GB", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; }#wkTBAGocxtaM .fx9 {font-style: normal}#wkTBAGocxtaM .fb1 { fill: var(--N900-FG, 0.15); }#wkTBAGocxtaM .fb1 {fill: rgba(31,35,41, 0.15)}#wkTBAGocxtaM .fb2 { fill: rgb(201, 212, 230); }#wkTBAGocxtaM .fb2 {fill: rgb(201, 212, 230)}#wkTBAGocxtaM .fa4 { fill: var(--bg-body); }#wkTBAGocxtaM .fa4 {fill: #fff}AB1234目录用途workspace/sessions/my-plugin/agent 干活的地方:放一个仓库的克隆(或把现有项目复制进来)会话日志(JSONL),出事可回放你的插件项目

​

​

安全约定:workspace 必须是"弄坏了也不心疼"的副本。dsh 的 agent 会真实改文件。​

​

13.3 插件:weekly_report 工具​

创建 my-plugin/src/weekly.ts:​

​

代码块​

Plain Text

import type { Context } from '@deepseek-ai/cordis'​

import { defineTool } from '@deepseek-ai/dsh-tools'​

import Schema from '@deepseek-ai/schemastery'​

​

export const name = 'weekly-report'​

export const inject = ['tools']​

​

export interface Config {​

author: string​

repoName: string​

outputDir: string​

}​

​

export const Config: Schema = Schema.object({​

author: Schema.string().required(),​

repoName: Schema.string().required(),​

outputDir: Schema.string().required(),​

})​

​

注意两点:​

•

这个工具的 execute 是纯函数:它把结构化数据渲染成 Markdown,不做任何危险操作。收集数据的脏活(跑 git log、统计文件)交给模型用自己的 bash 工具完成——职责分离,插件更安全、更容易测试;​

•

Config 走的是第 7 章约定:可调参数全部可配置,不硬编码。​

13.4 加载与调试​

创建 my-plugin/cordis.yml(路径换成你的绝对路径):​

​

代码块​

Plain Text

- insert:​

- id: weekly​

name: '/absolute/path/to/agent-workbench/my-plugin/src/weekly.ts'​

config:​

author: '你的名字'​

repoName: 'my-project'​

outputDir: '/absolute/path/to/agent-workbench/reports'​

​

先看配置树,再启动:​

​

代码块​

Plain Text

pnpm dsh web --patch ./my-plugin/cordis.yml --dump-config​

​

在 Web UI 里发这样一个任务:​

​

代码块​

Plain Text

Inspect the workspace repo. Run git log --oneline -20 to see recent commits,​

then use the weekly_report tool with the last week's data and save the result​

to the configured output directory.​

​

模型会自己跑 git、整理数据、调用 weekly_report。打开报告目录,你的第一份 Agent 生成的周报就在那了。​

13.5 打包进专属 profile​

临时 --patch 只适合调试。把它转成 bundle,装进一个叫 workbench 的 profile:​

my-plugin/package.json:​

​

代码块​

Plain Text

​

​

main 指向的是编译后的 JS 产物(用 tsc/tsdown 从 weekly.ts 构建),示例中为简洁省略了构建步骤;开发期直接走 --patch 加载 TS 源码即可。​

​

cordis.patch.yml 里的插件行改成按包名引用:​

​

代码块​

Plain Text

- insert:​

- id: weekly​

name: dsh-weekly-report​

​

安装并验证:​

​

代码块​

Plain Text

dsh plugin --profile workbench add ./my-plugin​

dsh --profile workbench --dump-config​

dsh --profile workbench​

​

以后 dsh --profile workbench 就是你的"工作台"——自带周报能力。​

13.6 Python 调度脚本:每天自动跑​

agent-workbench/run_daily.py:​

​

代码块​

Plain Text

​

然后用系统的定时任务(macOS launchd、Linux cron、Windows 计划任务)每天早晨执行:​

​

代码块​

Plain Text

0 9 * * * cd /absolute/path/to/agent-workbench && /path/to/python run_daily.py >> daily.log 2>&1​

​

三个约定再强调一次:​

•

每天用新的 session id(daily-2026-08-16 这种),任务之间状态不串;​

•

cwd 指向 workspace,session_root 指向 sessions,日志归档留痕;​

•

完整路径写绝对路径,定时任务的工作目录不可依赖。​

13.7 安全与生产化清单​

•

workspace 用副本,出问题随时重建;​

•

锁版本:dsh 固定版本,升级先看官方 Release;​

•

Key 走环境变量(DEEPSEEK_API_KEY),绝不写进代码或 git;​

•

想更严:给 profile 换非 danger-full-access 的沙箱策略(参考 docs/subsystems/sandbox.md);​

•

日志定期归档:sessions/ 和 reports/ 挂进备份。​

13.8 下一步扩展​

•

加检索:按第 10 章案例 C 的思路加 search_docs 工具;​

•

加定时:参考官方 examples/web-schedule,把任务接进 dsh 自己的调度;​

•

加多 Agent:研究 docs/subsystems/subagent.md,让主 agent 委派子任务;​

•

发布分享:把这个 bundle 发布到 npm,别人 dsh plugin add dsh-weekly-report 就能装。​

13.9 本章小结​

•

插件只做"渲染"这类纯逻辑,数据收集交给模型的工具,安全又易测;​

•

--patch 调试 → bundle + profile 固化,是插件进生产的标准路径;​

•

无头 + Python SDK + 系统定时任务 = 每天自动干活的 Agent;​

•

固定 session id 的规则、绝对路径、隔离 workspace,是三条保命铁律。​

到这里,你已经有能力搭建属于自己的 Agent 工作台了。附录里的命令速查和术语表,随时回来翻。​