Skip to content

feat: tool-use enforcement + strip budget warnings from history#3528

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-5a68ad9d
Mar 28, 2026
Merged

feat: tool-use enforcement + strip budget warnings from history#3528
teknium1 merged 1 commit intomainfrom
hermes/hermes-5a68ad9d

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Salvage of PR #3479 with refactoring to make tool-use enforcement reusable.

1. Tool-use enforcement prompt (refactored)

Adds TOOL_USE_ENFORCEMENT_GUIDANCE to the system prompt for models that need explicit steering to use tools instead of describing actions. Refactored from the original GPT-specific implementation:

  • TOOL_USE_ENFORCEMENT_MODELS — tuple of model name substrings that trigger the guidance. Currently ("gpt", "codex"). Adding a new model family is a one-line change to this tuple.
  • Injected in _build_system_prompt() when any(p in model_lower for p in TOOL_USE_ENFORCEMENT_MODELS) and tools are loaded
  • Part of the frozen system prompt — no cache-breaking

2. Budget warning history stripping

_strip_budget_warnings_from_history() strips turn-scoped budget pressure warnings from tool-result messages at the start of run_conversation(). Previously these persisted in the session transcript and caused models to avoid tool calls in ALL subsequent turns.

Handles both formats:

  • JSON: removes _budget_warning key from parsed tool result dicts
  • Plain text: regex strips [BUDGET WARNING: Iteration N/M...] patterns

Files changed

  • agent/prompt_builder.pyTOOL_USE_ENFORCEMENT_GUIDANCE constant + TOOL_USE_ENFORCEMENT_MODELS tuple
  • run_agent.py — Import + inject guidance, new _strip_budget_warnings_from_history() + call in run_conversation()
  • tests/agent/test_prompt_builder.py — 11 new tests (guidance content, model list membership, budget stripping)

Test plan

python -m pytest tests/agent/test_prompt_builder.py tests/test_run_agent.py -n0 -q
310 passed

Closes #3479.

Cherry-pick of feat/gpt-tool-steering with modifications:

1. Tool-use enforcement prompt (refactored from GPT-specific):
   - Renamed GPT_TOOL_USE_GUIDANCE -> TOOL_USE_ENFORCEMENT_GUIDANCE
   - Added TOOL_USE_ENFORCEMENT_MODELS tuple: ('gpt', 'codex')
   - Injection logic now checks against the tuple instead of hardcoding
     'gpt' — adding new model families is a one-line change
   - Addresses models describing actions instead of making tool calls

2. Budget warning history stripping:
   - _strip_budget_warnings_from_history() strips _budget_warning JSON
     keys and [BUDGET WARNING: ...] text from tool results at the start
     of run_conversation()
   - Prevents old budget warnings from poisoning subsequent turns

Based on PR #3479 by teknium1.
@teknium1 teknium1 merged commit 831e8ba into main Mar 28, 2026
4 checks passed
teknium1 added a commit that referenced this pull request Mar 28, 2026
…cement

The TOOL_USE_ENFORCEMENT_GUIDANCE injection (added in #3528) was
hardcoded to only match gpt/codex model names. This makes it a
config option so users can turn it on for any model family.

New config key: agent.tool_use_enforcement
  - "auto" (default): matches gpt/codex (existing behavior)
  - true: inject for all models
  - false: never inject
  - list of strings: custom model-name substrings to match
    e.g. ["gpt", "codex", "deepseek", "qwen"]

No version bump needed — deep merge provides the default
automatically for existing installs.

12 new tests covering all config modes.
teknium1 added a commit that referenced this pull request Mar 28, 2026
…cement (#3551)

The TOOL_USE_ENFORCEMENT_GUIDANCE injection (added in #3528) was
hardcoded to only match gpt/codex model names. This makes it a
config option so users can turn it on for any model family.

New config key: agent.tool_use_enforcement
  - "auto" (default): matches gpt/codex (existing behavior)
  - true: inject for all models
  - false: never inject
  - list of strings: custom model-name substrings to match
    e.g. ["gpt", "codex", "deepseek", "qwen"]

No version bump needed — deep merge provides the default
automatically for existing installs.

12 new tests covering all config modes.
teknium1 added a commit that referenced this pull request Mar 28, 2026
… pages

Fixes found by auditing docs against recent PRs/commits:

Critical (misleading):
- hooks.md: Remove stale 'planned — not yet wired' markers for 4 hooks
  that are now active (#3542). Add correct callback signatures.
- security.md: Update tirith verdict behavior — block verdicts now go
  through approval flow instead of hard-blocking (#3428). Add pkill/killall
  self-termination guard and gateway-run backgrounding patterns (#3593).

New feature docs:
- configuration.md: Add tool_use_enforcement section with value table
  (auto/true/false/list) from #3551/#3528.
- configuration.md: Expand auxiliary config with per-task timeouts
  (compression 120s, web_extract 30s, approval 30s) from #3597.
- api-server.md: Add /v1/health alias, Security Headers section,
  CORS details (Max-Age, SSE headers, Idempotency-Key) from
  #3572/#3573/#3576/#3580/#3530.

Stale/incomplete:
- configuration.md: Fix Alibaba model name qwen-plus -> qwen3.5-plus (#3484).
- environment-variables.md: Specify actual DashScope default URL.
- cli-commands.md: Add alibaba to --provider list.
- fallback-providers.md: Add Alibaba/DashScope to provider table.
- email.md: Document noreply/automated sender filtering (#3606).
- toolsets-reference.md: Add 4 missing platform toolsets — matrix,
  mattermost, dingtalk, api-server (#3583).
- skills.md: List default GitHub taps including garrytan/gstack (#3605).
teknium1 added a commit that referenced this pull request Mar 28, 2026
… pages (#3618)

Fixes found by auditing docs against recent PRs/commits:

Critical (misleading):
- hooks.md: Remove stale 'planned — not yet wired' markers for 4 hooks
  that are now active (#3542). Add correct callback signatures.
- security.md: Update tirith verdict behavior — block verdicts now go
  through approval flow instead of hard-blocking (#3428). Add pkill/killall
  self-termination guard and gateway-run backgrounding patterns (#3593).

New feature docs:
- configuration.md: Add tool_use_enforcement section with value table
  (auto/true/false/list) from #3551/#3528.
- configuration.md: Expand auxiliary config with per-task timeouts
  (compression 120s, web_extract 30s, approval 30s) from #3597.
- api-server.md: Add /v1/health alias, Security Headers section,
  CORS details (Max-Age, SSE headers, Idempotency-Key) from
  #3572/#3573/#3576/#3580/#3530.

Stale/incomplete:
- configuration.md: Fix Alibaba model name qwen-plus -> qwen3.5-plus (#3484).
- environment-variables.md: Specify actual DashScope default URL.
- cli-commands.md: Add alibaba to --provider list.
- fallback-providers.md: Add Alibaba/DashScope to provider table.
- email.md: Document noreply/automated sender filtering (#3606).
- toolsets-reference.md: Add 4 missing platform toolsets — matrix,
  mattermost, dingtalk, api-server (#3583).
- skills.md: List default GitHub taps including garrytan/gstack (#3605).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant