DeepSeek Harness 桌面端来了!带你拆解核心机制
来源: 人人都是产品经理
作者:叶小钗
日期:2026-10-10
基本信息
- 来源类型:网页文章
- 原文位置:raw/articles/2026-10-12-133252-tg-cddfe4.md
- 原文 URL:https://www.woshipm.com/ai/6475794.html
- 消化日期:2026-10-12
核心观点
- DeepSeek Harness(DSH)是 DeepSeek 开源的 AI Agent 框架,核心理念是 Everything is a Plugin,将模型接入、工具、技能、会话、沙箱、存储、任务调度、Agent Loop 等全部功能做成可替换的插件,由 Cordis 统一管理生命周期和服务依赖。
- 插件架构支持高度可组合性:通过配置选择/替换现有插件,或开发自定义插件时遵守接口和生命周期约定。
- 插件类型包括工具插件(提供模型可调用的操作)、模型适配插件(对接不同模型)、服务插件(公共能力)、策略插件(权限/超时控制)、界面插件(UI/展示)、外部系统接入插件等。
- Host 与 Client 插件区分:Host 运行模型/执行命令,Client 处理输入/显示结果。
- Agent Loop 是默认插件,负责任务组织、上下文整理、工具调用等流程。
- 插件开发需在 apply 函数中注册能力,通过 ctx 注入服务,监听事件(如 tools/pre-execute),使用 ctx.effect() 管理资源清理。
实操内容保留
插件开发示例(订单查询插件)
// scratch-order-plugin/src/index.ts
import type { Context } from '@deepseek-ai/cordis';
import Schema from '@deepseek-ai/schemastery';
import { defineTool } from '@deepseek-ai/dsh-tools';
import { orders } from './orders.ts';
export const name = 'order-demo';
export const inject = ['tools'];
export interface Config {
storeName: string;
}
export const Config = Schema.object({
storeName: Schema.string().default('演示商店'),
});
export function apply(ctx: Context, config: Config) {
ctx.tools.register(defineTool({
name: 'lookup_order',
description: '按订单号查询演示商店的模拟订单。只读,不修改订单;查不到时请说明未找到。',
parameters: {
orderId: {
type: 'string',
required: true,
description: '订单号,例如 DS1001。',
},
},
output: {
schema: {
type: 'object',
additionalProperties: false,
properties: {
storeName: { type: 'string', required: true },
orderId: { type: 'string', required: true },
order: {
required: true,
oneOf: [
{ type: 'null' },
{
type: 'object',
additionalProperties: false,
properties: {
orderId: { type: 'string', required: true },
product: { type: 'string', required: true },
status: {
type: 'string',
enum: ['待发货', '已发货', '已取消'],
required: true,
},
trackingNumber: {
required: true,
oneOf: [{ type: 'string' }, { type: 'null' }],
},
},
},
],
},
},
},
render: (_args, value) => [{
type: 'text',
text: value.order === null
? `【模拟数据】${value.storeName}:未找到订单 ${value.orderId},请核对订单号。`
: [
`【模拟数据】${value.storeName}`,
`订单号:${value.order.orderId}`,
`商品:${value.order.product}`,
`状态:${value.order.status}`,
`物流单号:${value.order.trackingNumber ?? '暂无'}`,
].join('\n'),
}],
},
async execute(args) {
const orderId = args.orderId.trim().toUpperCase();
if (orderId.length === 0) {
throw new Error('订单号不能为空,请提供 DS1001 这样的订单号。');
}
return {
storeName: config.storeName,
orderId,
order: orders.find(order => order.orderId === orderId) ?? null,
};
},
}));
console.log(`[order-demo] 已注册 lookup_order,店铺:${config.storeName}`);
}启动与配置
-
在 DeepSeek Harness 源码目录:
cd /path/to/deepseek-harness pnpm install pnpm run build -
创建插件配置:
# scratch-order-plugin/cordis.patch.yml - insert: - id: order-demo name: "/home/your/path/deepseek-harness/scratch-order-plugin/src/index.ts" config: storeName: '演示商店' -
启动:
pnpm dsh web --patch ./scratch-order-plugin/cordis.patch.yml --port 3088 --no-open
创造模式使用
在桌面端选择创造模式,向 Agent 发送提示词:
请帮我开发并安装一个 DSH 订单查询插件,让我能在当前桌面 App 的对话里查询模拟订单。 数据直接保存在本地插件中,不连接外部 API、不使用数据库。准备以下三条虚构数据: – DS1001:机械键盘,已发货,物流单号 DEMO-SF1001。 – DS1002:无线鼠标,待发货,暂无物流单号。 – DS1003:显示器支架,已取消,暂无物流单号。 提供一个名为 lookup_demo_order 的工具,接收订单号,返回商品、状态和物流单号,并标明是模拟数据。忽略订单号两端的空格和字母大小写;查不到就说明未找到,不编造发货或到货时间。
Agent 会自动生成代码,修正后即可使用。
关键概念
- 插件:可替换的模块,包含 apply() 注册能力、inject() 声明依赖、ctx.effect() 管理生命周期。
- Cordis:插件协调器,提供服务依赖、事件通信、资源清理机制。
- Agent Loop:默认任务组织插件,负责模型调用、工具执行、会话记录。
- Host/Client:插件运行环境区分,Host 执行后端,Client 处理前端交互。
与其他素材的关联
本文与 DeepSeek 系列技术文章相关,重点介绍了 Agent 框架的插件化设计,适合开发者快速上手开发自定义 Agent 能力。
原文精彩摘录
“DeepSeek Harness的核心机制, Everything is a Plugin ,也就是把各种功能都做成插件,可以按需替换。我们也可以把自己的业务当成插件一样接入进来,比如查询订单、读取内部数据、调用企业服务等,这样就可以让 Agent 在对话中帮我们处理业务。”
“插件卸载时,清理它注册的能力和资源。 插件运行后,可能注册服务、监听事件,也可能创建定时器或网络连接。 Cordis 会在卸载时撤销纳入生命周期管理的注册,并执行相应的资源清理逻辑。”
本文由人人都是产品经理作者叶小钗原创发布。
相关页面
(暂无)