feat: GPT tool-use steering + strip budget warnings from history#3479
Closed
feat: GPT tool-use steering + strip budget warnings from history#3479
Conversation
Two changes to improve tool reliability, especially for OpenAI GPT models:
1. GPT tool-use enforcement prompt: Adds GPT_TOOL_USE_GUIDANCE to the
system prompt when the model name contains 'gpt' and tools are loaded.
This addresses a known behavioral pattern where GPT models describe
intended actions ('I will run the tests') instead of actually making
tool calls. Inspired by similar steering in OpenCode (beast.txt) and
Cline (GPT-5.1 variant).
2. Budget warning history stripping: Budget pressure warnings injected by
_get_budget_warning() into tool results are now stripped when
conversation history is replayed via run_conversation(). Previously,
these turn-scoped signals persisted across turns, causing models to
avoid tool calls in all subsequent messages after any turn that hit
the 70-90% iteration threshold.
teknium1
added a commit
that referenced
this pull request
Mar 28, 2026
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
added a commit
that referenced
this pull request
Mar 28, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes to improve tool reliability, especially for OpenAI GPT models:
1. GPT tool-use enforcement prompt
Adds
GPT_TOOL_USE_GUIDANCEto the system prompt when the model name containsgptand tools are loaded. This addresses a known behavioral pattern where GPT models describe intended actions ("I will run the tests", "Next time I reply, it'll be with concrete results") instead of actually making tool calls.Both OpenCode and Cline have extensive model-specific steering for this exact issue:
Our guidance is injected in
_build_system_prompt()when"gpt" in self.model.lower()and the model has tools loaded. It's part of the frozen system prompt, so no cache-breaking concerns.2. Budget warning history stripping
Budget pressure warnings injected by
_get_budget_warning()into tool resultcontent(e.g.[BUDGET WARNING: ... Provide your final response NOW. No more tool calls unless absolutely critical.]) now get stripped when conversation history is replayed viarun_conversation().Previously these turn-scoped signals persisted in the session transcript. When the gateway replayed history for the next user message, the model would see old warnings telling it not to use tools — and comply, avoiding tool calls in ALL subsequent turns.
The fix strips both JSON
_budget_warningkeys and plain-text budget warning patterns from tool-result messages at the start ofrun_conversation().Files changed
agent/prompt_builder.py— NewGPT_TOOL_USE_GUIDANCEconstantrun_agent.py— Import + inject guidance in_build_system_prompt(), new_strip_budget_warnings_from_history()function + call inrun_conversation()tests/agent/test_prompt_builder.py— 8 new tests (guidance content + budget stripping)Test plan
python -m pytest tests/agent/test_prompt_builder.py -n0 -q→ 106 passedpython -m pytest tests/test_run_agent.py -n0 -q→ 201 passed