[问题/Issue] 章节8.2:EpisodicMemory.get_all() returns MemoryItems with invalid metadata causing consolidate() failure

Author: McinWangCreated Jan 18, 2026Updated Aug 31, 2026
Labelsdocumentation

1. 遇到问题的章节 / Affected Chapter

Chapter8.2

2. 问题类型 / Issue Type

代码错误 / Code Error

3. 具体问题描述 / Problem Description

在使用 MemoryToolconsolidate 方法将情景记忆(episodic)整合到语义记忆(semantic)时,报错: ❌ 整合记忆失败: 'Episode' object has no attribute 'metadata'

4. 问题重现材料 / Reproduction Materials

from hello_agents.tools import MemoryTool

memory_tool = MemoryTool( user_id="demo_user", memory_types=["working", "episodic", "semantic", "perceptual"] )

memory_tool.execute("add", content="测试情景记忆", memory_type="episodic", importance=0.8 )

memory_tool.execute("consolidate", from_type="episodic", to_type="semantic", importance_threshold=0.8 )

5. 补充信息 / Additional Information

经过排查,问题可能出在 EpisodicMemory.get_all() 方法返回的 MemoryItem 对象,其 metadata 参数错误地使用了 episode.metadata,而 Episode 类并没有 metadata 属性,只有 context 存储元数据。

尝试修改: EpisodicMemory.get_all()

from hello_agents.base import MemoryItem

def get_all(self): memory_items = [] for episode in self.episodes: memory_items.append(MemoryItem( id=episode.episode_id, content=episode.content, memory_type="episodic", user_id=episode.user_id, timestamp=episode.timestamp, importance=episode.importance, metadata=episode.context # Episode 没有 metadata 属性,修改为context )) return memory_items

确认事项 / Verification

  • 我已阅读过相关章节的文档 / I have read the relevant chapter documentation
  • 我已搜索过现有的Issues,确认此问题未被报告 / I have searched existing Issues and confirmed this hasn't been reported
  • 我已尝试过基本的故障排除(如重启、重新安装依赖等) / I have tried basic troubleshooting (restart, reinstall dependencies, etc.)

Source: datawhalechina/hello-agents