fix(agent): gate memory + context engine tool injection on enabled_toolsets (#5544)#30177
Merged
Conversation
MemoryManager.get_all_tool_schemas() output was appended to AIAgent.tools unconditionally — bypassing the enabled_toolsets / platform_toolsets filter. Setting `platform_toolsets: telegram: []` had no effect: fact_store and other memory provider tools still leaked into the tool surface on every session. Impact on local models (per @thundercat49's benchmarks on Qwen3-30B-A3B Q4_K_M / RTX 3090): tool-formatted prompts process at 134 tok/s vs 1,230 tok/s for plain text. With 8 memory tool schemas injected, a simple 'hello' on Telegram took ~42s instead of ~1.7s. Small models also entered tool-call loops when memory tools were the only tools present. Gate condition (matches the natural meaning of enabled_toolsets): None → no filter, inject (backward compat) contains 'memory' → user opted in, inject otherwise (including []) → skip injection Co-authored-by: Teknium <127238744+teknium1@users.noreply.github.com>
The memory-provider gate added in the prior commit closes one of two blind-injection sites in agent_init.py. The context engine block (lines ~1445) follows the identical pattern: agent.context_compressor.get_tool_schemas() (lcm_grep, lcm_describe, lcm_expand) was appended to agent.tools unconditionally, ignoring enabled_toolsets. Same bug class, same local-model latency penalty, same one-line gate — using 'context_engine' as the toolset name (matches the existing plugin-system convention in plugins.py, plugins_cmd.py, etc.). Also adds Lempkey to scripts/release.py AUTHOR_MAP for the prior commit's authorship.
Contributor
🔎 Lint report:
|
1 task
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.
Closes #5544. Salvages #5788.
Summary
platform_toolsets: telegram: []now actually means "no tools on Telegram."Previously, memory-provider tools (
fact_storeetc.) and context-engine tools(
lcm_grepetc.) leaked into the tool surface regardless of the platform'senabled_toolsetsconfiguration — bypassing the toolset filter that gates everyother tool category.
Root cause
Two blind-injection sites in
agent/agent_init.pyappended tool schemas toagent.toolsunconditionally afterget_tool_definitions(enabled_toolsets=...)ran:
agent._memory_manager.get_all_tool_schemas()(~line 1128)agent.context_compressor.get_tool_schemas()(~line 1448)Both ignored
agent.enabled_toolsetsentirely.Impact (from @thundercat49's benchmarks on Qwen3-30B-A3B Q4_K_M / RTX 3090)
A simple "hello" on Telegram with
telegram: []took ~42 s instead of ~1.7 s.Small local models also entered tool-call loops when memory tools were the only
tools present.
Cloud APIs masked this — prompt processing is near-instant regardless of tool
count, so the bug was invisible to most users.
Fix
Gate both injection sites on
agent.enabled_toolsets(matches the naturalinterpretation of the existing toolset filter):
enabled_toolsetsNone'memory''context_engine'[])Changes
agent/agent_init.pytests/agent/test_memory_provider.pyscripts/release.pyValidation
Unit tests:
tests/agent/test_memory_provider.py: 60 → 74 tests, all passE2E with real
AIAgent+ a realMemoryProviderplugin:enabled_toolsetsNonefact_storeinjectedfact_storeinjected ✓[]fact_storeleaked (34 tools)fact_storeblocked ✓["terminal"]fact_storeleakedterminal+process,fact_storeblocked ✓["memory"]fact_storeinjectedfact_storeinjected ✓Notes
cherry-pick clean — file moved from
run_agent.pytoagent/agent_init.py).First commit preserves their authorship via
--author=.injection site — same bug class, same one-line gate.
test_memory_provider.py.E2E validation against the live
AIAgentwas done out-of-band.Co-authored by @Lempkey.
Reported by @thundercat49 with full latency benchmarks.