Repository navigation
Improve OpenAI prompt caching with System One tool selection - #190
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review issues were identified, and all reviewed changes are covered by passing validation.
No open issues 🎉
What changed in this PR
Adds an optional System One mode that preserves OpenAI Responses tool definitions for prompt-cache reuse while restricting callable tools.
Changes:
- Adds
restrict_callsconfiguration with compatibility fallbacks. - Applies
allowed_toolsrestrictions and execution safeguards. - Adds tests, documentation, diagnostics, localization, and version bump to 3.1.8.
| File | Description |
|---|---|
spec/support/tool_selection_helpers.rb |
Adds Responses API request capture helpers. |
spec/lib/llm_client_spec.rb |
Tests compatibility detection. |
spec/lib/bot_tool_selection_spec.rb |
Covers selection, restriction, fallback, and safety behavior. |
README.md |
Documents configuration and caching behavior. |
plugin.rb |
Bumps the plugin version. |
lib/discourse_chatbot/llm_client.rb |
Detects supported Responses configurations. |
lib/discourse_chatbot/bot.rb |
Applies definition retention and callable-tool restrictions. |
config/settings.yml |
Adds the tool-selection mode setting. |
config/locales/server.en.yml |
Adds setting and diagnostic translations. |
Review effort: Lite
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.
System One currently removes unselected tool definitions before calling the answering model. When a later query selects a different set, the changed definitions can reduce OpenAI prompt-cache reuse. This adds an optional mode that keeps eligible definitions stable and restricts callable tools through
allowed_toolson the official OpenAI Responses API. It also extends the fixed-instruction cache breakpoint to the supported GPT-6 and GPT-6.1 families.chatbot_system_one_tool_selection_modeoffers:remove_definitions(default): omit unselected descriptions to reduce input tokens.restrict_calls: retain eligible definitions and ordering while limiting API calls and execution dispatch to System One's selected tools.The settings dropdown offers
restrict_callsonly for OpenAI without Azure, with translated labels. Reload the settings page after changing provider or API type to refresh the choices. Saved preferences survive provider changes; trust-level models and custom endpoints are checked at runtime, with definition removal used for unsupported configurations.Forced local search applies only when the tool is eligible and included in the supplied definitions; regressions cover disabled embeddings and trust-level exclusion across all three request paths. Empty selections disable calls with
tool_choice: "none". Forced-tool behaviour, selection-error fallbacks, field-collection prompts and the final iteration's tool restriction remain enforced. Inner Thoughts distinguishes disabled tools from removed definitions and records the requested/effective mode and compatibility fallback reason.Official OpenAI GPT-5.6, GPT-6 and GPT-6.1 requests mark the end of the fixed developer instructions with an explicit breakpoint while retaining implicit caching. Older models, custom endpoints, Azure and other providers do not receive the new GPT-6 breakpoint configuration.
Includes README guidance and a patch bump to 3.1.8. No database migration. History windows and cache lifetime are unchanged. Cache savings depend on the rest of the prompt and should be measured using the existing usage reporting.
Validation: 307 backend examples pass; targeted lint and YAML parsing pass. Regressions cover stable definitions across exchanges and tool-loop iterations, changing allowed sets, empty selections, forced tools, selection failure, disabled selection, prevention of excluded field-writing tool execution, provider-aware settings choices, saved preferences, and GPT-5.6/GPT-6 breakpoint request formats and compatibility exclusions. API responses are mocked; no live cache-hit or billing comparison is claimed.
OpenAI documents these approaches in its prompt-caching guidance, breakpoint guidance, and tool-choice guide.