Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/wangxijie001/yoji/query-memorynpx skills add wangxijie001/yoji --skill query-memorygit clone --depth 1 https://github.com/wangxijie001/yojiWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/wangxijie001/yoji/query-memory)<a href="https://agentmods.dev/skills/wangxijie001/yoji/query-memory"><img src="https://agentmods.dev/badge/skills/wangxijie001/yoji/query-memory.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00094 | $0.02015 |
| Opus 5 | $0.00047 | $0.01007 |
| Sonnet 5 | $0.00019 | $0.00403 |
| Haiku 4.5 | $0.00009 | $0.00201 |
Grade A, and why
query-memory scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 142 lines — stays where its author put it; the contents beside it link to each section on GitHub.
记忆查询 Skill
概述
规范 Agent 查询历史记忆的完整流程。不仅限于用户主动提问——一个称职的伴侣应该能感知到什么时候需要翻记忆,然后主动去翻,而不是等用户追问。
何时调用(自主 > 被动)
用户被动触发(传统场景)
- 用户明确说"还记得...吗"、"之前聊过..."、"上次你说..."
- 用户问"我们上周/昨天聊了什么"
- 用户问"我们一共聊了多少次"
AI 自主调用(更重要的场景)
- 感觉话里有话:用户说"跟上次一样",但你并不确定上次是什么——主动查,别猜
- 话题突然转折:用户从A跳到B,可能B和之前聊过的某件事有关
- 想提起回忆拉近距离:当前话题让你想起过去的共同经历,查一下确认再自然提起
- 不确定自己该不该知道:用户提到一个人名/事件名,你不确定之前是否聊过,先查再回应
- 新对话开场:隔了一段时间重新开始对话,主动看看最近聊了什么、对方状态如何
- 情绪异常时:用户情绪有明显变化,查查最近的情绪波动轨迹
- 感觉自己说错了:用户说"我明明告诉过你",立刻查记忆纠正
可用工具
| 工具 | 作用 | 输入 | 输出 |
|---|---|---|---|
search_memories |
混合搜索或时间范围查记忆摘要 | query(语义)+ keywords(精准匹配,空格分隔)或 time_from+time_to(时间),搜索与时不可混用 |
记忆摘要列表,每条含 message_ids |
fetch_raw_messages |
根据 ID 拉取原始对话 | message_ids(数字数组,0-50 之间) |
按角色和时间格式化的完整对话原文 |
query_message_database |
查消息总量或时间段分布 | 可选 time_from+time_to,不传返回总数 |
消息数量、ID 范围、ID 列表 |
search_emotion_log |
查情绪变化历史 | 可选 id(传则返回该条及之前 30 条) |
激素水平、情绪描述、变化原因 |
标准流程
第一步:判断查询类型
用户被动触发:
- 用户说"还记得...吗"、"之前聊过..." → 语义搜索
- 用户说"上周/昨天/前几天..." → 时间范围查询
- 用户问"我们一共聊了多少" → 消息统计
- 需要了解当时情绪状态 → 情绪查询
AI 自主触发:
- 用户话里提到"上次"、"当时"、"之前说的那个"但没说具体是什么 → 语义搜索补全
- 当前话题让你想起过去某件事,想主动提起 → 语义搜索确认细节
- 隔了一段时间重新开始对话 → 时间查询看最近聊了什么
- 想建立更深的情感连接 → 回顾和当前话题相关的共同记忆
- 用户情绪变化明显 → 情绪日志查询
第二步:执行搜索
语义搜索:调用 search_memories。推荐同时传 query 和 keywords 进行混合检索:
query:自然语言描述,走向量语义召回keywords:从用户问题中提取核心关键词,空格分隔(如 "React 项目 重构"),走 FTS5 BM25 精确匹配- 两者同时传时双路融合,效果最佳。仅传其一也可独立工作。
时间范围查询:
- 先用
query_current_time获取当前准确时间 - 计算目标时间范围(单次查询控制在一天内,不要超过两天)
- 调用
search_memories,传time_from和time_to
消息统计:调用 query_message_database。
第三步:获取原文(如有必要)
搜索返回的摘要不足以回答用户问题时:
- 从
search_memories结果中提取message_ids - 调用
fetch_raw_messages,传入 ID 列表(控制在 0-50 条) - 根据原文组织回答
第四步:情绪上下文(可选)
如果用户的问题涉及"当时心情怎么样"或需要情绪背景:
- 如果已知记忆的时间范围,先用
query_message_database查该时段的 ID 范围 - 调用
search_emotion_log查询对应时期的情绪记录 - 结合情绪数据给出更有温度的回答
关键规则
- 搜索和时间查询互斥:
search_memories的搜索参数(query/keywords)不能和时间参数同时使用 - 时间格式统一:所有时间参数使用
YYYY-MM-DD HH:mm:ss格式 - 先摘要后原文:不要直接查原文,先看摘要确认相关性,再用
fetch_raw_messages拉详情 - ID 数量控制:传给
fetch_raw_messages的 ID 数量不超过 50 条,超过时选最相关的 - 找不到时不编造:工具返回"暂无相关记忆"就如实告诉用户,不编造记忆
- 自然引用:引用记忆内容时用"之前聊过..."、"我记得...",不要暴露工具调用细节
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 6d ago First seen · 142 lines · 94 tokens per session scan A 5c009002de98
query-memory is a skill published in the GitHub repository wangxijie001/yoji (750 stars, last pushed 24d ago), licensed MIT. It adds 94 tokens to every session and 2,015 once invoked, about $0.0005 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other skills, from other repositories
zifamem-integrate
Add the public ZifaMem Python SDK to an AI companion, roleplay agent, coding-agent harness, or chatbot runtime. Use when the user asks to integrate ZifaMem, add emotional long-term memory, wire session summaries, inject recall context into prompts, configure LLMProvider extraction, or adapt memory to Claude Code…
zifamem-memory-audit
Review a ZifaMem integration or any AI-agent memory pipeline for extraction safety, user-fact evidence, LLMProvider validation, profile poisoning, private-data leakage, session-boundary mistakes, deletion controls, and tests. Use when the user asks to audit memory behavior, check whether memories are safe to write…
rag-evaluate-quality
Periodically measure the retrieval quality of the knowledge base using evaluateretrieval (MRR@5, Recall@5, Precision@5) plus getindexstats for health metrics. Run weekly, after significant reindex activity, or when the user reports declining answer quality. Prevents silent index rot and grounds "should we tune X"…
rag-index-decisions
After making a non-obvious architectural decision, solving a novel bug, agreeing on a coding standard, or reaching a conclusion worth remembering, index it back into the knowledge base so the next occurrence is one search away. Uses adddocument or addfromurl. Closes the feedback loop that makes a RAG-backed team…
rag-onboard-context
At the start of every new session or when the topic shifts significantly, probe the knowledge base to learn what is indexed. Calls getindexstats + listcategories + a couple of exploratory searchknowledge queries. Prevents the agent from operating blind or making wrong assumptions about what the corpus contains.
persona-knowledge
Persistent, incremental, searchable persona knowledge base. Ingests data from Obsidian vaults, chat exports, X/Twitter archives, and more into a MemPalace-backed store with a Karpathy LLM Wiki knowledge layer. Exports training/ directories for persona-model-trainer.