Skip to content

refactor(plugin): hand mem0 search decisions to the agent#4992

Open
gabrielstein-mem0 wants to merge 3 commits intomainfrom
refactor/improvve-plugin-search
Open

refactor(plugin): hand mem0 search decisions to the agent#4992
gabrielstein-mem0 wants to merge 3 commits intomainfrom
refactor/improvve-plugin-search

Conversation

@gabrielstein-mem0
Copy link
Copy Markdown
Contributor

@gabrielstein-mem0 gabrielstein-mem0 commented Apr 27, 2026

Description

The on_user_prompt.sh hook previously ran a blind semantic search against the user's raw prompt and injected the top-5 results into context on every turn. This wasted API calls on prompts where memory wouldn't help, and the raw-prompt-as-query approach produced low-recall results that crowded the context window with noise.

This PR restructures the hook to be a prompt-injection point rather than a search-execution point. On every substantive prompt, the hook now injects a decision rubric:

  • WHEN to search — references to past work/decisions, decision-style framing ("how should we"), debugging, work that touches the user's stack/tools/preferences, or non-trivial tasks in a known project.
  • WHEN to skip — acknowledgements, write triggers (user stating new info), pure syntax questions, or repeat searches in the same scope this turn.
  • HOW to search well — 2–4 parallel search_memories calls with different angles, noun-phrased queries ("auth module decisions" vs full sentences), metadata.type filters scoped by intent (decision / anti_pattern / user_preference / convention).

The agent — which has full conversation context — decides whether and how to search. The skill (mem0-codex/SKILL.md) is updated with the same rules plus a worked example, so the agent has both a load-time reference (skill) and per-turn reinforcement (hook).

The on_user_prompt hook previously ran a blind semantic search using the
raw user prompt as the query and injected the top results unconditionally.
That undermined the agent's judgment with low-quality context and made
heavy API calls on prompts where memory wouldn't help.

Replace with a decision rubric injected into context per turn. The agent
decides whether memory would improve the response and, if so, runs targeted
searches with metadata.type filters and proper query phrasing. Mirror the
same rules in mem0-codex/SKILL.md so the skill (loaded once) and the hook
(re-asserted per turn) agree.

Skip gates preserved: prompts under 20 chars and missing MEM0_API_KEY.

- on_user_prompt.sh: API call replaced with stdout rubric injection
- hooks.json / codex-hooks.json: statusMessage updated to match new behavior
- mem0-codex/SKILL.md: "On every new task" rewritten with search/skip rules,
  query phrasing guidance, metadata filter table, and a worked example
The plain-string source ("./mem0-plugin") parsed as a marketplace
without errors but caused /plugin install to fail with "Plugin 'mem0'
not found in any marketplace". Claude Code and Cursor require the
object form: {"source": "directory", "path": "..."}. Codex already
uses the object form (with "source": "local") in .agents/plugins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant