2026-07-12 05:13:17 +08:00
# System Prompt Assembly
2026-07-15 23:11:25 -07:00
English | [中文 ](system-prompt.zh.md )
2026-07-12 05:13:17 +08:00
The [system-prompt package ](../../packages/core/system-prompt ) owns the data exchanged between prompt contributors and one assembly call. The package [README ](../../packages/core/system-prompt/README.md ) documents registration, ordering, scoping, and rendering behavior; this page pins the literal cross-package shapes that plugins implement or pass.
Source: [`packages/core/system-prompt/src/index.ts` ](../../packages/core/system-prompt/src/index.ts ).
## Assembly context
2026-07-16 18:12:34 +08:00
`AssembleContext` identifies the scope layer one assembly resolves and may carry the explicit control signal for that request. It is merge-extensible: `dsh-agent` adds the optional live `agent` field, and `assembleContextFor(agent, signal)` sets the explicit fields together. A bare assembly has neither scope nor signal.
2026-07-12 05:13:17 +08:00
```ts type-equiv
2026-07-19 12:25:40 +08:00
/** Merge-extensible context for one prompt assembly. */
2026-07-12 05:13:17 +08:00
interface AssembleContext {
2026-07-19 12:25:40 +08:00
/**
* Scope whose providers and waterfall listeners participate. When absent,
* only global providers and subject-less listeners participate.
*/
2026-07-12 05:13:17 +08:00
scope?: ScopeKey
2026-07-20 21:38:49 +08:00
/** Explicit control signal for the turn that requested this assembly, when any. */
2026-07-16 18:12:34 +08:00
signal?: AbortSignal
2026-07-12 05:13:17 +08:00
}
` ``
## Tool-provider result
2026-07-13 13:09:41 +08:00
` ToolProviderResult.schemas` is the model-visible set for the current assembly. ` knownNames` is the provider's pre-restriction name universe used to distinguish a configured-name typo from a known tool that is deliberately hidden in this scope.
2026-07-12 05:13:17 +08:00
` ``ts type-equiv
2026-07-19 12:25:40 +08:00
/** Tool schemas visible in one assembly and their pre-restriction name set. */
2026-07-12 05:13:17 +08:00
interface ToolProviderResult {
2026-07-19 12:25:40 +08:00
/** The schemas this provider contributes to THIS assembly. */
2026-07-12 22:49:46 +08:00
readonly schemas: readonly ToolSchema[]
2026-07-19 12:25:40 +08:00
/** The pre-restriction name universe for config validation (defaults to ` schemas`' names). */
2026-07-12 22:49:46 +08:00
readonly knownNames?: readonly string[]
2026-07-12 05:13:17 +08:00
}
` ``
2026-07-13 13:09:41 +08:00
## Prompt sections
2026-07-12 05:13:17 +08:00
2026-07-13 13:09:41 +08:00
` PromptSection` is a readonly same-process registration contract. Its text may be static or resolved from the current assembly context.
2026-07-12 05:13:17 +08:00
` ``ts type-equiv
2026-07-19 12:25:40 +08:00
/** One contributed section of the system prompt (registry input). */
2026-07-12 22:49:46 +08:00
interface PromptSection {
2026-07-19 12:25:40 +08:00
/** Unique name — a duplicate registration throws (see {@link SystemPrompt.section}). */
2026-07-12 22:49:46 +08:00
readonly name: string
2026-07-19 12:25:40 +08:00
/**
* Sections are concatenated in ascending order. Convention: ` -100` is the
* harness identity, ` 0` the deployment persona, tool guidance uses 100– 199;
* other negative orders also render before the persona.
*/
2026-07-12 22:49:46 +08:00
readonly order: number
2026-07-19 12:25:40 +08:00
/**
* 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}.
*/
2026-07-12 22:49:46 +08:00
readonly text: string | ((context: AssembleContext) => string)
2026-07-12 05:13:17 +08:00
}
` ``