Skip to content

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

Closed
100yenadmin wants to merge 6 commits into
openclaw:mainfrom
electricsheephq:gpt5-v3/tool-enforcement-section
Closed

feat(agents): add tool_enforcement as first-class provider prompt section [v3 3/6]#66373
100yenadmin wants to merge 6 commits into
openclaw:mainfrom
electricsheephq:gpt5-v3/tool-enforcement-section

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

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, feat(google): add Gemini execution guidance via prompt overlay [v3 6/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)

Promote tool enforcement from stablePrefix to a proper
sectionOverrides key so providers can independently control
mandatory tool-use guidance without touching execution_bias.

Changes:
- Add "tool_enforcement" to ProviderSystemPromptSectionId union
- Add buildOverridablePromptSection call in system-prompt.ts
  (renders after execution_bias, before stablePrefix)
- Add OPENAI_GPT5_TOOL_ENFORCEMENT constant and wire it into
  sectionOverrides.tool_enforcement for GPT-5 models

This separation enables other providers (Google Gemini, etc.)
to inject their own tool enforcement via the same mechanism.

Part of GPT 5.4 Enhancement v3 sprint. Closes #66348.
Tracking issue: #66345.
Copilot AI review requested due to automatic review settings April 14, 2026 06:00
@greptile-apps

greptile-apps Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds tool_enforcement as a new first-class ProviderSystemPromptSectionId, separating mandatory tool-use rules from execution behavior directives. The core section is wired in system-prompt.ts with an empty fallback (so non-GPT-5 providers are unaffected), and the OpenAI extension populates it with OPENAI_GPT5_TOOL_ENFORCEMENT. All 7 affected test assertions are correctly updated, and the shared EXPECTED_GPT5_STABLE_PREFIX constant is a nice deduplication.

Confidence Score: 5/5

  • Safe to merge — additive type extension with empty fallback; no existing behavior is changed.
  • The change is purely additive: a new union member in the type, a new section slot with fallback: [], and a new constant wired into the OpenAI extension. The previous test-failure concern from thread was addressed in 67b860f. No P0/P1 findings remain.
  • No files require special attention.

Reviews (2): Last reviewed commit: "fix(openai): handle minimal tool profile..." | Re-trigger Greptile

Comment thread extensions/openai/prompt-overlay.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Promotes tool enforcement (mandatory tool-use categories) to a first-class, provider-overridable system prompt section, separating it from execution bias so providers can tune them independently.

Changes:

  • Add "tool_enforcement" to the provider prompt section ID union.
  • Insert a new overridable tool_enforcement section into the agent system prompt pipeline (after execution_bias, before stablePrefix).
  • Introduce OPENAI_GPT5_TOOL_ENFORCEMENT and wire it into OpenAI’s sectionOverrides.tool_enforcement.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/agents/system-prompt-contribution.ts Extends the provider section ID union to include tool_enforcement.
src/agents/system-prompt.ts Adds a new overridable prompt section slot for tool_enforcement.
extensions/openai/prompt-overlay.ts Defines GPT-5 tool enforcement text and returns it via sectionOverrides.tool_enforcement.

Comment thread extensions/openai/prompt-overlay.ts Outdated
Comment thread src/agents/system-prompt.ts
Comment thread extensions/openai/prompt-overlay.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7435e9b41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread extensions/openai/prompt-overlay.ts Outdated
Address review feedback:
- Add OPENAI_GPT5_TOOL_ENFORCEMENT import and update all 7 test
  assertions to include tool_enforcement in sectionOverrides
- Use canonical OpenClaw tool names (exec, read, search_files,
  web_search, code_execution, session_status)
- Replace em dashes with periods per GPT-5 output contract

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67b860f5d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread extensions/openai/prompt-overlay.ts Outdated
Codex review correctly flagged that search_files is not a registered
tool ID. The actual file-search primitives are read, grep, find, and
exec.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread extensions/openai/index.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Port PR #66371 improvements to this PR's branch:

1. Handle tools.profile="minimal" where only session_status is
   registered. Updated tool enforcement to say "use an available
   tool" and added explicit "state the limitation" fallback.

2. Factor stablePrefix expectation into EXPECTED_GPT5_STABLE_PREFIX
   helper at the top of the test file. Reduces brittleness when
   overlay blocks are added/reordered.
@100yenadmin

Copy link
Copy Markdown
Contributor Author

@copilot @greptile-apps Re-review please — addressed in 7ac0610:

…ofiles

Port PR #66371 fix to this branch.

Codex P1: unconditional "NEVER answer from memory" broke 2+2 in
minimal/messaging profiles where exec/code_execution aren't
registered. Now carves out an exception for trivial deterministic
questions, while keeping the rule strong for stale-prone categories
(time, system state, files, git, live facts).
@100yenadmin

Copy link
Copy Markdown
Contributor Author

@copilot Re-review please — 9142b82 ports the same minimal-profile fix from #66371 to this branch's tool enforcement constant.

Same parity revert as PR #66371's 63e0659 — restore exact Hermes
mandatory_tool_use block text, keeping only mechanical tool ID
substitutions required by OpenClaw's tool catalog.

See 63e0659 commit message on gpt5-v3/mandatory-tool-use-categories
for the full audit.
@100yenadmin
100yenadmin requested a review from Copilot April 14, 2026 11:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +93 to +103
export const OPENAI_GPT5_TOOL_ENFORCEMENT = `## Mandatory Tool Use

NEVER answer these from memory or mental computation — ALWAYS use a tool:
- Arithmetic, math, calculations → use exec or code_execution
- Hashes, encodings, checksums → use exec (e.g. sha256sum, base64)
- Current time, date, timezone → use exec (e.g. date)
- System state: OS, CPU, memory, disk, ports, processes → use exec
- File contents, sizes, line counts → use read or exec
- Git history, branches, diffs → use exec
- Current facts (weather, news, versions) → use web_search

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description (and linked PR #66371) states GPT-5 tool enforcement includes 8 mandatory categories (including network checks), but OPENAI_GPT5_TOOL_ENFORCEMENT currently lists 7 and omits the network checks category. Either add the missing network bullet to the prompt text or update the PR description/issue docs so the implementation and documented behavior match.

Copilot uses AI. Check for mistakes.
NEVER answer these from memory or mental computation — ALWAYS use a tool:
- Arithmetic, math, calculations → use exec or code_execution
- Hashes, encodings, checksums → use exec (e.g. sha256sum, base64)
- Current time, date, timezone → use exec (e.g. date)

Copilot AI Apr 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool enforcement bullet for time/date/timezone mandates using exec (e.g. date), but the core system prompt guidance elsewhere instructs using session_status to get the current date/time. This conflicting guidance can lead to unnecessary exec usage (and potential approval friction) for time lookups; consider aligning this section to prefer session_status (or explicitly allow either) to avoid contradictory instructions in the final prompt.

Suggested change
- Current time, date, timezone use exec (e.g. date)
- Current time, date, timezone use session_status or exec (e.g. date)

Copilot uses AI. Check for mistakes.
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Superseded by consolidated final-sprint PRs. This PR's changes are incorporated into:

The v3 PRs were split across 6 separate PRs which made review harder and touched the same files redundantly. The final-sprint consolidation combines them into 3 clean, independently-mergeable PRs rebased on current main.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants