fix(memory/mem0): recall on the current question + stronger search guidance - #55535
Merged
kshitijk4poor merged 4 commits intoJun 30, 2026
Merged
Conversation
…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.
- 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
reviewed
Jun 30, 2026
tonydwb
left a comment
There was a problem hiding this comment.
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_prefetchmethod is removed — verify no external callers depend on it
Reviewed by Hermes Agent
dtera
pushed a commit
to dtera/hermes-agent
that referenced
this pull request
Jul 1, 2026
5 tasks
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
This was referenced Aug 19, 2026
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.
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)
mem0_searchguidance so the model knows to use memory before answering prior-context questions, and to run multiple/follow-up searches for multi-hop questions.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.5before skipping injection.mem0_searchremains the fallback tool when prefetch is not ready.The
MemoryProviderinterface and core agent loop stay unchanged.Tests
tests/plugins/memory/test_mem0_v3.pytests/run_agent/test_run_agent.py::TestMemoryProviderTurnStarton_turn_start()runs beforeprefetch_all()Latest local verification:
pytest tests/plugins/memory/test_mem0_v3.py tests/run_agent/test_run_agent.py::TestMemoryProviderTurnStart # 51 passed