openclaw - 💡(How to fix) Fix Embedded agent runtime overwrites OpenClaw system prompt after tool activation [1 pull requests]

Official PRs (…)
ON THIS PAGE

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…

The embedded agent runtime can overwrite OpenClaw's intended system prompt with the generic embedded coding-agent prompt after active tools are selected.

This changes model behavior in live channel sessions. In the observed regression, the model received a system prompt starting with:

You are an expert coding assistant operating inside OpenClaw's embedded coding agent harness...

instead of the expected OpenClaw assistant prompt:

You are a personal assistant running inside OpenClaw.

The bad prompt also included:

Available tools: (none)

Root Cause

On current main, the embedded runner applies the intended OpenClaw system prompt, then immediately changes active tools:

  • src/agents/embedded-agent-runner/run/attempt.ts
    • applySystemPromptOverrideToSession(session, systemPromptText)
    • session.setActiveToolsByName(sessionToolAllowlist)

setActiveToolsByName(...) rebuilds and writes the session system prompt:

  • src/agents/sessions/agent-session.ts
    • this.baseSystemPrompt = this.rebuildSystemPrompt(validToolNames)
    • this.agent.state.systemPrompt = this.baseSystemPrompt

That rebuild uses the embedded coding-agent prompt from:

  • src/agents/sessions/system-prompt.ts

The override helper tries to protect the prompt by writing _baseSystemPrompt and _rebuildSystemPrompt:

  • src/agents/embedded-agent-runner/system-prompt.ts

But the internalized OpenClaw AgentSession uses baseSystemPrompt and rebuildSystemPrompt, not the old underscored fields. Those underscore writes no longer affect the real prompt state.

Fix Action

Fixed

RAW_BUFFERClick to expand / collapse

Summary

The embedded agent runtime can overwrite OpenClaw's intended system prompt with the generic embedded coding-agent prompt after active tools are selected.

This changes model behavior in live channel sessions. In the observed regression, the model received a system prompt starting with:

You are an expert coding assistant operating inside OpenClaw's embedded coding agent harness...

instead of the expected OpenClaw assistant prompt:

You are a personal assistant running inside OpenClaw.

The bad prompt also included:

Available tools: (none)

Impact

This changes how the agent behaves in user-facing channels even when the same env, provider, model, workspace context, and skills are used.

Observed environment:

  • Env: Violet-media-live-20260527
  • Stable runtime: 2026.5.26
  • Dev/current runtime: 2026.5.28
  • Provider/model: github-copilot/claude-opus-4.7

Skills were not the cause in the inspected sessions. The visible <available_skills> prompt was byte-identical between stable and dev.

Root Cause

On current main, the embedded runner applies the intended OpenClaw system prompt, then immediately changes active tools:

  • src/agents/embedded-agent-runner/run/attempt.ts
    • applySystemPromptOverrideToSession(session, systemPromptText)
    • session.setActiveToolsByName(sessionToolAllowlist)

setActiveToolsByName(...) rebuilds and writes the session system prompt:

  • src/agents/sessions/agent-session.ts
    • this.baseSystemPrompt = this.rebuildSystemPrompt(validToolNames)
    • this.agent.state.systemPrompt = this.baseSystemPrompt

That rebuild uses the embedded coding-agent prompt from:

  • src/agents/sessions/system-prompt.ts

The override helper tries to protect the prompt by writing _baseSystemPrompt and _rebuildSystemPrompt:

  • src/agents/embedded-agent-runner/system-prompt.ts

But the internalized OpenClaw AgentSession uses baseSystemPrompt and rebuildSystemPrompt, not the old underscored fields. Those underscore writes no longer affect the real prompt state.

Why This Regressed

This appears to come from the runtime internalization work:

  • bb46b79d3c refactor: internalize OpenClaw agent runtime (#85341)

In 2026.5.26, OpenClaw used the external @earendil-works/[email protected] runtime, whose session internals used _baseSystemPrompt and _rebuildSystemPrompt.

After internalization, OpenClaw owns the session class and the real fields are non-underscored private members, but the override shim still writes the old underscored names.

Expected Behavior

The embedded runner should preserve the OpenClaw-built system prompt after active tool selection.

Tool activation must not replace the OpenClaw assistant prompt with the generic embedded coding-agent prompt.

Suggested Fix

Add a real system prompt override API on AgentSession, for example:

  • setSystemPromptOverride(systemPrompt: string)

Then make rebuildSystemPrompt(...) preserve the override while still tracking selected tools in prompt options.

Also apply the initial embedded runner override after setActiveToolsByName(...), so tool activation cannot clobber the OpenClaw prompt.

Regression Coverage

Add tests for:

  • changing active tools after setting a system prompt override does not replace the override;
  • applySystemPromptOverrideToSession(...) uses the real override API when available;
  • the embedded runner preserves the OpenClaw prompt through session creation and tool activation.

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