Skip to content

[GPT 5.4 v3 — PR 3/6] Add tool_enforcement as first-class provider prompt section #66348

Description

@100yenadmin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions