feat(agents): add tool_enforcement as first-class provider prompt section [v3 3/6]#66373
feat(agents): add tool_enforcement as first-class provider prompt section [v3 3/6]#66373100yenadmin wants to merge 6 commits into
Conversation
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.
Greptile SummaryAdds Confidence Score: 5/5
Reviews (2): Last reviewed commit: "fix(openai): handle minimal tool profile..." | Re-trigger Greptile |
There was a problem hiding this comment.
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_enforcementsection into the agent system prompt pipeline (afterexecution_bias, beforestablePrefix). - Introduce
OPENAI_GPT5_TOOL_ENFORCEMENTand wire it into OpenAI’ssectionOverrides.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. |
There was a problem hiding this comment.
💡 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".
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
There was a problem hiding this comment.
💡 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".
Codex review correctly flagged that search_files is not a registered tool ID. The actual file-search primitives are read, grep, find, and exec.
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.
|
@copilot @greptile-apps Re-review please — addressed in
|
…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).
|
@copilot Re-review please — |
| 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 | ||
|
|
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| - Current time, date, timezone → use exec (e.g. date) | |
| - Current time, date, timezone → use session_status or exec (e.g. date) |
|
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 |
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
4 files changed:
src/agents/system-prompt-contribution.ts— Add"tool_enforcement"toProviderSystemPromptSectionIdunionsrc/agents/system-prompt.ts— AddbuildOverridablePromptSectioncall fortool_enforcement(afterexecution_bias, beforestablePrefix)extensions/openai/prompt-overlay.ts— AddOPENAI_GPT5_TOOL_ENFORCEMENTconstant, wire intosectionOverrides.tool_enforcementextensions/openai/index.test.ts— Update all 7 contribution assertions to includetool_enforcementinsectionOverrides, factor the sharedstablePrefixexpectation into anEXPECTED_GPT5_STABLE_PREFIXhelper constantBenefits
tool_enforcementfor its own operational directives