From ebd2332db481e701a9c923dbb67011b06dbe7520 Mon Sep 17 00:00:00 2001 From: pewdiepie-archdaemon Date: Thu, 11 Jun 2026 09:49:20 +0900 Subject: [PATCH] Agent prompt builder: stop re-adding ALWAYS_AVAILABLE on top of filtered tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found the reason yesterday's tool-retrieval drop wasn't taking effect: in _build_agent_prompt, when relevant_tools was provided, it computed tool_names = set(ALWAYS_AVAILABLE) | set(relevant_tools) which silently re-added every tool get_tools_for_query had just deliberately discarded. So when a 'save this for ' query dropped manage_memory from the retrieved set, the prompt builder put it right back, and the model saw both tools again. Trust the relevant_tools set. get_tools_for_query already starts from ALWAYS_AVAILABLE — any discard there is intentional and should propagate. Only force-include ask_user and update_plan here as belt- and-suspenders since the agent loop relies on those for its own control flow. Other callers (task_scheduler) already union ALWAYS_AVAILABLE or ASSISTANT_ALWAYS_AVAILABLE into relevant_tools before passing it in, so they're unaffected. --- src/agent_loop.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/agent_loop.py b/src/agent_loop.py index b8eaa89d2..7f66a2f9c 100644 --- a/src/agent_loop.py +++ b/src/agent_loop.py @@ -1264,8 +1264,14 @@ def _build_base_prompt( disabled.add("generate_image") if relevant_tools is not None: - # RAG mode: include always-available + retrieved + admin (if needed) - tool_names = set(ALWAYS_AVAILABLE) | set(relevant_tools) + # RAG mode: trust the relevant_tools set as already-composed. + # get_tools_for_query starts from ALWAYS_AVAILABLE and may + # *discard* tools that conflict with the query's intent (e.g. + # drop manage_memory for clear contact-save patterns). Unioning + # ALWAYS_AVAILABLE back in here used to silently undo those + # drops. Only force-include the irreducible loop primitives + # (ask_user, update_plan) as belt-and-suspenders. + tool_names = set(relevant_tools) | {"ask_user", "update_plan"} if needs_admin: tool_names |= _ADMIN_TOOLS agent_prompt = _assemble_prompt(tool_names, disabled, compact=compact)