From 88ffede2d8a641872ddb293e626c98eaaf559cbd Mon Sep 17 00:00:00 2001 From: Ayush Sahay Chaudhary <44045943+ayushere@users.noreply.github.com> Date: Wed, 13 May 2026 08:15:26 +0530 Subject: [PATCH] fix: skip memory prefetch on trivial user prompts (greetings) When the user sends a greeting (hi/hey/hello) or trivial acknowledgement, skip memory-provider prefetch_all() to prevent context-dumping on sessions where the user is simply opening a conversation. This fixes the case where memory context containing instruction-like directives overrode the agent's configured persona on short first-turn messages. Additionally, add greeting words (hi/hey/hello/yo/sup) to the Honcho plugin's _TRIVIAL_PROMPT_RE so the plugin-level injection gate also skips greetings. Files changed: - run_agent.py: add trivial-query gate before prefetch_all() call - plugins/memory/honcho/__init__.py: add greetings to _TRIVIAL_PROMPT_RE --- plugins/memory/honcho/__init__.py | 5 +++-- run_agent.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/plugins/memory/honcho/__init__.py b/plugins/memory/honcho/__init__.py index d97f459acef66..0dbb84ab68dae 100644 --- a/plugins/memory/honcho/__init__.py +++ b/plugins/memory/honcho/__init__.py @@ -988,11 +988,12 @@ class HonchoMemoryProvider(MemoryProvider): return r return "" - # Prompts that carry no semantic signal — trivial acknowledgements, slash - # commands, empty input. Skipping injection here saves tokens and prevents + # Prompts that carry no semantic signal — trivial acknowledgements, greetings, + # slash commands, empty input. Skipping injection here saves tokens and prevents # stale user-model context from derailing one-word replies. _TRIVIAL_PROMPT_RE = re.compile( r'^(yes|no|ok|okay|sure|thanks|thank you|y|n|yep|nope|yeah|nah|' + r'hi|hey|hello|yo|sup|' r'continue|go ahead|do it|proceed|got it|cool|nice|great|done|next|lgtm|k)$', re.IGNORECASE, ) diff --git a/run_agent.py b/run_agent.py index f9eaee85af67b..6c35dbbcf2594 100644 --- a/run_agent.py +++ b/run_agent.py @@ -12118,11 +12118,27 @@ class AIAgent: # 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. + # + # Skip prefetch on trivial prompts (greetings, acknowledgements) to + # prevent memory-context injection on turns that carry no semantic signal. + _TRIVIAL_QUERY_RE = re.compile( + r'^(yes|no|ok|okay|sure|thanks|thank you|y|n|yep|nope|yeah|nah|' + r'hi|hey|hello|yo|sup|' + r'continue|go ahead|do it|proceed|got it|cool|nice|great|done|next|lgtm|k)$', + re.IGNORECASE, + ) + _ext_prefetch_cache = "" if self._memory_manager: try: _query = original_user_message if isinstance(original_user_message, str) else "" - _ext_prefetch_cache = self._memory_manager.prefetch_all(_query) or "" + _is_trivial = ( + not _query + or _query.strip().startswith("/") + or re.match(_TRIVIAL_QUERY_RE, _query.strip()) + ) + if not _is_trivial: + _ext_prefetch_cache = self._memory_manager.prefetch_all(_query) or "" except Exception: pass