Skip to content

feat: add configurable system prompt preamble via file override - #62

Open
NOVA-Openclaw wants to merge 1 commit into
mainfrom
feature/system-prompt-preamble
Open

feat: add configurable system prompt preamble via file override#62
NOVA-Openclaw wants to merge 1 commit into
mainfrom
feature/system-prompt-preamble

Conversation

@NOVA-Openclaw

@NOVA-Openclaw NOVA-Openclaw commented May 31, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a file-based override for the system prompt preamble. If ~/.openclaw/system-prompt-preamble.md (or a custom filename via config) exists in the state directory, its contents replace the hardcoded "You are a personal assistant running inside OpenClaw." string.

Motivation

The hardcoded preamble contradicts custom agent personas defined in bootstrap context. Every agent operator should be able to define their own identity framing.

Implementation

  • New resolveSystemPromptPreamble() helper in src/agents/system-prompt-preamble.ts
  • Resolution order:
    1. Config agents.defaults.systemPromptPreambleFile for custom filename
    2. Default filename: system-prompt-preamble.md
    3. Full path: <stateDir>/<filename>
    4. File content used if non-empty (trimmed, CRLF→LF normalized)
    5. Falls back to hardcoded default if file missing/empty/unreadable (WARN logged for permission errors)
  • Process-scoped cache (read once at startup)
  • Integrated into stablePromptPrefixCache hash for proper cache invalidation

Changes

  • src/agents/system-prompt-preamble.ts — new helper + cache + clearSystemPromptPreambleCache() for testing
  • src/agents/system-prompt.ts — both promptMode="none" and main stablePrefix paths patched
  • src/agents/system-prompt-config.ts — wires config field through to prompt builder
  • src/cli/capability-cli.ts — lazy resolution for LOCAL_MODEL_RUN_SYSTEM_PROMPT
  • src/config/types.agent-defaults.ts + zod-schema.agent-defaults.ts — schema for systemPromptPreambleFile
  • src/agents/system-prompt-preamble.test.ts — 18 unit tests covering happy path, fallback, edge cases, caching, filename override
  • tests/test-cases-system-prompt-preamble.md — 29 test case specifications

Backward Compatibility

When no preamble file exists, behavior is identical to current — zero breaking changes.

Upstream PR Candidate

This is a clean, non-breaking enhancement suitable for upstream PR to openclaw/openclaw.

Closes #61

Closes #43

Adds resolveSystemPromptPreamble() helper that reads a preamble file from
the state directory, replacing the hardcoded 'You are a personal assistant
running inside OpenClaw.' string.

Resolution order:
1. Config agents.defaults.systemPromptPreambleFile for custom filename
2. Default filename: system-prompt-preamble.md
3. Full path: <stateDir>/<filename>
4. File content used if non-empty (trimmed, CRLF normalized)
5. Falls back to hardcoded default if file missing/empty/unreadable

Changes:
- New: src/agents/system-prompt-preamble.ts (helper + cache)
- Modified: src/agents/system-prompt.ts (both promptMode paths)
- Modified: src/agents/system-prompt-config.ts (wire config field)
- Modified: src/cli/capability-cli.ts (lazy resolution)
- Modified: src/config/types.agent-defaults.ts (schema type)
- Modified: src/config/zod-schema.agent-defaults.ts (zod schema)
- New: src/agents/system-prompt-preamble.test.ts (unit tests)
- New: tests/test-cases-system-prompt-preamble.md (29 test cases)

Closes #61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configurable system prompt preamble per agent Implement preamble-only system prompt override (agents.defaults.preamble)

1 participant