ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

DeepSeek Harness 震撼发布!一切皆插件的 AI Agent 框架,附 10 分钟上手 Demo

DeepSeek Harness 震撼发布!一切皆插件的 AI Agent 框架,附 10 分钟上手 Demo 导读2026 年 8 月 13 日DeepSeek 正式开源 DeepSeek Harness v0.1主打一切皆插件架构MIT 协议完全开源。本文带你 10 分钟上手手写第一个 AI Agent 插件为什么 DeepSeek Harness 值得关注在 AI Agent 框架百花齐放的 2026 年DeepSeek Harness 凭什么出圈特性DeepSeek HarnessLangGraphCrewAI架构模式插件化图工作流角色协作热插拔✅ 支持❌ 不支持❌ 不支持开源协议MITMITMIT多模型✅ 原生支持✅✅国产化✅❌❌学习成本中高低核心优势一切皆插件——模型、工具、技能、UI、沙箱全部插件化自由组合、替换、扩展 快速开始10 分钟上手 Demo环境准备# Node.js 版本要求 18.0node-v# 建议 v20# 克隆仓库gitclone https://github.com/deepseek-ai/deepseek-harness.gitcddeepseek-harness# 安装依赖npminstall# 构建核心npmrun build项目结构速览deepseek-harness/ ├── packages/ │ ├── core/ # 核心框架Cordis 元框架 │ ├── plugins/ # 官方插件 │ │ ├── model/ # 模型插件 │ │ ├── tool/ # 工具插件 │ │ └── ui/ # UI 插件 │ └── examples/ # 示例代码 ├── docs/ # 文档 └── package.json 实战手写第一个插件场景开发一个「天气查询」工具插件我们要创建一个简单的 AI Agent 插件让 AI 能够查询天气信息。Step 1创建插件项目# 创建插件目录mkdirweather-plugincdweather-plugin# 初始化 npm 项目npminit-y# 安装 Harness 核心依赖npminstalldeepseek-harness/coreStep 2编写插件代码创建src/weather-plugin.ts// src/weather-plugin.tsimport{Plugin,definePlugin}fromdeepseek-harness/core;// 定义插件配置接口interfaceWeatherPluginConfig{apiKey:string;defaultCity:string;}// 定义插件exportconstweatherPlugindefinePluginWeatherPluginConfig({name:weather-query,version:1.0.0,description:天气查询工具插件,// 插件激活时的初始化asyncsetup(config){console.log([Weather] 插件已激活默认城市${config.defaultCity});return{currentCity:config.defaultCity,apiKey:config.apiKey,};},// 插件提供的工具函数tools:{// 查询天气asyncgetWeather(ctx,city?:string){conststatectx.getPluginStateReturnTypetypeofthis.setup();consttargetCitycity||state.currentCity;// 模拟天气数据实际使用需调用 APIconstweatherData{city:targetCity,temperature:Math.floor(Math.random()*35)°C,condition:[晴,多云,小雨,阴天][Math.floor(Math.random()*4)],humidity:Math.floor(Math.random()*100)%,};return{success:true,data:weatherData,};},// 设置默认城市asyncsetDefaultCity(ctx,city:string){conststatectx.getPluginStateReturnTypetypeofthis.setup();state.currentCitycity;return{success:true,message:默认城市已设置为${city},};},},// 插件销毁时的清理asyncteardown(){console.log([Weather] 插件已卸载);},});exportdefaultweatherPlugin;Step 3创建插件入口创建src/index.ts// src/index.tsexport{weatherPlugin}from./weather-plugin;exporttype{WeatherPluginConfig}from./weather-plugin;Step 4编译插件创建tsconfig.json{compilerOptions:{target:ES2020,module:commonjs,lib:[ES2020],declaration:true,outDir:./dist,rootDir:./src,strict:true,esModuleInterop:true,skipLibCheck:true},include:[src/**/*],exclude:[node_modules,dist]}编译npx tscStep 5在 Harness 中注册插件创建src/app.ts主程序// src/app.tsimport{Harness}fromdeepseek-harness/core;import{weatherPlugin}from./weather-plugin;asyncfunctionmain(){// 创建 Harness 实例constharnessnewHarness({name:my-first-agent,version:1.0.0,});// 注册天气插件awaitharness.registerPlugin(weatherPlugin,{apiKey:your-api-key-here,// 实际使用需申请天气 APIdefaultCity:北京,});console.log(✅ Harness 启动成功);// 获取插件实例constweatherharness.getPlugin(weather-query);// 调用插件工具constresultawaitweather.tools.getWeather(null,上海);console.log(️ 天气查询结果:,result);// 设置默认城市awaitweather.tools.setDefaultCity(null,广州);// 再次查询使用默认城市constresult2awaitweather.tools.getWeather(null);console.log(️ 默认城市天气:,result2);}main().catch(console.error);Step 6运行 Demo# 编译主程序npx tsc src/app.ts--outDirdist# 运行nodedist/app.js预期输出[Weather] 插件已激活默认城市北京 ✅ Harness 启动成功 ️ 天气查询结果{ success: true, data: { city: 上海, temperature: 28°C, condition: 多云, humidity: 65% } } ️ 默认城市天气{ success: true, data: { city: 广州, temperature: 32°C, condition: 晴, humidity: 80% } } [Weather] 插件已卸载进阶多插件协作示例Harness 的强大之处在于插件自由组合。下面演示模型插件 工具插件的协作。完整示例AI 天气助手// src/ai-weather-agent.tsimport{Harness}fromdeepseek-harness/core;import{deepSeekModelPlugin}fromdeepseek-harness/model-deepseek;import{weatherPlugin}from./weather-plugin;asyncfunctionmain(){constharnessnewHarness({name:ai-weather-agent,version:1.0.0,});// 注册模型插件awaitharness.registerPlugin(deepSeekModelPlugin,{apiKey:process.env.DEEPSEEK_API_KEY,model:deepseek-chat,});// 注册天气插件awaitharness.registerPlugin(weatherPlugin,{apiKey:your-weather-api-key,defaultCity:北京,});// 获取插件constmodelharness.getPlugin(deepseek-model);constweatherharness.getPlugin(weather-query);// 用户输入constuserInput帮我查一下上海的天气然后用一句话总结;// 第一步让 AI 理解意图constintentawaitmodel.tools.chat({messages:[{role:user,content:userInput}],tools:[weather-query.getWeather],// 告知可用工具});// 第二步调用天气插件if(intent.toolCalls?.[0]?.namegetWeather){constweatherResultawaitweather.tools.getWeather(null,intent.toolCalls[0].args.city||上海);// 第三步让 AI 总结constsummaryawaitmodel.tools.chat({messages:[{role:user,content:userInput},{role:assistant,toolCalls:intent.toolCalls},{role:tool,content:JSON.stringify(weatherResult.data)},],});console.log( AI 总结:,summary.content);}}main().catch(console.error);运行效果 AI 总结上海今天多云气温 28°C湿度 65%适合外出活动。 插件类型大全DeepSeek Harness 支持多种插件类型下面是常见插件的开发模板1. 模型插件exportconstmyModelPlugindefinePlugin({name:my-model,tools:{asyncchat(ctx,messages:Message[]){// 调用 LLM APIreturnawaitcallLLM(messages);},},});2. 工具插件exportconstfilePlugindefinePlugin({name:file-operations,tools:{asyncreadFile(ctx,path:string){returnawaitfs.promises.readFile(path,utf-8);},asyncwriteFile(ctx,path:string,content:string){awaitfs.promises.writeFile(path,content);return{success:true};},},});3. UI 插件exportconstcliUiPlugindefinePlugin({name:cli-ui,hooks:{onOutput(output){console.log( 输出:,output);},},});4. 沙箱插件exportconstdockerSandboxPlugindefinePlugin({name:docker-sandbox,tools:{asyncexecute(ctx,code:string,language:string){// 在 Docker 容器中执行代码returnawaitdocker.run(code,language);},},}); 发布你的插件到 NPM# 完善 package.jsonnpmpkgsetkeywordsdeepseek-harness,plugin,ai-agentnpmpkgsetrepository.githubyour-username/your-plugin# 测试npmpack# 发布npmpublish--accesspublic发布后其他人可以npminstallyour-weather-plugin然后在 Harness 中使用import{weatherPlugin}fromyour-weather-plugin;awaitharness.registerPlugin(weatherPlugin,config); 实际应用场景场景 1AI 代码助手// 组合模型 文件 沙箱 代码审查插件harness.registerPlugin(deepSeekModelPlugin);harness.registerPlugin(filePlugin);harness.registerPlugin(dockerSandboxPlugin);harness.registerPlugin(codeReviewPlugin);// AI 可以读写文件 → 生成代码 → 沙箱运行 → 自动审查场景 2自动化测试 Agent// 组合模型 浏览器 测试 报告插件harness.registerPlugin(deepSeekModelPlugin);harness.registerPlugin(playwrightPlugin);harness.registerPlugin(testGeneratorPlugin);harness.registerPlugin(reportPlugin);// AI 可以分析需求 → 生成测试 → 执行 → 输出报告场景 3数据分析助手// 组合模型 SQL 可视化 报告插件harness.registerPlugin(deepSeekModelPlugin);harness.registerPlugin(sqlPlugin);harness.registerPlugin(chartPlugin);harness.registerPlugin(reportPlugin);// AI 可以理解问题 → 查询数据 → 生成图表 → 输出分析⚠️ 注意事项事项说明版本兼容性v0.1 预览版API 可能变动生产环境暂不建议用于生产等待 v1.0文档完善度部分文档仍在补充中社区支持新框架遇到问题需自行探索资源链接资源链接GitHub 仓库https://github.com/deepseek-ai/deepseek-harness官方文档https://github.com/deepseek-ai/deepseek-harness/blob/master/docs/development.zh.mdAwesome 资源https://github.com/0xsline/awesome-deepseek-harness本文 Demo 代码可关注公众号回复harness获取写在最后deepseek Harness本质上主要是适用于前端 JS/TS的AI开发框架方便统一管理插件并不能直接应用于 Java/Python/Golang 乃至于客户端app的Android, IOS 鸿蒙开发等
返回列表