Files
deepseek-harness/docs/core-data-structures/system-prompt.zh.md
2026-07-23 18:45:56 +08:00

2.7 KiB
Raw Blame History

系统提示词组装

English | 中文

system-prompt 包package负责管理提示词贡献者与一次组装调用之间交换的数据。该包的 README 记录了注册、排序、作用域与渲染行为;本页固定各插件实现或传递的跨包字面形状。

源码:packages/core/system-prompt/src/index.ts

组装上下文

AssembleContext 标识一次组装所解析的作用域 layer并可携带该请求的显式控制 signal。它可合并扩展dsh-agent 添加可选的 live agent 字段,assembleContextFor(agent, signal) 则一起设置这些显式字段。裸组装既没有 scope也没有 signal。

/** Merge-extensible context for one prompt assembly. */
interface AssembleContext {
  /**
   * Scope whose providers and waterfall listeners participate. When absent,
   * only global providers and subject-less listeners participate.
   */
  scope?: ScopeKey
  /** Explicit control signal for the turn that requested this assembly, when any. */
  signal?: AbortSignal
}

工具提供方结果

ToolProviderResult.schemas 是当前组装中对模型可见的工具集合。knownNames 是提供方在限制前的名称全集,用于区分「配置名拼写错误」与「已知工具在此作用域中被有意隐藏」。

/** Tool schemas visible in one assembly and their pre-restriction name set. */
interface ToolProviderResult {
  /** The schemas this provider contributes to THIS assembly. */
  readonly schemas: readonly ToolSchema[]
  /** The pre-restriction name universe for config validation (defaults to `schemas`' names). */
  readonly knownNames?: readonly string[]
}

提示词段落

PromptSection 是一份只读的同进程注册契约。其文本可以是静态的,也可以从当前组装上下文动态解析。

/** One contributed section of the system prompt (registry input). */
interface PromptSection {
  /** Unique name — a duplicate registration throws (see {@link SystemPrompt.section}). */
  readonly name: string
  /**
   * Sections are concatenated in ascending order. Convention: `-100` is the
   * harness identity, `0` the deployment persona, tool guidance uses 100199;
   * other negative orders also render before the persona.
   */
  readonly order: number
  /**
   * Static text or a provider evaluated at each assembly with that assembly's
   * {@link AssembleContext}. The text may reference `{{variable}}`s — they are
   * interpolated later, by {@link renderPrompt}.
   */
  readonly text: string | ((context: AssembleContext) => string)
}