Skip to content

fix(memory/mem0): recall on the current question + stronger search guidance - #55535

Merged
kshitijk4poor merged 4 commits into
NousResearch:mainfrom
kartik-mem0:fix/mem0-retrieval-prefetch
Jun 30, 2026
Merged

fix(memory/mem0): recall on the current question + stronger search guidance#55535
kshitijk4poor merged 4 commits into
NousResearch:mainfrom
kartik-mem0:fix/mem0-retrieval-prefetch

Conversation

@kartik-mem0

@kartik-mem0 kartik-mem0 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Bug

prefetch(query) was not reliably giving the model memory for the question being answered. The old Mem0 prefetch path was tied to a post-turn warm, so first-turn recall could be empty and later turns could surface stale/previous-turn context.

Changes (Mem0 plugin only)

  • Strengthened mem0_search guidance so the model knows to use memory before answering prior-context questions, and to run multiple/follow-up searches for multi-hop questions.
  • Strengthened the Mem0 system prompt block with the same “use memory before answering context-dependent questions” guidance.
  • Added current-query prefetch at turn start: on_turn_start() starts a Mem0 search for the user’s current query.
  • prefetch(query) now consumes the current-query result if ready, or waits up to _PREFETCH_WAIT_SECS = 1.5 before skipping injection.
  • Slow Mem0 search no longer stalls the turn indefinitely; mem0_search remains the fallback tool when prefetch is not ready.

The MemoryProvider interface and core agent loop stay unchanged.

Tests

  • tests/plugins/memory/test_mem0_v3.py
    • prefetch searches the current query
    • first-call recall works without a previous warm
    • turn-start queues current-query recall
    • slow search returns quickly and can be consumed later
    • empty results / circuit breaker behavior stay safe
  • tests/run_agent/test_run_agent.py::TestMemoryProviderTurnStart
    • preserves the contract that on_turn_start() runs before prefetch_all()

Latest local verification:

pytest tests/plugins/memory/test_mem0_v3.py tests/run_agent/test_run_agent.py::TestMemoryProviderTurnStart
# 51 passed

…idance

Mem0 scored 59.3% on ENACT vs 72.8% full-context; the gap is retrieval.
Two plugin-level causes, both fixed here:

1. Prefetch was mis-keyed. prefetch(query) ignored its argument and returned
   whatever the background queue_prefetch() had warmed from the PREVIOUS turn
   (run post-turn in run_agent.py). So turn 1 auto-injected nothing and turn N
   injected turn N-1's memories — for a one-question-per-turn QA eval, recall
   was empty or off-topic. prefetch() now does a synchronous backend search on
   the CURRENT query (filters=_read_filters(), top_k=10, rerank=True), formats
   hits under "## Mem0 Memory", gated by the circuit breaker and best-effort.
   queue_prefetch() is dropped (falls back to the ABC no-op) so no wasted
   post-turn search fires.

2. Weak guidance. system_prompt_block() now tells the agent it has persistent
   memory and to search BEFORE answering anything context-dependent, and to run
   several/follow-up searches for multi-hop questions instead of stopping at
   one. mem0_search/mem0_list descriptions get "when to use" + multi-hop hints.

Provider interface and agent loop untouched. Rolling-summary (mem0 core) and
SDK version (already on latest 2.0.10) are out of scope and unchanged.

Tests: new TestMem0Prefetch (search keyed on query, recall on first call,
breaker/empty guards, queue_prefetch fires no search). 520 memory tests pass.

Bumps plugin 1.1.0 -> 1.2.0.
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers P3 Low — cosmetic, nice to have labels Jun 30, 2026
- prefetch searches the current question (daemon thread, 3s bounded join)
  instead of returning the previous turn's background warm — fixes empty
  first-turn recall and stale/off-topic recall on later turns
- drop the now-redundant queue_prefetch warm (ABC no-op)
- all 5 tool descriptions + system prompt state when to use them

@tonydwb tonydwb 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.

Code Review Summary

Verdict: LGTM

Clean mem0 prefetch fix (3 files, +123 lines). The old implementation used queue_prefetch to warm memories from the PREVIOUS turn, leaving the first turn empty and later turns stale. The new implementation searches on the CURRENT question synchronously with a 3s bounded wait.

Looks Good

  • Correctly searches the current query instead of a stale background warm
  • Bounded join (3s) prevents slow backends from stalling the turn
  • Circuit breaker integration preserved
  • Tool descriptions improved with clearer usage guidance
  • Good test coverage for the new prefetch behavior

Note

  • The queue_prefetch method is removed — verify no external callers depend on it

Reviewed by Hermes Agent

@kshitijk4poor
kshitijk4poor merged commit c6eb7f9 into NousResearch:main Jun 30, 2026
31 checks passed
dtera pushed a commit to dtera/hermes-agent that referenced this pull request Jul 1, 2026
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Jasper6439 pushed a commit to Jasper6439/hermes-agent that referenced this pull request Jul 5, 2026
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants