QP内容库 Logo
首页
文章
文档
默认分类
关于
登录 →
QP内容库 Logo
首页 文章
文档
默认分类 关于
登录
  1. 首页
  2. 文档
  3. DeepSeek Harness
  4. 用户指南
  5. 开发
  6. 基础
  7. 开发一个工具

开发一个工具

  • 基础
  • 发布于 2026-09-30
  • 0 次阅读
目录
当前文章没有目录

English | 中文

本教程会在 Web UI 中添加一个 greet 工具。请先完成第一个插件,并保留其中的 scratch-plugin 目录。

创建工具插件

将 scratch-plugin/src/my-plugin.ts 替换为:

import type { Context } from '@deepseek-ai/cordis'
import { defineTool } from '@deepseek-ai/dsh-tools'

export const name = 'greet-tool'
export const inject = ['tools']

export function apply(ctx: Context) {
  ctx.tools.register(defineTool({
    name: 'greet',
    description: 'Greet someone by name.',
    parameters: {
      name: { type: 'string', required: true, description: 'The name to greet' },
    },
    output: {
      schema: { type: 'string' },
      render: (_args, value) => [{ type: 'text', text: value }],
    },
    async execute(args) {
      return `Hello, ${args.name}!`
    },
  }))
}

inject 让 Cordis 等待工具注册表就绪。defineTool 根据 parameters 推导并校验 args;execute 返回 output.schema 声明的规范值,output.render 再将该值转换为面向模型的内容。

运行并调用工具

如果开发命令未在运行,请重新启动:

pnpm dsh web --patch ./scratch-plugin/cordis.yml

打开 http://127.0.0.1:3080,然后输入:Use the greet tool to greet Ada. 模型可以调用 greet,并收到 Hello, Ada! 这一工具结果。

下一步

  • 插件配置 — 让问候语可配置。
  • 工具编写参考 — 查阅嵌套 schema、规范值、后台工作、策略钩子、PTC mode 和 UI 卡片。
  • 能力分层 — 将可替换能力拆分为 Service Definition、Service Provider 和 Consumer 三类包。
相关文章

开发一个工具

English | 中文 本教程会在 Web UI 中添加一个 greet 工具。请先完成第一个插件,并保留其中的 scratch-plugin 目录。 创建工具插件 将 scratch-plugin/src/my-plugin.ts 替换为: import type { Context } fro

打包与安装插件

English | 中文 前几篇教程通过 --patch overlay 加载本地插件。本教程把它打包成可安装的组合包(bundle),用 dsh plugin add 安装进一个 profile,并解释决定组合后配置的层顺序。本文假设 dsh CLI 已安装。请先完成插件配置。 如果改用全新的源码

第一个插件

English | 中文 本教程会创建一个最小的 Harness 插件,并将其加载到 Web UI 中。请从已完成从源码运行路径的仓库检出开始。 创建本地项目 在仓库根目录创建本教程使用的临时项目: mkdir -p scratch-plugin/src 插件是什么 在 Harness 中,插件是

插件配置

English | 中文 让你的插件接受用户在 cordis.yml 中传入的配置。 定义 Config 类型 在插件中导出一个 Config 类型和同名的 Schemastery schema;默认值直接写在 schema 中: import type { Context } from '@dee

目录
当前文章没有目录

星沉月落夜闻香,素手出锋芒。

Copyright © 2026 quping.com All Rights Reserved. Powered by Halo.
鲁ICP备09092435号