openclaw - ✅(Solved) Fix [GPT 5.4 v3 — PR 3/6] Add tool_enforcement as first-class provider prompt section [2 pull requests, 1 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#66348Fetched 2026-04-15 06:26:31
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
cross-referenced ×4referenced ×1

Fix Action

Fixed

PR fix notes

PR #66371: feat(openai): add mandatory tool-use categories for GPT-5 models [v3 1/6]

Description (problem / solution / changelog)

GPT 5.4 Enhancement v3 — PR 1/6

Tracking: #66345 | Issue: #66346 Priority: P0 — CRITICAL | Gap closure: ~35%

Problem

GPT 5.4 on OpenClaw answers factual, computational, and system-state questions from training data instead of calling tools. This is the #1 root cause of the behavioral gap vs Hermes Agent.

               User: "What time is it?"
          ┌─────────────┴──────────────┐
          │                            │
    ┌─────▼──────┐              ┌──────▼──────┐
    │   Hermes    │              │  OpenClaw    │
    │             │              │  (before)    │
    │ Has:        │              │              │
    │ "NEVER      │              │ No mandatory │
    │  answer     │              │ tool-use     │
    │  from       │              │ categories   │
    │  memory"    │              │              │
    │ + 8 categ.  │              │              │
    └─────┬───────┘              └──────┬───────┘
          │                             │
    ┌─────▼──────┐              ┌───────▼──────┐
    │ Calls       │              │ Answers from  │
    │ `date` tool │              │ training data │
    │ ✅ CORRECT   │              │ ❌ STALE       │
    └─────────────┘              └──────────────┘

Changes

extensions/openai/prompt-overlay.ts:

  • Added OPENAI_GPT5_TOOL_ENFORCEMENT constant with 8 mandatory tool-use categories:
    • Arithmetic/math, hashes/encodings, timestamps, system state, file contents, git, current facts, network checks
  • Appended to stablePrefix in resolveOpenAISystemPromptContribution

Hermes Reference

agent/prompt_builder.py lines 207-218 — <mandatory_tool_use> block within OPENAI_MODEL_EXECUTION_GUIDANCE.

Verification

Test GPT 5.4 — all should call tools, not answer from memory:

  • "What time is it?" → date
  • "What's the sha256 of 'hello'?" → echo -n hello | sha256sum
  • "How much free disk space?" → df -h
  • "What branch am I on?" → git branch --show-current
  • "What's 2^64?" → terminal/code execution

Note

Currently placed in stablePrefix. PR 3 (#66348) will promote tool_enforcement to a first-class sectionOverrides key, at which point this moves from stablePrefix to sectionOverrides.tool_enforcement.

Changed files

  • extensions/openai/index.test.ts (modified, +19/-7)
  • extensions/openai/prompt-overlay.ts (modified, +25/-1)

PR #66373: feat(agents): add tool_enforcement as first-class provider prompt section [v3 3/6]

Description (problem / solution / changelog)

GPT 5.4 Enhancement v3 — PR 3/6

Tracking: #66345 | Issue: #66348 Priority: P1 — MEDIUM | Type: Architecture

Problem

PR 1 (#66371) adds mandatory tool-use categories for GPT-5 via stablePrefix. This works but conflates two concerns:

  • execution_bias: how the agent executes (act first, don't plan)
  • tool_enforcement: when it must use tools (mandatory categories)

Providers should be able to override these independently.

Changes

  ┌─────────────────────────────────────────────────────────┐
  │        System Prompt Section Pipeline                    │
  │                                                          │
  │  ┌──────────────────┐  ┌──────────────────┐             │
  │  │ interaction_style │  │ tool_call_style   │             │
  │  │ (personality)     │  │ (narration rules) │             │
  │  └──────────────────┘  └──────────────────┘             │
  │                                                          │
  │  ┌──────────────────┐  ┌──────────────────┐             │
  │  │ execution_bias    │  │ tool_enforcement  │  ← NEW     │
  │  │ (act first,       │  │ (mandatory tool   │             │
  │  │  don't plan)      │  │  categories)      │             │
  │  └──────────────────┘  └──────────────────┘             │
  │                                                          │
  │  Each: provider overrides via sectionOverrides,          │
  │  or falls back to default                                │
  └─────────────────────────────────────────────────────────┘

4 files changed:

  1. src/agents/system-prompt-contribution.ts — Add "tool_enforcement" to ProviderSystemPromptSectionId union
  2. src/agents/system-prompt.ts — Add buildOverridablePromptSection call for tool_enforcement (after execution_bias, before stablePrefix)
  3. extensions/openai/prompt-overlay.ts — Add OPENAI_GPT5_TOOL_ENFORCEMENT constant, wire into sectionOverrides.tool_enforcement
  4. extensions/openai/index.test.ts — Update all 7 contribution assertions to include tool_enforcement in sectionOverrides, factor the shared stablePrefix expectation into an EXPECTED_GPT5_STABLE_PREFIX helper constant

Benefits

  • Separation of concerns: execution bias and tool enforcement are distinct prompt sections
  • Provider extensibility: Google Gemini (PR 6, #66379) uses tool_enforcement for its own operational directives
  • Testability: each section can be tested independently
  • Default empty: providers that don't need tool enforcement get an empty section (zero noise)

Changed files

  • extensions/openai/index.test.ts (modified, +25/-7)
  • extensions/openai/prompt-overlay.ts (modified, +25/-0)
  • src/agents/system-prompt-contribution.ts (modified, +2/-1)
  • src/agents/system-prompt.ts (modified, +4/-0)

Code Example

┌──────────────────────────────────────────────────────┐
System Prompt Section Pipeline  │                                                       │
  │  ┌─────────────────┐  ┌─────────────────┐            │
  │  │ interaction_style│  │ tool_call_style  │            │
 (personality) (narration rules)│            │
  │  └─────────────────┘  └─────────────────┘            │
  │                                                       │
  │  ┌─────────────────┐  ┌─────────────────┐            │
  │  │ execution_bias   │  │ tool_enforcement │ ← NEW (act first, (mandatory tool  │            │
  │  │  don't plan)     │  │  categories)     │            │
  │  └─────────────────┘  └─────────────────┘            │
  │                                                       │
Each section: provider can override via               │
  │  sectionOverrides, or fall back to default  └──────────────────────────────────────────────────────┘

---

export type ProviderSystemPromptSectionId =
  | "interaction_style"
  | "tool_call_style"
  | "execution_bias"
  | "tool_enforcement";  // ← NEW

---

...buildOverridablePromptSection({
  override: providerSectionOverrides.execution_bias,
  fallback: buildExecutionBiasSection({ isMinimal }),
}),
...buildOverridablePromptSection({
  override: providerSectionOverrides.tool_enforcement,  // ← NEW
  fallback: [],  // empty by default — only providers that need it inject content
}),

---

sectionOverrides: {
  execution_bias: OPENAI_GPT5_EXECUTION_BIAS,
  tool_enforcement: OPENAI_GPT5_TOOL_ENFORCEMENT,  // ← moved here
  ...(params.mode === "friendly" ? { interaction_style: ... } : {}),
},
RAW_BUFFERClick to expand / collapse

Parent: #66345 — GPT 5.4 Enhancement v3: Hermes Parity Sprint

Priority: P1 — MEDIUM Type: Architecture / Refactor

Problem

PR 1 (#66346) adds mandatory tool-use categories for GPT-5. Currently, the only way to inject this is via stablePrefix (a flat string) or by hardcoding it into the execution_bias section override. Neither is clean:

  • stablePrefix doesn't participate in the section override system, so providers can't selectively replace tool enforcement without touching execution bias.
  • Stuffing it into execution_bias conflates two concerns: how the agent executes (bias) vs when it must use tools (enforcement).

Proposed Implementation

Architecture

  ┌──────────────────────────────────────────────────────┐
  │        System Prompt Section Pipeline                 │
  │                                                       │
  │  ┌─────────────────┐  ┌─────────────────┐            │
  │  │ interaction_style│  │ tool_call_style  │            │
  │  │ (personality)    │  │ (narration rules)│            │
  │  └─────────────────┘  └─────────────────┘            │
  │                                                       │
  │  ┌─────────────────┐  ┌─────────────────┐            │
  │  │ execution_bias   │  │ tool_enforcement │ ← NEW     │
  │  │ (act first,      │  │ (mandatory tool  │            │
  │  │  don't plan)     │  │  categories)     │            │
  │  └─────────────────┘  └─────────────────┘            │
  │                                                       │
  │  Each section: provider can override via               │
  │  sectionOverrides, or fall back to default             │
  └──────────────────────────────────────────────────────┘

File: src/agents/system-prompt-contribution.ts

Add "tool_enforcement" to the section ID union:

export type ProviderSystemPromptSectionId =
  | "interaction_style"
  | "tool_call_style"
  | "execution_bias"
  | "tool_enforcement";  // ← NEW

File: src/agents/system-prompt.ts

Add a new buildOverridablePromptSection call after execution_bias:

...buildOverridablePromptSection({
  override: providerSectionOverrides.execution_bias,
  fallback: buildExecutionBiasSection({ isMinimal }),
}),
...buildOverridablePromptSection({
  override: providerSectionOverrides.tool_enforcement,  // ← NEW
  fallback: [],  // empty by default — only providers that need it inject content
}),

File: extensions/openai/prompt-overlay.ts

Move tool enforcement from stablePrefix to sectionOverrides:

sectionOverrides: {
  execution_bias: OPENAI_GPT5_EXECUTION_BIAS,
  tool_enforcement: OPENAI_GPT5_TOOL_ENFORCEMENT,  // ← moved here
  ...(params.mode === "friendly" ? { interaction_style: ... } : {}),
},

Benefits

  1. Separation of concerns: Execution bias and tool enforcement are distinct prompt concerns
  2. Provider extensibility: Google, Anthropic, or custom providers can inject their own tool enforcement via the same mechanism
  3. Testability: Each section can be tested independently
  4. Future-proofing: New providers (e.g., Google Gemini in PR 6) can use tool_enforcement without modifying core

Verification

  • Unit test: GPT-5 models receive tool enforcement section in system prompt
  • Unit test: Non-GPT-5 models receive empty tool enforcement section
  • Unit test: Custom provider can override tool enforcement independently of execution bias

extent analysis

TL;DR

To address the issue, add a new tool_enforcement section to the system prompt pipeline, allowing providers to override it independently of execution_bias.

Guidance

  • Introduce a new tool_enforcement section ID to the ProviderSystemPromptSectionId union type in src/agents/system-prompt-contribution.ts.
  • Add a buildOverridablePromptSection call for tool_enforcement in src/agents/system-prompt.ts, with an empty fallback.
  • Move tool enforcement from stablePrefix to sectionOverrides in extensions/openai/prompt-overlay.ts.
  • Verify the changes through unit tests, ensuring GPT-5 models receive the tool enforcement section, non-GPT-5 models receive an empty section, and custom providers can override tool enforcement independently.

Example

// src/agents/system-prompt-contribution.ts
export type ProviderSystemPromptSectionId =
  | "interaction_style"
  | "tool_call_style"
  | "execution_bias"
  | "tool_enforcement";

// src/agents/system-prompt.ts
...buildOverridablePromptSection({
  override: providerSectionOverrides.tool_enforcement,
  fallback: [],
}),

// extensions/openai/prompt-overlay.ts
sectionOverrides: {
  execution_bias: OPENAI_GPT5_EXECUTION_BIAS,
  tool_enforcement: OPENAI_GPT5_TOOL_ENFORCEMENT,
},

Notes

This solution assumes that the buildOverridablePromptSection function and sectionOverrides object are already implemented and functioning correctly. Additionally, the OPENAI_GPT5_TOOL_ENFORCEMENT constant should be defined and contain the necessary tool enforcement configuration.

Recommendation

Apply the proposed implementation, as it provides a clean and extensible solution for separating execution bias and tool enforcement concerns, allowing for better testability and future-proofing.

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