feat: same-turn memory retrieval in provider mode

prefetch() now reuses the in-flight background search when it matches
the current query, or falls back to a synchronous search (capped at 3s,
split across both requests in case-insensitive mode) so memories are
injected on the same turn instead of one turn behind.

- Track _prefetch_query to scope cached results to their query
- Reset _prefetch_result when starting a new background search to
  prevent stale cross-turn injection after a timed-out join
- Guard background thread writes against superseded queries
- Add optional per-request timeout override to LocalMem0Client
- Update AGENTS.md and README to describe the same-turn flow
This commit is contained in:
2026-08-15 19:52:25 +02:00
parent fad5eb7f1e
commit c79cf43ff8
4 changed files with 64 additions and 25 deletions
+2 -2
View File
@@ -43,8 +43,8 @@ curl http://localhost:8000/health
**Memory injection flow:**
1. `queue_prefetch()` — Spawns background thread on user message
2. `prefetch()`Returns cached result next turn
3. `pre_llm_call` hook — Sync prefetch for immediate injection (fallback context)
2. `prefetch()`Sync retrieval for the current query (same-turn injection); falls back to cached background result when no query is provided
3. `pre_llm_call` hook — Sync prefetch for immediate injection (plugin mode)
4. `sync_turn()` — Non-blocking server-side fact extraction
**Circuit breaker:** 5 consecutive failures → 120s cooldown.