Skip to content

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

Closed
100yenadmin wants to merge 7 commits into
openclaw:mainfrom
electricsheephq:gpt5-v3/mandatory-tool-use-categories
Closed

feat(openai): add mandatory tool-use categories for GPT-5 models [v3 1/6]#66371
100yenadmin wants to merge 7 commits into
openclaw:mainfrom
electricsheephq:gpt5-v3/mandatory-tool-use-categories

Conversation

@100yenadmin

Copy link
Copy Markdown
Contributor

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.

GPT 5.4 on OpenClaw answers factual, computational, and system-state
questions from training data instead of calling tools. This produces
hallucinated or stale answers and breaks the agentic flow.

Hermes Agent solves this with an explicit mandatory tool-use list.
This PR ports that pattern: 8 categories where GPT-5 must always use
a tool (arithmetic, hashing, timestamps, system state, file contents,
git, current facts, network checks).

Placed in stablePrefix for now; will move to sectionOverrides once
tool_enforcement becomes a first-class section ID.

Part of GPT 5.4 Enhancement v3 sprint. Closes #66346.
Tracking issue: #66345.
@greptile-apps

greptile-apps Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds OPENAI_GPT5_TOOL_ENFORCEMENT, an 8-category mandatory tool-use block, to the stablePrefix for all GPT-5 models — mirroring Hermes Agent's <mandatory_tool_use> guidance. Test assertions are cleanly updated via the new EXPECTED_GPT5_STABLE_PREFIX helper, which avoids per-assertion drift when the prefix changes in future PRs.

Confidence Score: 5/5

  • Safe to merge — the previous snapshot-test breakage is resolved and the only remaining finding is a stale comment.
  • The prior P1 issue (7 broken stablePrefix assertions) was addressed. The new constant is correct, the test helper cleanly consolidates the shared expectation, and the implementation matches the stated goal. Only a P2 comment about the inline comment not documenting the temporary stablePrefix placement remains.
  • No files require special attention.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/openai/prompt-overlay.ts
Line: 132-139

Comment:
**Stale comment doesn't reflect `OPENAI_GPT5_TOOL_ENFORCEMENT` placement**

The block comment explains why `OPENAI_GPT5_TOOL_CALL_STYLE` lives in `stablePrefix`, but `OPENAI_GPT5_TOOL_ENFORCEMENT` is now also in `stablePrefix` for a different reason (temporary staging until PR 3 introduces `sectionOverrides.tool_enforcement`). A reader landing here has no indication that the third entry has a different rationale and will eventually move.

```suggestion
  // tool_call_style is NOT overridden via sectionOverrides because the
  // default section includes dynamic channel-specific approval guidance
  // from buildExecApprovalPromptGuidance() that varies per runtime
  // channel. Overriding it with a static string would lose that dynamic
  // content. Instead, the tool-first reinforcement lives in stablePrefix
  // so it's always present alongside the default tool_call_style section.
  // tool_enforcement is also in stablePrefix temporarily; PR 3 (#66348)
  // will promote it to a first-class sectionOverrides.tool_enforcement key.
  return {
    stablePrefix: [OPENAI_GPT5_OUTPUT_CONTRACT, OPENAI_GPT5_TOOL_CALL_STYLE, OPENAI_GPT5_TOOL_ENFORCEMENT].join("\n\n"),
```

How can I resolve this? If you propose a fix, please make it concise.

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

Adds a GPT‑5-specific “mandatory tool use” block to the OpenAI provider’s system prompt overlay to reduce GPT‑5 models answering time/math/system-state questions from training data instead of using tools (Hermes parity gap #1).

Changes:

  • Introduces OPENAI_GPT5_TOOL_ENFORCEMENT with mandatory tool-use categories.
  • Appends the new enforcement block into stablePrefix within resolveOpenAISystemPromptContribution.

Comment thread extensions/openai/prompt-overlay.ts
Comment thread extensions/openai/prompt-overlay.ts Outdated

@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: 88ad3f2ea0

ℹ️ 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
Comment thread extensions/openai/prompt-overlay.ts Outdated
Address review feedback:
- Replace generic "terminal" with canonical "exec"
- Replace "read or search tools" with "read, search_files"
- Replace "web search" with "web_search if available"
- Replace "code execution" with "code_execution"
- Add session_status as alternative for time/date
- 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: 16b8e7152b

ℹ️ 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
Eva added 2 commits April 14, 2026 13:53
All 7 test assertions now include OPENAI_GPT5_TOOL_ENFORCEMENT in the
stablePrefix array, matching the runtime behavior.
@100yenadmin
100yenadmin requested a review from Copilot April 14, 2026 07: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 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread extensions/openai/index.test.ts Outdated
Comment thread extensions/openai/prompt-overlay.ts Outdated

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 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread extensions/openai/index.test.ts
Address two Copilot review comments on PR #66371:

1. tools.profile="minimal" only has session_status registered, so
   instructing GPT-5 to "ALWAYS use exec/web_search" can produce
   invalid tool calls. Updated OPENAI_GPT5_TOOL_ENFORCEMENT to:
   - Say "use an available tool" (conditional)
   - Prefer session_status for time/system state when available
   - Explicitly instruct the model to state the limitation and ask
     to enable the needed tools/profile if the preferred tool is
     unavailable, rather than guessing.

2. stablePrefix assertion is repeated in 7 places in the test file,
   making it brittle to future overlay tweaks. Factored into a
   EXPECTED_GPT5_STABLE_PREFIX helper constant at the top of the
   test file.
@100yenadmin

Copy link
Copy Markdown
Contributor Author

@copilot @greptile-apps Re-review please — addressed both comments in 07f4ebb:

  • Test file: factored stablePrefix into EXPECTED_GPT5_STABLE_PREFIX helper constant
  • Tool enforcement: handles minimal tool profile (session_status fallback, explicit 'state the limitation' if tool unavailable)

@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: 07f4ebb012

ℹ️ 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
…ofiles

Codex P1 review: the previous text unconditionally said "NEVER answer
from memory" and "state the limitation and ask to enable tools" even
for trivial prompts like "2+2". In minimal/messaging profiles where
exec/code_execution are not registered, this created a functional
regression — GPT-5 would refuse to answer instead of just computing.

Fix: carve out an explicit exception for trivial deterministic
questions when no tool is available:
- Trivial arithmetic, well-known facts → answer directly, prefix
  with "from memory" so the user knows it is not grounded
- Stale-prone categories (time, system state, files, git, live
  facts) → still say we cannot verify without the tool

When a tool IS available, the rule remains strong: use it.
@100yenadmin

Copy link
Copy Markdown
Contributor Author

@copilot Re-review please — 7360b04 addresses the minimal-profile regression by carving out trivial deterministic questions (2+2, well-known facts) so they are answered directly in minimal/messaging profiles, while keeping strong grounding requirements for stale-prone categories.

Parity audit: previous iterations drifted significantly from the
Hermes reference text based on low-confidence bot review suggestions.
The entire point of the GPT 5.4 Enhancement v3 sprint is to replicate
Hermes's success on GPT-5, so the prompt must mirror Hermes as
closely as possible to preserve the cross-comparison.

Reverts the following drift:
- "NEVER answer from memory" -> softened conditional phrasing  (REVERT)
- Added "When No Tool Is Available" carve-out                  (REVERT)
- Added "Network checks" category                              (REVERT)
- Removed "Your memory and user profile describe the USER..."  (REVERT)
- Replaced arrows -> with colons                                (REVERT)

Keeps these minimal changes vs Hermes, justified by real OpenClaw
runtime differences:
- terminal     -> exec              (no `terminal` tool in OpenClaw)
- execute_code -> code_execution    (canonical OpenClaw ID)
- read_file    -> read              (canonical OpenClaw ID)
- search_files -> exec              (no first-class file-search tool)

These substitutions are documented in a comment above the constant so
future reviewers understand what is load-bearing (the semantics) vs
what is a mechanical tool-ID mapping.

The concerns raised by bot reviewers about minimal/messaging profiles
(2+2 becoming a forced refusal) are noted but are the EXACT same
behavior Hermes exhibits with its unconditional rule. If Hermes ships
with that rule and works, OpenClaw must ship with it too to preserve
the parity benchmark.

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 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines +95 to +103
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.

The PR description says GPT-5 gets 8 mandatory tool-use categories (including “Network checks”), but the new OPENAI_GPT5_TOOL_ENFORCEMENT list currently has 7 bullets and is missing the “Network checks (port open, DNS, connectivity)” category. Either add the missing category to the prompt block or update the PR description/issue references so they match exactly.

Copilot uses AI. Check for mistakes.
- 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.

This block says “NEVER … ALWAYS use a tool” and then references exec/code_execution/read/web_search as mandatory tools. In OpenClaw, tools.profile="minimal" only includes session_status by default (see src/agents/tool-catalog.ts), so GPT‑5 can be instructed to call tools that are not available in the current runtime, leading to repeated invalid tool calls instead of a graceful limitation message. Please add an explicit fallback in the enforcement text for when the preferred tool is unavailable (e.g., don’t guess; state that the tool isn’t enabled and ask to enable an appropriate tools.profile/allowlist).

Suggested change
If the needed tool is unavailable or not enabled in this runtime, do not guess and do not pretend to have used it. State that the required tool is not enabled, and ask the user to enable an appropriate tools.profile or tool allowlist for the needed capability.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@steipete @pashpashpash working on this and trying to figure out how to handle this. Code review agents aren't qualified for prompt engineering however, it is NOT wrong about tools.profile=minimal here (GPT 5.4 will potentially loop or simply try to guess and fail > preferred method is to state tool not enabled and ask to enable on tool list.

However, GPT 5.4 is "lazy" here and if prompt is changed for this, it will affect negatively the performance of all other users. It is recommended to allow this to simply error out or handle as separate PR that changes prompting for "minimal" tools profiles. My gut check is very few users on OC actually use the profile and it is better that 99% of users have a better experience in this small update versus 1% that need a "workaround".

Comment on lines +82 to +89
// Ported verbatim from Hermes Agent's OPENAI_MODEL_EXECUTION_GUIDANCE
// mandatory_tool_use block (agent/prompt_builder.py lines 207-218) with
// only tool ID substitutions for OpenClaw-canonical names:
// terminal -> exec (no `terminal` tool in OpenClaw)
// execute_code -> code_execution (canonical OpenClaw ID)
// read_file -> read (canonical OpenClaw ID)
// search_files -> exec (no first-class file-search tool;
// use shell grep via exec)

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 header comment claims there is “no first-class file-search tool” and maps search_files -> exec, but OpenClaw exposes first-class grep/find tools (e.g. src/agents/system-prompt.ts tool list). Please update this comment (and consider pointing the enforcement guidance at grep/find instead of shelling out via exec) so the overlay documentation matches actual tool availability.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants