插件
一切皆插件
DeepSeek Harness 的核心理念:每个能力都是插件。学习插件是什么、写第一个插件、注册工具。基于官方开发者指南。
什么是插件?
Harness 插件是导出 apply 函数的 TypeScript 模块。框架加载时调用 apply,传入 ctx(上下文对象),你通过它注册能力:
import type { Context } from '@deepseek-ai/cordis'
export const name = 'my-plugin'
export function apply(ctx: Context) {
// Register capabilities here.
} 通过 ctx 注册的任何东西,插件卸载时都会自动清理。
第一个插件
mkdir -p scratch-plugin/src // scratch-plugin/src/my-plugin.ts
import type { Context } from '@deepseek-ai/cordis'
export const name = 'hello-plugin'
export function apply(ctx: Context) {
console.log('[hello-plugin] plugin loaded!')
} 创建 scratch-plugin/cordis.yml 指向绝对路径,然后用 patch 启动 Web UI:
- insert:
- id: hello
name: '/absolute/path/to/deepseek-harness/scratch-plugin/src/my-plugin.ts' pnpm dsh web --patch ./scratch-plugin/cordis.yml 注册一个工具
用 defineTool 给 Agent 添加可调用的工具:
import { defineTool } from '@deepseek-ai/dsh-tools'
ctx.tools.register(defineTool({
name: 'greet',
description: 'Greet someone by name.',
parameters: { name: { type: 'string', required: true, description: 'The name' } },
output: { schema: { type: 'string' }, render: (_a, v) => [{ type: 'text', text: v }] },
async execute(args) { return `Hello, ${args.name}!` },
})) 社区插件与发布
给仓库加 dsh-plugin 话题加入生态,浏览插件目录(120+ 精选)。