DSH利用插件SystemPrompt将自己注册为服务服务名为systemPrompt来以类似于Builder模式来渲染系统提示词我们可以将此服务作为Builder通过提供相应配置注册构成最终系统提示词的相关元素PromptSection和PromptContext并同时提供描述有序工具的Schema。本篇以实例演示的方式来介绍如何利用SystemPrompt来生成我们希望的系统提示词。1. 默认的提示词如下的演示程序体现了默认提示的内容。如代码所示我们通过注入systemPrompt服务注册了一个测试插件并在其中调用ctx.systemPrompt的assemble方法组装了一个PromptAssembly对象并以此为参数调用了renderPrompt函数将其渲染成一个提示词文本并输出。import{Context}fromdeepseek-ai/cordisimport{SystemPrompt,renderPrompt}fromdeepseek-ai/dsh-system-promptconstctxnewContext()ctx.plugin(SystemPrompt)constfiberctx.inject([systemPrompt],asyncctx{constassembleawaitctx.systemPrompt.assemble()console.log(renderPrompt(assemble))})awaitfiber.await()输出You are an AI agent powered by DeepSeek Harness.上面输出的这段提示词文本被称为DeepSeek Harness身份标识默认会称为系统提示词的组成部分。assemble方法返回PromptAssembly可以视为SystemPrompt的核心输出对应接口定义如下exportinterfacePromptAssembly{sections:AssembledSection[]contexts:AssembledContext[]tools:ToolSchema[]variables:Recordstring,string|undefined}四个字段说明如下sections系统提示词的正文片段已求值但未插值按order排序最终由renderPrompt插值、过滤、拼接成提示词字符串contexts动态运行时上下文快照已求值但未插值按order排序最终渲染成用户消息插入模型历史tools面向模型的工具Schema列表已结构化、已按toolOrder排序不做文本渲染直接作为LLM API的tools参数传入variables变量名到值的扁平映射已求值仅作为sections和contexts插值时的查表来源。2. 为SystemPrompt服务提供配置SystemPrompt插件具有如下这个Config接口表示的配置我们可以在注册此插件时这利用它对系统提示词的组装行为进行定制。exportinterfaceConfig{includeHarnessIdentity?:booleanincludeRuntimeContext?:booleanpersonaPrefix?:stringpersonaSuffix?:stringtoolOrder?:string[]}五个配置选项说明如下includeHarnessIdentity是否在部署persona为LLM设置的人设之前插入固定的 DeepSeek Harness 身份标识默认为true。如果部署方想完全自定义身份、不暴露 Harness 品牌可设为falseincludeRuntimeContext是否把动态运行时上下文快照时间、环境、用户信息等注入到模型历史中默认为truepersonaPrefix部署级的persona前缀模板插在第一方指导语之前默认为空字符串personaSuffix部署级的persona后缀模板插在第一方指导语之后默认为空字符串toolOrder指定面向模型的工具名顺序省略则按字典序排列。我们在上面演示程序的基础上在调用ctx.plugin方法注册SystemPrompt插件的同时提供了一个定制的Config对象并设置了作为人设的personaPrefix和personaSuffix。import{Context}fromdeepseek-ai/cordisimport{SystemPrompt,renderPrompt,Config}fromdeepseek-ai/dsh-system-promptconstconfig:Config{personaPrefix:你是一个皆具时尚敏感度有深谙养生之道的个人助理。,personaSuffix:全程使用中文回答问题。}constctxnewContext()ctx.plugin(SystemPrompt,config)constfiberctx.inject([systemPrompt],asyncctx{constassembleawaitctx.systemPrompt.assemble()console.log(renderPrompt(assemble))})awaitfiber.await()输出You are an AI agent powered by DeepSeek Harness. 你是一个皆具时尚敏感度有深谙养生之道的个人助理。 全程使用中文回答问题。由于这两个配置最终会转换成AssembledSection出现在PromptAssembly的sections字段中所以调用renderPrompt函数渲染注册来系统提示词文本会包含它们的内容。3. 注册一组有序的“章节”PromptAssembly的sections返回的PromptSection列表是系统提示词的核心组成部分我们可以调用SystemPrompt的section方法对此进行注册。exportclassSystemPromptextendsService{section(section:PromptSection):()void}exportinterfacePromptSection{readonlyname:stringreadonlyorder:numberreadonlytext:string|((context:AssembleContext)string)readonlycomplete?:boolean}exportinterfaceAssembleContext{scope?:ScopeKey signal?:AbortSignal}name唯一标识同层重复注册报错作用域同名遮蔽全局order拼接顺序升序text正文静态字符串或按AssembleContext求值的函数complete标记排他性完整提示词整个PromptSection列表中最多只能出现一个。如果出现只会使用这个唯一的PromptSection。在上面演示程序的基础上我们调用了section方法注册了两个PromptSection并刻意以注册的相反的顺序设置了它的order字段。import{Context}fromdeepseek-ai/cordisimport{SystemPrompt,renderPrompt,Config}fromdeepseek-ai/dsh-system-promptconstconfig:Config{personaPrefix:你是一个皆具时尚敏感度有深谙养生之道的个人助理。,personaSuffix:全程使用中文回答问题。}constctxnewContext()ctx.plugin(SystemPrompt,config)constfiberctx.inject([systemPrompt],asyncctx{constdisposables:(()void)[][]disposables.push(ctx.systemPrompt.section({name:requirement-focus,text:对于用户提出的问题应该尽量分析他/她的最终需求并针对需求回答问题。,order:2}))disposables.push(ctx.systemPrompt.section({name:concise,text:回答问题尽可能简洁不要啰嗦。,order:1}))constassembleawaitctx.systemPrompt.assemble()console.log(renderPrompt(assemble))return()disposables.forEach(disposedispose())})awaitfiber.await()输出You are an AI agent powered by DeepSeek Harness. 你是一个皆具时尚敏感度有深谙养生之道的个人助理。 回答问题尽可能简洁不要啰嗦。 对于用户提出的问题应该尽量分析他/她的最终需求并针对需求回答问题。 全程使用中文回答问题。4. 注册一组有序的动态上下文SystemPrompt的context方法用来注册一条动态运行时上下文返回一个。注册的内容最终会作为运行时快照消息插入模型历史并不是以进入系统提示词文本的形式出现的。exportclassSystemPromptextendsService{context(context:PromptContext):()void}exportinterfacePromptContext{readonlyname:stringreadonlyorder:numberreadonlytext:string|((context:AssembleContext)string)}PromptContext定义更为简单相较于PromptSection少了complete字段。我们在上面演示程序的基础上调用context方法注册了一个名为current-date提供了当前的日期。由于renderPrompt函数仅仅用来渲染系统提示词文本所以我们需要利用renderContextSnapshot函数以上下文快照的形式进行渲染。import{Context}fromdeepseek-ai/cordisimport{SystemPrompt,renderPrompt,renderContextSnapshot,Config}fromdeepseek-ai/dsh-system-promptconstconfig:Config{personaPrefix:你是一个皆具时尚敏感度有深谙养生之道的个人助理。,personaSuffix:全程使用中文回答问题。,includeRuntimeContext:true}constctxnewContext()ctx.plugin(SystemPrompt,config)constfiberctx.inject([systemPrompt],asyncctx{constdisposables:(()void)[][]...disposables.push(ctx.systemPrompt.context({name:current-date,text:_当前日期为${newDate()},order:1}))constassembleawaitctx.systemPrompt.assemble()console.log(renderPrompt(assemble))console.log(renderContextSnapshot(assemble))return()disposables.forEach(disposedispose())})awaitfiber.await()输出你是一个皆具时尚敏感度有深谙养生之道的个人助理。 回答问题尽可能简洁不要啰嗦。 对于用户提出的问题应该尽量分析他/她的最终需求并针对需求回答问题。 全程使用中文回答问题。 Current runtime context. This snapshot supersedes earlier runtime-context snapshots. 当前日期为Sat Sep 26 2026 06:53:02 GMT0800 (China Standard Time)5. 提供工具SchemaSystemPrompt的tools方法用来注册工具的Schema它的参数是一个根据指定的AssembleContext用来提供ToolProviderResult的函数。ToolProviderResult接口包含两个字段schemas提供一组描述工具的SchemaknownNames提供有已知的工具名称。exportclassSystemPromptextendsService{tools(provider:(context:AssembleContext)ToolProviderResult):()void}exportinterfaceToolProviderResult{readonlyschemas:readonlyToolSchema[]readonlyknownNames?:readonlystring[]}DeepSeek Harness深度拆解-12:揭秘工具完整的执行流程对工具执行流程进行了详细介绍但依然漏掉很多细节比如在作为工具运行时ToolRuntime的构造函数中会将注册工具基于当前Scope的Schema和名称列表生成一个ToolProviderResult对象并通过调用tools方法注册到SystemPrompt服务上。exportclassToolRuntimeextendsService{constructor(ctx:Context,config:Config{}){...ctx.systemPrompt.tools(contextthis.wireSchemas(context.scope))...}privatewireSchemas(scope?:ScopeKey):ToolProviderResult}我们在上面演示实例的基础上进一步以如下的方式调用tools方法注册了一个get_weather工具对应的ToolProviderResult我们指定了工具描述和参数Schema。import{Context}fromdeepseek-ai/cordisimport{SystemPrompt,ToolProviderResult,renderPrompt,renderContextSnapshot,Config}fromdeepseek-ai/dsh-system-promptconstconfig:Config{personaPrefix:你是一个皆具时尚敏感度有深谙养生之道的个人助理。,personaSuffix:全程使用中文回答问题。,includeRuntimeContext:true}constctxnewContext()ctx.plugin(SystemPrompt,config)constfiberctx.inject([systemPrompt],asyncctx{constdisposables:(()void)[][]...consttoolProvider:ToolProviderResult{knownNames:[get_weather],schemas:[{name:get_weather,description:Get specified citys weather information.,parameters:{city:{type:string,description:The city to look up weather for.},}}]asconst}disposables.push(ctx.systemPrompt.tools(_toolProvider))constassembleawaitctx.systemPrompt.assemble()console.log(renderPrompt(assemble))console.log(renderContextSnapshot(assemble))console.log(\nassemble.tools:)console.log(JSON.stringify(assemble.tools,null,2))return()disposables.forEach(disposedispose())})awaitfiber.await()输出You are an AI agent powered by DeepSeek Harness. 你是一个皆具时尚敏感度有深谙养生之道的个人助理。 回答问题尽可能简洁不要啰嗦。 对于用户提出的问题应该尽量分析他/她的最终需求并针对需求回答问题。 全程使用中文回答问题。 Current runtime context. This snapshot supersedes earlier runtime-context snapshots. 当前日期为Sat Sep 26 2026 08:38:16 GMT0800 (China Standard Time) assemble.tools: [ { name: get_weather, description: Get specified citys weather information., parameters: { city: { type: string, description: The city to look up weather for. } } } ]6. 使用变量在Agent开发中提示词一般以模板的形式定义也就是说我们将提示词文本内容包括PromptSection和PromptContext的text字段定义成包含占位符的模板在渲染的时候利用指定的变量对占位符进行替换。SystemPrompt提供了用来定义变量的variable方法具体的变量由指定的将AssembleContext作为输入的函数来提供。exportclassSystemPromptextendsService{variable(name:string,provider:(context:AssembleContext)string|undefined):()void}在如下的演示程序中我们将Config的personaPrefix设置成一个包含占位符{{persona}}的模板对应的变量在注册的插件中通过调用ctx.systemPrompt.variable方法定义。import{Context}fromdeepseek-ai/cordisimport{SystemPrompt,renderPrompt,Config}fromdeepseek-ai/dsh-system-promptconstconfig:Config{personaPrefix:你是一个{{persona}}。,personaSuffix:全程使用中文回答问题。,includeRuntimeContext:true}constctxnewContext()ctx.plugin(SystemPrompt,config)constfiberctx.inject([systemPrompt],asyncctx{constdisposables:(()void)[][]ctx.systemPrompt.variable(persona,_皆具时尚敏感度有深谙养生之道的个人助理)constassembleawaitctx.systemPrompt.assemble()console.log(renderPrompt(assemble))return()disposables.forEach(disposedispose())})awaitfiber.await()输出You are an AI agent powered by DeepSeek Harness. 你是一个皆具时尚敏感度有深谙养生之道的个人助理。 全程使用中文回答问题。7. 基于Scope的注册SystemPrompt被注册为一个全局单例服务它基于Scope的注册体现在如下两个方面方法(section、context、tools和variable等)注册的元素于当前Context所在的Scope关联并由此具有作用范围比如针对具体的AgentPromptSection、PromptContext的text字段以及variable方法注册的变量可以是一段静态文本也可以是一个将AssembleContext作为输入的函数意味着对应的值可以根据当前Scope动态决定。SystemPrompt的assemble方法也提供了context参数我们有利用它指定具体的ScopeKey获取指定范围的PromptAssemble对象。exportclassSystemPromptextendsService{asyncassemble(context:AssembleContext{})}上述的基于Scope的提示词注册清晰地体现在如下这个演示程序中。如代码所示我们将配置的personaPrefix字段设置为一个包含{{persona}}占位符的模板。在调用inject方法以systemPrompt作为依赖服务的插件中我们调用createScope函数创建两个Scope分别模拟两个分别用来安排交通行程和酒店住宿的Agent。我们调用ctx.systemPrompt.variable方法根据AssembleContext提供的Scope动态执行persona变量的值。并在这两个Scope对用的Context中通过注册了同名authorization的PromptSection。最后我们将注册的内嵌插件中针对两个Scope生成了对应的PromptAssemble并将渲染的文本输出来。import{Context}fromdeepseek-ai/cordisimport{createScope,}fromdeepseek-ai/dsh-scopeimport{SystemPrompt,renderPrompt}fromdeepseek-ai/dsh-system-promptconstctxnewContext()ctx.plugin(SystemPrompt,{personaPrefix:你是一个{{persona}}。})consttransport_assistant{agent:transport assistant}constaccommodation_assistant{agent:accommodation assistant}ctx.inject([systemPrompt],ctx{ctx.systemPrompt.variable(persona,context{if(transport_assistantcontext.scope){return专门负责交通行程安排的助理}if(accommodation_assistantcontext.scope){return专门住宿安排的助理}return资深个人助理})consttransport_assistant_scopecreateScope(ctx,transport_assistant)constaccommodation_assistant_scopecreateScope(ctx,accommodation_assistant)transport_assistant_scope.ctx.systemPrompt.section({name:authorization,text:授予你自动下单购买机票的权限,order:1})accommodation_assistant_scope.ctx.systemPrompt.section({name:authorization,text:授予你自动预定酒店的权限,order:1})ctx.inject([systemPrompt],asyncctx{letassembleawaitctx.systemPrompt.assemble({scope:transport_assistant})console.log(For transport assistant:\n\n${renderPrompt(assemble)})assembleawaitctx.systemPrompt.assemble({scope:accommodation_assistant})console.log(For accommodation assistant:\n\n${renderPrompt(assemble)})})})输出For transport assistant: You are an AI agent powered by DeepSeek Harness. 你是一个专门负责交通行程安排的助理。 授予你自动下单购买机票的权限 For accommodation assistant: You are an AI agent powered by DeepSeek Harness. 你是一个专门住宿安排的助理。 授予你自动预定酒店的权限
企业数字化 ERP 产品动态
相关推荐
一个美工做网站好做吗:5年实战对比评测揭秘效率陷阱 一个美工做网站好做吗:5年实战对比评测揭秘效率陷阱 改个需求建站公司拖一周,这种憋屈感谁懂?很多前端初学者或转行的美工朋友,手里拿着设计稿,心里却发虚: 一个美工做网站好做吗… · 2026/9/27 15:10:05
用了一下国产免费 AI 代码补全工具,真不错!TaoToken 统一 Key 接入 Cline 实测 /* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/9/27 15:09:59
深圳建设网站费用全解析:避坑指南与安全防护实操 深圳建设网站费用全解析:避坑指南与安全防护实操 在深圳做网站,最怕的不是钱不够,而是钱花了,站没建好,甚至还没上线就被黑了。找建站公司怕被坑高价,这不仅是预算问题,更是安全红线。很多老板以为“深圳建设网站费用”只包含设计和代码,其实… · 2026/9/27 15:09:52
新手入门怎么给网站开发后台?3步搞定防黑与高转化 新手入门怎么给网站开发后台?3步搞定防黑与高转化 网站被黑挂马,首页变黄图,客户投诉电话打爆,你甚至不知道后门在哪里?别慌,这不是你代码写得烂,而是你缺一个能“看家护院”又“招财进宝”的后台。很多新手入门建站,只盯着前端页面好不好看,却忽略… · 2026/9/27 16:54:09
上海网络维护有哪些公司?2026避坑指南 上海网络维护有哪些公司?2026避坑指南 别再盯着那些一眼假的模板网站了。 如果你的官网打开速度慢、手机端排版乱、后台像上世纪的产物,那真的该换脑子了。 很多老板问我,上海做网络维护的公司到底哪家强? 说实话,这行水很深,坑更多。… · 2026/9/27 16:53:57
wordpress4.3撰写设置详解 建站成本多少钱才不踩坑 wordpress4.3撰写设置详解 建站成本多少钱才不踩坑 备案流程一头雾水,是不是让你对着后台发愣?很多刚起步的站长,光搞懂ICP备案就要折腾半个月,更别提还要算清建站到底 多少钱 才不亏。其实,WordPress 4.3… · 2026/9/27 16:53:51
彻底卸载OpenClaw:完整指南与TaoToken配置残留清理 /* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/9/27 16:53:44
收藏!从0到领跑:DeepSeek大模型技术演进全拆解,TaoToken统一API通道配置实战 /* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/9/27 16:53:20
MATLAB雷达信号脉冲压缩仿真:LFM线性调频、匹配滤波与距离分辨率实现 简介:这套Matlab仿真工具完整呈现雷达信号脉冲压缩过程,从线性调频(LFM)信号生成、目标回波仿真到匹配滤波压缩处理均有可运行代码支撑,面向电子信息工程、计算机、数学等专业学生,适用于课程设计、期末大作… · 2026/9/27 0:00:01
汕头网站建设制作厂家避坑指南:5大注意事项救急 汕头网站建设制作厂家避坑指南:5大注意事项救急 改个需求建站公司拖一周,这种憋屈事我见得太多了。 很多汕头老板找本地建站团队,签合同前看着方案挺美,一上线就变脸。 今天不聊虚的,直接拆解找 汕头网站建设制作厂家 时的5个核心 注意事项… · 2026/9/27 0:00:01
多模态虚假新闻检测实战:BERT+ResNet双塔与对比学习 简介:基于PyTorch的多模态虚假新闻检测项目完整代码包,面向自然语言处理与计算机视觉交叉方向的开发者、科研人员及毕业设计选题者,解决社交媒体中文本与图像联合识别虚假新闻的问题。系统以BERT预训练模型提取文本语义特征,以Res… · 2026/9/27 0:00:01
MATLAB雷达信号脉冲压缩仿真:LFM线性调频、匹配滤波与距离分辨率实现 简介:这套Matlab仿真工具完整呈现雷达信号脉冲压缩过程,从线性调频(LFM)信号生成、目标回波仿真到匹配滤波压缩处理均有可运行代码支撑,面向电子信息工程、计算机、数学等专业学生,适用于课程设计、期末大作… · 2026/9/27 0:00:01
汕头网站建设制作厂家避坑指南:5大注意事项救急 汕头网站建设制作厂家避坑指南:5大注意事项救急 改个需求建站公司拖一周,这种憋屈事我见得太多了。 很多汕头老板找本地建站团队,签合同前看着方案挺美,一上线就变脸。 今天不聊虚的,直接拆解找 汕头网站建设制作厂家 时的5个核心 注意事项… · 2026/9/27 0:00:01
多模态虚假新闻检测实战:BERT+ResNet双塔与对比学习 简介:基于PyTorch的多模态虚假新闻检测项目完整代码包,面向自然语言处理与计算机视觉交叉方向的开发者、科研人员及毕业设计选题者,解决社交媒体中文本与图像联合识别虚假新闻的问题。系统以BERT预训练模型提取文本语义特征,以Res… · 2026/9/27 0:00:01