Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/memos/mem_reader/read_skill_memory/process_skill_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def _extract_skill_memory_by_llm_md(
seen_messages = set()

for mem in old_memories_dict:
if mem["metadata"]["memory_type"] == "SkillMemory" and mem["metadata"]["relativity"] > 0.02:
if mem["metadata"]["memory_type"] == "SkillMemory":
old_skill_content.append(
{
"id": mem["id"],
Expand Down Expand Up @@ -524,19 +524,21 @@ def _extract_skill_memory_by_llm_md(
)
chat_history_context = chat_history_context[-chat_history_max_length:]

# Prepare prompt
lang = detect_lang(messages_context)

# Prepare old memories context
old_skill_content = (
("Exsit Skill Schemas: \n" + json.dumps(old_skill_content, ensure_ascii=False, indent=2))
"已有技能列表: \n" if lang == "zh" else "Exsit Skill Schemas: \n" +
json.dumps(old_skill_content, ensure_ascii=False, indent=2)
if old_skill_content
else ""
)
Comment on lines 531 to 536
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional expression building old_skill_content is parsed such that when lang == "zh" it always returns only the header ("已有技能列表") and never appends the JSON payload (and it will even return the header when the skill list is empty). Restructure this so the language-specific header is combined with json.dumps(...) only when the original skill list is non-empty (e.g., compute a header first, then header + dumps), otherwise use an empty string.

Copilot uses AI. Check for mistakes.

old_memories_context = "Relavant Context:\n" + "\n".join(
old_memories_context = "相关历史对话:\n" if lang == "zh" else "Relavant Context:\n" + "\n".join(
[f"{k}:\n{v}" for k, v in old_memories_context.items()]
Comment on lines +532 to 539
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling in the prompt labels: Exsit Skill Schemas / Relavant Context are misspelled. Typos in prompt text can reduce LLM instruction clarity; please correct them (e.g., Existing Skill Schemas, Relevant Context).

Copilot uses AI. Check for mistakes.
)
Comment on lines +538 to 540
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old_memories_context currently drops the actual joined history content when lang == "zh" (it becomes only "相关历史对话:\n"). This makes the prompt miss the recalled context for Chinese conversations. Build the prefix based on language, then always append the joined content (and consider returning an empty string if old_memories_context is empty).

Copilot uses AI. Check for mistakes.

# Prepare prompt
lang = detect_lang(messages_context)
template = (
SKILL_MEMORY_EXTRACTION_PROMPT_MD_ZH if lang == "zh" else SKILL_MEMORY_EXTRACTION_PROMPT_MD
)
Expand Down Expand Up @@ -570,6 +572,10 @@ def _extract_skill_memory_by_llm_md(
"[PROCESS_SKILLS] No skill memory extracted from conversation (LLM returned null)"
)
return None
# If no old skill content, set update to False (for llm hallucination)
if not old_skill_content:
skill_memory["old_memory_id"] = ''
skill_memory["update"] = False
Comment on lines +575 to +578
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hallucination guard if not old_skill_content: is now checking the post-formatted string, but old_skill_content is reassigned from a list to a string earlier. With the current formatting logic, this can become non-empty even when there are no skills (or no JSON payload), so the guard may not fire. Keep the original list in a separate variable (or check it before formatting) to decide whether to force update=False/empty old_memory_id.

Copilot uses AI. Check for mistakes.

return skill_memory

Expand Down
8 changes: 4 additions & 4 deletions src/memos/templates/skill_mem_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@
# Skill Extraction Principles
To define the content of a skill, comprehensively analyze the dialogue content to create a list of reusable resources, including scripts, reference materials, and resources. Please generate the skill according to the following principles:
1. **Generalization**: Extract abstract methodologies that can be applied across scenarios. Avoid specific details (e.g., 'travel planning' rather than 'Beijing travel planning'). Moreover, the skills acquired should be durable and effective, rather than tied to a specific time.
2. **Similarity Check**: If a similar skill exists, set "update": true and provide the "old_memory_id". Otherwise, set "update": false and leave "old_memory_id" blank.
2. **Similarity Check**: If the skill list in 'existing skill memory' is not empty and there are skills with the **same topic**, you need to set "update": true and "old_memory_id". Otherwise, set "update": false and leave "old_memory_id" empty.
3. **Language Consistency**: Keep consistent with the language of the dialogue.
4. **Historical Usage Constraint**: Use 'historically related dialogues' as auxiliary context. If the current historical messages are insufficient to form a complete skill, and the historically related dialogue can provide missing information in the messages that is related to the current task objectives, execution methods, or constraints, it may be considered.
5. If the abstract methodology you extract and an existing skill memory describe the same topic (such as the same life scenario), be sure to use the update operation rather than creating a new methodology. Properly append it to the existing skill memory to ensure fluency and retain the information of the existing methodology.
Note: If the similarity check result shows that an existing **skill** description covers the same topic, be sure to use the update operation and set old_memory_id to the ID of the existing skill. Do not create a new methodology; make sure to reasonably add it to the existing skill memory, ensuring smoothness while preserving the information of the existing methodology.

# Output Format and Field Specifications
## Output Format
Expand Down Expand Up @@ -320,10 +320,10 @@
# 技能提取原则
为了确定技能的内容,综合分析对话内容以创建可重复使用资源的清单,包括脚本、参考资料和资源,请你按照下面的原则来生成技能:
1. **通用化**:提取可跨场景应用的抽象方法论。避免具体细节(如"旅行规划"而非"北京旅行规划")。 而且提取的技能应该是持久有效的,而非与特定时间绑定。
2. **相似性检查**:如存在相似技能,设置"update": true 及"old_memory_id"。否则设置"update": false 并将"old_memory_id"留空。
2. **相似性检查**:如果‘现有技能记忆’中的技能列表不为空,且存在**相同主题**的技能,则需要设置"update": true 及"old_memory_id"。否则设置"update": false 并将"old_memory_id"留空。
3. **语言一致性**:与对话语言保持一致。
4. **历史使用约束**:“历史相关对话”作为辅助上下文,若当前历史消息不足以形成完整的技能,且历史相关对话能提供 messages 中缺失、且与当前任务目标、执行方式或约束相关的信息增量时,可以纳入考虑。
5. 如果你提取的抽象方法论和已有的技能记忆描述的是同一个主题(比如同一个生活场景),请务必使用更新操作,不要新建一个方法论,注意合理的追加到已有的技能记忆上,保证通顺且不丢失已有方法论的信息
注意:如果相似性检查结果是存在已有的**一个**技能描述的是同一个主题,请务必使用更新操作,并将old_memory_id设置为该历史技能的id,不要新建一个方法论,注意合理的追加到已有的技能记忆上,保证通顺的同时不丢失已有方法论的信息

# 输出格式的模版和字段规范描述
## 输出格式
Expand Down
Loading