# Conflicts: # .agents/notes/implemented/architecture/2026-06-11-content-block-vocabulary.i18n.yaml # .agents/notes/implemented/architecture/2026-06-11-content-block-vocabulary.zh.md # .agents/notes/implemented/architecture/2026-06-11-event-sourced-sessions.i18n.yaml # .agents/notes/implemented/architecture/2026-06-11-microkernel-event-taxonomy.i18n.yaml # .agents/notes/implemented/architecture/2026-06-11-microkernel-event-taxonomy.zh.md # .agents/notes/implemented/architecture/2026-06-18-agent-lifecycle-and-ownership-seams.i18n.yaml # .agents/notes/implemented/architecture/2026-06-18-session-surface.i18n.yaml # .agents/notes/implemented/architecture/2026-06-21-bounded-llm-request-recovery.i18n.yaml # .agents/notes/implemented/architecture/2026-06-21-bounded-llm-request-recovery.zh.md # .agents/notes/implemented/architecture/2026-06-30-event-domain-semantics.i18n.yaml # .agents/notes/implemented/architecture/2026-06-30-event-domain-semantics.zh.md # .agents/notes/implemented/architecture/2026-07-05-reconstructable-requests.i18n.yaml # .agents/notes/implemented/architecture/2026-07-05-reconstructable-requests.zh.md # .agents/notes/implemented/architecture/2026-07-10-after-call-compaction-pressure-and-overflow-recovery.i18n.yaml # .agents/notes/implemented/architecture/2026-07-10-after-call-compaction-pressure-and-overflow-recovery.zh.md # .agents/notes/implemented/architecture/2026-07-10-single-file-executable-sdk-runtime-distribution.i18n.yaml # .agents/notes/implemented/architecture/2026-07-10-single-file-executable-sdk-runtime-distribution.zh.md # .agents/notes/implemented/architecture/2026-07-14-provider-routed-llm-adapters.i18n.yaml # .agents/notes/implemented/architecture/2026-07-15-replay-token-meter-service.i18n.yaml # .agents/notes/implemented/architecture/2026-07-16-explicit-turn-cancellation.i18n.yaml # .agents/notes/implemented/architecture/2026-07-22-unified-send-and-coalesced-user-messages.i18n.yaml # .agents/notes/implemented/architecture/2026-07-22-unified-send-and-coalesced-user-messages.zh.md # .agents/notes/implemented/architecture/2026-07-24-separate-context-injection-from-turn-execution.i18n.yaml # .agents/notes/implemented/architecture/2026-07-24-separate-context-injection-from-turn-execution.zh.md # .agents/notes/implemented/architecture/2026-07-25-web-client-session-scope-and-provide-channel.i18n.yaml # .agents/notes/implemented/architecture/2026-07-25-web-client-session-scope-and-provide-channel.zh.md # .agents/notes/implemented/architecture/2026-07-28-identified-immutable-message-values.i18n.yaml # .agents/notes/implemented/bug-fix/2026-07-21-semantic-session-checkpoints.i18n.yaml # .agents/notes/implemented/bug-fix/2026-07-21-semantic-session-checkpoints.zh.md # .agents/notes/implemented/feature/2026-06-18-compaction-capability-seam.i18n.yaml # .agents/notes/implemented/feature/2026-06-18-compaction-capability-seam.zh.md # .agents/notes/implemented/feature/2026-06-24-workspace-context.i18n.yaml # .agents/notes/implemented/feature/2026-06-24-workspace-context.zh.md # .agents/notes/implemented/feature/2026-06-30-hook-bridges.i18n.yaml # .agents/notes/implemented/feature/2026-06-30-hook-protocol-lib.i18n.yaml # .agents/notes/implemented/feature/2026-06-30-hook-protocol-lib.zh.md # .agents/notes/implemented/feature/2026-06-30-interception-seams.i18n.yaml # .agents/notes/implemented/feature/2026-06-30-interception-seams.zh.md # .agents/notes/implemented/feature/2026-07-06-sandbox.i18n.yaml # .agents/notes/implemented/feature/2026-07-06-sandbox.zh.md # .agents/notes/implemented/feature/2026-07-16-durable-per-step-time-context.i18n.yaml # .agents/notes/implemented/feature/2026-07-16-durable-per-step-time-context.zh.md # .agents/notes/implemented/feature/2026-07-16-harness-level-loop.i18n.yaml # .agents/notes/implemented/feature/2026-07-16-harness-level-loop.zh.md # .agents/notes/implemented/feature/2026-07-19-human-goal-command.i18n.yaml # .agents/notes/implemented/feature/2026-07-19-model-facing-goal-tools.i18n.yaml # .agents/notes/implemented/feature/2026-07-19-persisted-same-session-goal-domain.i18n.yaml # .agents/notes/implemented/feature/2026-07-19-persisted-same-session-goal-domain.zh.md # .agents/notes/implemented/feature/2026-07-19-plugin-command-registration.i18n.yaml # .agents/notes/implemented/feature/2026-07-19-same-session-goal-round-driver.i18n.yaml # .agents/notes/implemented/feature/2026-07-19-same-session-goal-round-driver.zh.md # .agents/notes/implemented/feature/2026-07-21-cross-session-references.i18n.yaml # .agents/notes/implemented/feature/2026-07-21-cross-session-references.zh.md # .agents/notes/implemented/feature/2026-07-27-tmux-location-context.i18n.yaml # .agents/notes/implemented/simplification/2026-06-20-public-agent-stop-surface.i18n.yaml # .agents/notes/implemented/simplification/2026-07-17-one-send-one-turn.i18n.yaml # .agents/notes/implemented/simplification/2026-07-17-one-send-one-turn.zh.md # .agents/notes/implemented/simplification/2026-07-20-unwrap-injected-content-envelopes.i18n.yaml # .agents/notes/implemented/simplification/2026-07-22-plan-specific-collaboration-state.i18n.yaml # .agents/notes/implemented/simplification/2026-07-22-plan-specific-collaboration-state.zh.md # .agents/notes/implemented/simplification/2026-07-24-agent-loop-observable-state-machine.i18n.yaml # .agents/notes/implemented/simplification/2026-07-27-request-error-retry-action.i18n.yaml # docs/core-data-structures/compaction.i18n.yaml # docs/core-data-structures/goal.i18n.yaml # docs/core-data-structures/goal.zh.md # docs/core-data-structures/llm-streaming.i18n.yaml # docs/core-data-structures/session.i18n.yaml # docs/core-data-structures/session.zh.md # docs/core-data-structures/skills.i18n.yaml # docs/core-data-structures/skills.zh.md # docs/core-data-structures/system-prompt.i18n.yaml # docs/defensive-patterns.i18n.yaml # docs/defensive-patterns.zh.md # docs/user/develop/framework/events.i18n.yaml # docs/user/develop/framework/events.zh.md # packages/acp/acp/README.i18n.yaml # packages/client/ui-goal/README.i18n.yaml # packages/compact/compact-basic/README.i18n.yaml # packages/compact/compact/README.i18n.yaml # packages/context/time-context/README.i18n.yaml # packages/context/tmux-context/README.i18n.yaml # packages/core/agent-loop/README.i18n.yaml # packages/core/agent-loop/README.zh.md # packages/core/agent/README.i18n.yaml # packages/core/agent/README.zh.md # packages/core/session/README.i18n.yaml # packages/core/session/README.zh.md # packages/core/system-prompt/README.i18n.yaml # packages/core/system-prompt/README.zh.md # packages/examples/cli-demo/README.i18n.yaml # packages/goal/command-goal/README.i18n.yaml # packages/goal/goal-session/README.i18n.yaml # packages/goal/goal/README.i18n.yaml # packages/goal/tool-goal/README.i18n.yaml # packages/goal/tool-goal/README.zh.md # packages/guard/README.i18n.yaml # packages/guard/README.zh.md # packages/guard/repeat-tool-guard/README.i18n.yaml # packages/hooks/hooks-claude/README.i18n.yaml # packages/hooks/hooks-codex/README.i18n.yaml # packages/host/apiproxy/README.i18n.yaml # packages/host/apiproxy/README.zh.md # packages/llm/llm/README.i18n.yaml # packages/plan/plan-mode/README.i18n.yaml # packages/plan/plan-mode/README.zh.md # packages/sdk/sdk-client/README.i18n.yaml # packages/sdk/sdk-client/README.zh.md # packages/sdk/sdk-protocol/README.i18n.yaml # packages/session-persistence/session-persistence/README.i18n.yaml # packages/session-persistence/session-persistence/README.zh.md # packages/skill/tool-skill/README.i18n.yaml # packages/subagent/subagent-dsh-sdk/README.i18n.yaml # packages/subagent/subagent-inprocess/README.i18n.yaml # packages/subagent/subagent-inprocess/README.zh.md # packages/ui/jsonrpc/README.i18n.yaml
9.2 KiB
dsh-system-prompt
English | 中文
系统提示词组装注册表。插件贡献有序段、工具 schema 和具名变量。循环在每个步骤组装一次,并将结果渲染为完整的模型提示词。此插件拥有静态 harness 身份和全局部署 persona;agent(智能体)作用域的 persona 会遮蔽全局默认值。
配置
| 键 | 默认值 | 含义 |
|---|---|---|
includeHarnessIdentity |
true |
是否包含固定的 You are an AI agent powered by the DeepSeek Harness SDK.、顺序为 −100 的开场白。仅当兼容部署拥有完整系统提示词时设为 false。 |
persona |
'' |
全局部署 persona 默认值:唯一由配置创作的提示词片段,渲染为顺序为 0 的 deployment:persona 段,除非 agent 作用域的贡献将其遮蔽。它是模板,完整的 {{…}} 组会严格按已注册变量解释(随附循环注册 {{model}}/{{cwd}}),目前没有表达字面量花括号的转义语法。为空 ⇒ 渲染时删除该段。 |
toolOrder |
无 | 显式的面向模型工具顺序:一个 ToolSchema.name 列表,包含一个 '<unlisted-tools>' 其余项(TOOL_ORDER_REST)。已列工具占据列出的位置;未列工具按名称字典序落在其余项位置。缺席 ⇒ 直接按名称字典序排列。在 system-prompt/assemble waterfall(瀑布式事件)之前应用于已收集工具;与段的 order 排序一样,它会规范化注册表贡献的内容(注册顺序是插件加载产物),而修改列表的 waterfall 监听器拥有其输出的确定性。配置错误会明确失败:列表没有恰好一个其余项或存在重复项,会在加载时抛出;已列名称没有对应已注册工具,会使每次 assemble() 被拒绝;工具提供方返回保留的其余项名称也会被拒绝。在随附循环下,轮次会在任何模型请求前失败。为何采用中心列表而非每插件权重,见显式面向模型工具顺序。 |
服务:SystemPrompt(ctx 键:systemPrompt)
公开 API
ctx.systemPrompt.section(section: PromptSection): () => void:贡献一个段。层由调用上下文的作用域决定:agent.ctx只为该 agent 贡献,并在该处遮蔽同名全局段。同一层中的重复名称和非有限顺序会抛出。随调用 fiber 一并 dispose(资源释放)。ctx.systemPrompt.tools(provider: (context: AssembleContext) => ToolProviderResult): () => void:贡献工具 schema;每次组装时使用该次组装的上下文求值。ToolProviderResult={ schemas, knownNames? }:schemas是限制后的可见集合;knownNames是限制前由toolOrder使用的全集。提供方不得返回名为TOOL_ORDER_REST的 schema。带作用域提供方只在其作用域的组装中查询。随调用 fiber 一并 dispose。ctx.systemPrompt.variable(name: string, provider: (context) => string | undefined): () => void:贡献提示词变量,在段文本中以{{name}}引用。带作用域变量会为该 agent 遮蔽同名全局变量。同层重复或无法引用的名称会抛出;undefined表示「本次组装没有值」。随调用 fiber 一并 dispose。ctx.systemPrompt.assemble(context?: AssembleContext): Promise<PromptAssembly>:为一个调用方组装提示词:将全局层与context.scope的层合并,并在变换 seam 前分离工具 schema。它经过按作用域筛选的system-prompt/assemblewaterfall,并返回其权威结果。可选的context.signal显式控制本次组装请求;提供方与监听器可以配合该信号,但不得将它保留给另一轮次。当已配置的toolOrder指名提供方knownNames全集以外的工具,或提供方返回保留的其余项名称时,调用会被拒绝。
实时事件
system-prompt/assemble 是权威来源;替换条目的监听器必须保留任何活动 Code Mode 或结构化输出协议。筛选需要在呈现、查找与执行之间保持一致时,应使用 ToolRegistry.restrict()。注册表变更通知不经过筛选。生成的事件目录 拥有签名与分发契约。
关键类型
AssembleContext:说明一次assemble()调用的用途。它可通过合并扩展;此处声明scope?: ScopeKey(层选择器)与signal?: AbortSignal(显式请求控制能力),而dsh-agent声明agent?: Agent(类型化 DX 字段;绝不能在没有scope时设置,应使用assembleContextFor(agent, signal))。提供方必须容忍字段缺席,因为裸assemble()携带的是无作用域、无信号的空上下文。signal是请求值,不是环境 Agent 执行 frame 的一部分。PromptSection:{ name, order, text }。各段按order升序拼接。顺序区间:-100是 harness 身份,0是部署 persona,工具引导使用100–199。PromptAssembly:{ sections: AssembledSection[], tools: ToolSchema[], variables: Record<string, string | undefined> }。段文本到达时已解析,但尚未插值;variables包含对上下文解析后的每个已注册变量。工具 schema 按设计属于组装结果:「模型获知自己能做什么」是一个连贯整体,尽管适配器把 schema 作为独立 wire 字段传输。renderPrompt(assembly):插值每个段中的{{variable}}引用,删除空段,并用空行连接。严格规则:未知引用(使用Object.hasOwn查找,因此{{constructor}}等原型名称未知)、已注册但无值的引用、格式错误的完整{{…}}组,或一个起始{{没有打开完整组、但后面仍有}}({{{model}}}),都会抛出;明确失败胜过交付格式错误的提示词。孤立的{{如果后面任何位置都没有}},会按字面量通过;替换值绝不再次扫描。
可通过合并扩展:插件可以借助声明合并,为 PromptAssembly 和 AssembleContext 声明额外字段。
扩展点
- 段提供方:工具包(package)拥有跨调用引导(
tool:bash、tool:read等);此插件拥有harness:identity与deployment:persona。 - 变量提供方:agent loop(智能体循环)注册
model与cwd;任何插件都可以注册自己拥有的事实(未来的date、git 状态等)。 - 工具 schema 提供方:
ToolRegistry自动将自身注册为工具提供方。 system-prompt/assemblewaterfall:按调用方协作式修改或替换组装结果。
设计原理:提示词变量 Agent Note。
模型体验
系统提示词
模型看到的内容
默认情况下,每次组装都从下方 harness 身份开始,然后在严格变量插值后追加已配置 persona 与有序插件段。includeHarnessIdentity: false 仅为拥有完整兼容 persona 的部署省略这个固定开场白。空段会消失;带作用域的段和变量可以为一个 agent 遮蔽全局项。最终 system-prompt/assemble waterfall 结果是权威来源,因此专家监听器的变更决定交付的提示词与工具 schema。
Harness 身份
You are an AI agent powered by the DeepSeek Harness SDK.
Token 影响
启用时,身份是每次请求的固定成本。Persona 与插件文本在每次请求中重复,成本随渲染内容增长。
KV Cache 影响
只要身份、persona、变量、段文本与顺序的渲染完全相同,前缀就保持稳定。任何变更都可能从第一个变化的系统提示词 token 起使复用失效。
工具 schema
模型看到的内容
对于已交付工具,模型会收到生成工具 schema 中对每个 agent 可见的子集;限制与组装拦截完成后,按配置或字典序排列。扩展可以通过同一注册表贡献其他定义。段与 schema 提供方是独立的组装输入,因此工具限制不会移除独立注册的引导。
Token 影响
Schema token 在每次请求中重复。限制工具会为该 agent 移除其全部 schema 成本,但不会移除独立提示词段;重排序会改变缓存形状,但不改变语义内容。
KV Cache 影响
只要可见 schema 集合、渲染与顺序不变,前缀就保持稳定。注册、限制或重排序可能从第一个变化的 schema token 起使复用失效。
已知限制与暂缓事项
- 部署方编写的提示词文本只来自配置/组合:此插件拥有全局 persona 默认值;创建方插件可以注册 agent 作用域的遮蔽项;其他段来自拥有相应事实的插件。不存在终端用户提示词编辑 API。
- 没有表示字面量
{{…}}花括号的转义语法:每个完整组都会按已注册变量插值;只有实际提示词需要转义时才会实现。 toolOrder配置错误在提示词组装(首轮)时出现,而不是启动时:只有形状违规会在配置加载时抛出。- 共享同一
order值的段按注册顺序打破平局:这是插件加载产物;确定性依赖不同顺序区间的约定,与已规范化的工具顺序不同。