Skip to content

System Prompt Sections

ox-core assembles system prompts from an ordered list of named sections (PromptSection) via SystemPromptBuilder. Callers can override individual sections programmatically or from a directory of Markdown files without replacing the entire prompt.

Common section names follow a predictable order:

Section Purpose
identity Agent role, persona, and core behavioral rules
tools Tool usage guidance and environment constraints
skills Available skill summaries and activation rules
instructions Project-level instructions and repository conventions
memory Project memory index and recall guidance

SystemPromptBuilder::with_section appends a new section or replaces an existing section in place, preserving render order. render() trims outer whitespace from each section, skips blank sections, and joins the rest with a blank line (\n\n).

Use SystemPromptBuilder::apply_override(name, SectionOverride) to modify a registered section:

Variant Effect
Replace(String) Replaces the section body with new content
Append(String) Appends content after the existing body (separated by \n\n)
Prepend(String) Prepends content before the existing body (separated by \n\n)
Remove Removes the section from the rendered prompt

apply_override returns true when a matching section exists and false otherwise.

Use SystemPromptBuilder::apply_overrides_from_dir(dir) to load <section-name>.md files from a directory:

.ox/prompts/
├── identity.md # replaces the `identity` section
└── tools.md # empty file removes the `tools` section

Directory loading follows four rules (project-local .ox/ overrides require workspace trust via --trust or trusted.toml, see Project Trust, and <package_root>/prompts/ directories from configured package_roots are also loaded, see Package Roots):

  • Missing directories are ignored and return Ok(0).
  • Only regular .md files in dir are read, sorted by file name.
  • An empty or whitespace-only .md file removes the matching section, and a non-empty file replaces it.
  • Files whose stem does not match a registered section are ignored.

Declarative prompt overrides and custom compaction prompts are rendered through render_template before replacing a section or system prompt.

  • Syntax: Placeholders use {{name}} with lowercase ASCII letters, digits, or underscores ([a-z0-9_]+) and optional ASCII spaces inside the braces (such as {{ default }}).
  • Escaping: Prefix a valid placeholder with a backslash (\{{name}}) to emit literal {{name}} without the backslash.
  • Single-pass rendering: Substituted values are emitted directly without re-scanning, so placeholder syntax inside a variable value stays literal.
  • Unknown or invalid placeholders: Unrecognized names and non-matching syntax (such as {{ matrix.os }}, {{UPPER}}, or unclosed {{x) are preserved verbatim.
Placeholder Description
{{default}} Existing section content (or the built-in compaction prompt) before override
{{cwd}} Active workspace directory path
{{model}} Active model identifier when available