openclaw - ✅(Solved) Fix [Feature]: Add agents.defaults.systemPrompt for config-injectable rules [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#50103Fetched 2026-04-08 00:59:05
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
commented ×1cross-referenced ×1labeled ×1

Add support for injecting agent rules/system prompts from openclaw.json instead of (or in addition to) bootstrap files like AGENTS.md.

Root Cause

Add support for injecting agent rules/system prompts from openclaw.json instead of (or in addition to) bootstrap files like AGENTS.md.

Fix Action

Fixed

PR fix notes

PR #52038: feat(config): add agents.defaults.systemPrompt and rules for config-injectable agent rules

Description (problem / solution / changelog)

Summary

Add systemPrompt (string) and rules (string[]) fields to agents.defaults and agents.list[], allowing users to inject behavioral rules and safety guidelines into the agent system prompt from config instead of (or in addition to) workspace bootstrap files like AGENTS.md.

Problem: Currently, agent behavioral rules live exclusively in workspace files (AGENTS.md, SOUL.md). This ties rules to the workspace, makes central management across multiple workspaces difficult, and provides no way to manage rules via Control UI or openclaw config set.

Solution:

  • systemPrompt: a block of text appended to the system prompt after workspace bootstrap files
  • rules: an array of strings rendered as a numbered list and appended after systemPrompt
  • Per-agent overrides via agents.list[].systemPrompt / agents.list[].rules
  • Fully backward compatible — empty/absent values inject nothing

Config example

{
  "agents": {
    "defaults": {
      "systemPrompt": "You are a safety-conscious assistant.",
      "rules": [
        "Do not exfiltrate private data.",
        "Do not run destructive commands without asking.",
        "When in doubt, ask."
      ]
    },
    "list": [
      {
        "id": "support",
        "systemPrompt": "You are a customer support agent.",
        "rules": ["Always be polite.", "Escalate billing issues."]
      }
    ]
  }
}

Closes #50103

Change Type

  • Feature

Scope

  • Gateway
  • API

User-visible / Behavior Changes

  • New config fields agents.defaults.systemPrompt and agents.defaults.rules
  • New per-agent config fields agents.list[].systemPrompt and agents.list[].rules
  • Config-injected content appears in the system prompt after workspace bootstrap files and channel/group system prompts
  • Per-agent values override (not merge with) defaults

Security Impact

None. This adds a new way to inject rules from user-controlled config into the system prompt. The content flows through the same extraSystemPrompt pipeline as existing channel systemPrompt fields. No new permissions, secrets handling, network calls, or command execution surface.

Repro + Verification

  1. Add systemPrompt and/or rules to agents.defaults in openclaw.json
  2. Start a session — the injected text appears in the system prompt after bootstrap files
  3. Add per-agent overrides in agents.list[] — agent-specific values take precedence

Evidence

  • Schema validation tests: 5 new tests in src/config/zod-schema.agent-defaults.test.ts
  • Prompt resolution tests: 9 new tests in src/auto-reply/reply/get-reply-run.config-system-prompt.test.ts
  • All existing tests pass (scoped: agent-scope, schema help quality)
  • pnpm check passes (format, lint, typecheck, all boundary checks)

Human Verification

  • Verified schema accepts valid systemPrompt (string) and rules (string[])
  • Verified schema rejects invalid types (number for systemPrompt, string for rules)
  • Verified per-agent override takes precedence over defaults
  • Verified case-insensitive agent ID matching
  • Verified empty/whitespace-only values inject nothing
  • Did not verify: runtime end-to-end with a live gateway session (no access to running instance)

Compatibility / Migration

Fully backward compatible. Both fields are optional and default to undefined (no injection). Existing configs are unaffected.

Failure Recovery

Revert this commit. No migration or config changes needed.

Risks and Mitigations

Low risk. The change is additive — no existing behavior is modified. The injection point follows the same pattern as existing channel systemPrompt fields.

Changed files

  • docs/.generated/config-baseline.json (modified, +74/-0)
  • docs/.generated/config-baseline.jsonl (modified, +7/-1)
  • src/agents/cli-runner/helpers.ts (modified, +6/-0)
  • src/agents/config-system-prompt.ts (added, +30/-0)
  • src/agents/pi-embedded-runner/run/attempt.ts (modified, +6/-0)
  • src/agents/pi-embedded-runner/system-prompt.ts (modified, +3/-0)
  • src/agents/system-prompt.test.ts (modified, +26/-0)
  • src/agents/system-prompt.ts (modified, +7/-0)
  • src/auto-reply/reply/get-reply-run.config-system-prompt.test.ts (added, +99/-0)
  • src/config/schema.help.ts (modified, +4/-0)
  • src/config/schema.labels.ts (modified, +4/-0)
  • src/config/types.agent-defaults.ts (modified, +13/-0)
  • src/config/types.agents.ts (modified, +10/-0)
  • src/config/zod-schema.agent-defaults.test.ts (modified, +41/-0)
  • src/config/zod-schema.agent-defaults.ts (modified, +2/-0)
  • src/config/zod-schema.agent-runtime.ts (modified, +2/-0)
RAW_BUFFERClick to expand / collapse

Summary

Add support for injecting agent rules/system prompts from openclaw.json instead of (or in addition to) bootstrap files like AGENTS.md.

Problem to solve

Currently, safety rules and behavioral guidelines live in workspace files (AGENTS.md, SOUL.md, etc.). This works but:

  • Rules are tied to the workspace
  • Cannot manage rules centrally via config or Control UI
  • Hard to share the same rules across multiple workspaces

Proposed solution

Add one or both of these fields under agents.defaults:

Option A: systemPrompt (string) — Single block of text appended to the system prompt:

"agents": { "defaults": { "systemPrompt": "Don't exfiltrate private data. Don't run destructive commands without asking. When in doubt, ask." } } Option B: rules (array of strings) — Multiple rules rendered as a list and injected:

"agents": { "defaults": { "rules": [ "Don't exfiltrate private data. Ever.", "Don't run destructive commands without asking.", "trash > rm (recoverable beats gone forever)", "When in doubt, ask." ] } } Behavior:

Content is injected into the system prompt after bootstrap files (AGENTS.md, SOUL.md, etc.). Support per-agent overrides via agents.list[].systemPrompt or agents.list[].rules. Empty string or empty array injects nothing. Support $include to reference external files, e.g. "rules": { "$include": "./rules.json5" }.

Alternatives considered

Alternatives Considered Continue using AGENTS.md only — Works today, but rules stay tied to the workspace and cannot be managed via config or Control UI; sharing rules across workspaces is awkward. Use agent:bootstrap hook — Flexible, but requires writing an extension, which is not practical for most users and is not a built-in feature. Add rules to hooks.internal.entries.session-memory.onSessionStart — Only changes which files are read; does not allow injecting rules from config and increases prompt size. Per-channel systemPrompt only — Existing channels.telegram.groups.*.systemPrompt etc. apply per channel; there is no way to set global default rules.

Impact

Affected users/systems/channels: All OpenClaw users who want to manage agent behavior rules from config, especially those with multiple workspaces or channels.

Severity: Medium. AGENTS.md works today, but lack of config-level control makes rule management harder than necessary.

Frequency: Whenever a new workspace is created or rules are updated; more noticeable when sharing rules across workspaces.

Consequence:

Manual duplication of AGENTS.md across workspaces. No way to edit rules via Control UI or openclaw config set. Rules scattered across workspaces, harder to audit and version. Rules coupled to workspace layout, complicating deployment and migration.

Evidence/examples

No response

Additional information

No response

extent analysis

Fix Plan

To add support for injecting agent rules and system prompts from openclaw.json, follow these steps:

  1. Update openclaw.json schema: Add systemPrompt and rules fields under agents.defaults.
  2. Implement config parsing: Parse the new fields in openclaw.json and store them in a variable.
  3. Inject rules and prompts: Append the parsed rules and prompts to the system prompt after bootstrap files.

Example Code (JavaScript)

const openclawConfig = require('./openclaw.json');

// Parse systemPrompt and rules from openclaw.json
const systemPrompt = openclawConfig.agents.defaults.systemPrompt;
const rules = openclawConfig.agents.defaults.rules;

// Inject rules and prompts into system prompt
const injectRulesAndPrompts = (systemPrompt, rules) => {
  let prompt = '';
  if (systemPrompt) {
    prompt += systemPrompt + '\n';
  }
  if (rules) {
    prompt += 'Rules:\n' + rules.join('\n');
  }
  return prompt;
};

const updatedSystemPrompt = injectRulesAndPrompts(systemPrompt, rules);

Per-agent overrides: Support per-agent overrides by adding systemPrompt and rules fields to agents.list[] and updating the injectRulesAndPrompts function to prioritize these values.

$include support: Implement $include support by checking if the rules field is an object with a $include property, and if so, read the referenced file and parse its contents.

Verification

Verify the fix by:

  • Checking that the system prompt includes the injected rules and prompts.
  • Testing per-agent overrides.
  • Validating that $include support works correctly.

Extra Tips

  • Ensure that the openclaw.json schema is updated to reflect the new fields.
  • Consider adding validation for the systemPrompt and rules fields to prevent errors.
  • Document the new features and provide examples for users.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING