Skip to content

Improve OpenAI prompt caching with System One tool selection - #190

Merged
merefield merged 3 commits into
mainfrom
feature/cache-friendly-tool-selection
Oct 21, 2026
Merged

merefield merged 3 commits into
mainfrom
feature/cache-friendly-tool-selection

Conversation

@merefield

@merefield merefield commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

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_tools on 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_mode offers:

  • 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_calls only 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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_calls configuration with compatibility fallbacks.
  • Applies allowed_tools restrictions 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

@merefield merefield changed the title Preserve OpenAI prompt caching during System One tool selection Improve OpenAI prompt caching with System One tool selection Oct 21, 2026
@merefield
merefield requested a lite review from Copilot October 21, 2026 09:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Guard forced local_forum_search selection when the tool is not eligible or included in the request.

No open issues 🎉

Review effort: Lite

@merefield
merefield merged commit f694bb3 into main Oct 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants