diff --git a/run_agent.py b/run_agent.py index a2330f525..97f95d273 100644 --- a/run_agent.py +++ b/run_agent.py @@ -6689,10 +6689,12 @@ class AIAgent: # External memory provider: prefetch once before the tool loop. # Reuse the cached result on every iteration to avoid re-calling # prefetch_all() on each tool call (10 tool calls = 10x latency + cost). + # Use original_user_message (clean input) — user_message may contain + # injected skill content that bloats / breaks provider queries. _ext_prefetch_cache = "" if self._memory_manager: try: - _query = user_message if isinstance(user_message, str) else "" + _query = original_user_message if isinstance(original_user_message, str) else "" _ext_prefetch_cache = self._memory_manager.prefetch_all(_query) or "" except Exception: pass @@ -8666,11 +8668,13 @@ class AIAgent: _should_review_skills = True self._iters_since_skill = 0 - # External memory provider: sync the completed turn + queue next prefetch - if self._memory_manager and final_response and user_message: + # External memory provider: sync the completed turn + queue next prefetch. + # Use original_user_message (clean input) — user_message may contain + # injected skill content that bloats / breaks provider queries. + if self._memory_manager and final_response and original_user_message: try: - self._memory_manager.sync_all(user_message, final_response) - self._memory_manager.queue_prefetch_all(user_message) + self._memory_manager.sync_all(original_user_message, final_response) + self._memory_manager.queue_prefetch_all(original_user_message) except Exception: pass