Skip to content

fix(product): Correctly handle nested memory structure in chat methods - #148

Closed
muzzlol wants to merge 3 commits into
MemTensor:mainfrom
muzzlol:fix/nested-data-handling
Closed

fix(product): Correctly handle nested memory structure in chat methods#148
muzzlol wants to merge 3 commits into
MemTensor:mainfrom
muzzlol:fix/nested-data-handling

Conversation

@muzzlol

@muzzlol muzzlol commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

Description

Summary: This PR fixes an AttributeError that occurred in both chat() and chat_with_references() when processing memory references for streaming responses. The root cause was an incorrect assumption about the data structure returned from the search method.

Fix: #(no existing issue - bug found during development)

Docs Issue/PR: (not applicable)

Reviewer: @(leave blank)

Root Cause

The super().search() method returns a list of dictionaries, where each dictionary is structured as {"cube_id": "...", "memories": [TextualMemoryItem, ...]}.

The code was incorrectly trying to access attributes like .id and .model_dump() on the outer dictionary instead of on the TextualMemoryItem objects contained within the "memories" key.

Solution

A nested loop has been added to correctly iterate through the TextualMemoryItem objects. This ensures we are operating on the actual Pydantic models and can access their attributes without error.

Checklist:

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

- Fixes AttributeError when processing references in chat() and chat_with_references().
- The search result is a list of dictionaries .
- The previous code incorrectly treated the outer dictionary as a TextualMemoryItem.
- This change adds a nested loop to correctly iterate through the TextualMemoryItem objects inside the 'memories' key, resolving the crash.
@tangg555
tangg555 requested a review from fridayL July 24, 2025 03:21

@fridayL fridayL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for the late code review.
first please change pr branch to dev
and for the code I want to clarify that at lines 757-762:

memories_list = []
memories_result = super().search(
    query, user_id, install_cube_ids=[cube_id] if cube_id else None, top_k=10
)["text_mem"]
if memories_result:
    memories_list = memories_result[0]["memories"]

I have already handled this part maybe is not very good style.
If you want to change the structure later, you'll also need to update this code accordingly.

@CaralHsi

CaralHsi commented Aug 3, 2025

Copy link
Copy Markdown
Collaborator

Please resolve the conflicts. Thanks for your contribution:)

@github-actions

github-actions Bot commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

This PR has been automatically marked as stale due to inactivity.

@github-actions github-actions Bot added the status:stale Auto-marked stale after 30d inactivity; closes 7d later unless exempt. label Sep 3, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically closed due to inactivity.

@github-actions github-actions Bot closed this Sep 10, 2025
pull Bot pushed a commit to longduoduo112/MemOS that referenced this pull request Aug 18, 2026
…4b4d8b2

e4b4d8b2 Merge pull request MemTensor#157 from MemTensor/docs-sync/openclaw-cloud-auto-draft-release
28eb5f81 ci: automate cloud plugin draft releases
bf3f9b32 Merge pull request MemTensor#156 from MemTensor/fix/npm-publish-propagation
df4634d3 ci: validate release fixes before merge
0da6e0a9 ci: harden npm release propagation verification
a3176616 Merge pull request MemTensor#155 from EF1874/test
2ff7ec75 0.1.20
09714e85 Merge pull request MemTensor#153 from MemTensor/docs-sync/openclaw-cloud-main-source-release
d33d77fb ci: publish reviewed main versions without action PRs
066f330d Merge pull request MemTensor#152 from EF1874/test
50ae8cc5 Merge pull request MemTensor#149 from MemTensor/docs-sync/openclaw-cloud-release-quality
1b027080 ci: surface cloud workflow contract failures
31a17497 ci: isolate read-only release dry runs
8ebc5f02 ci: declare reusable publish secret
e941685b ci: minimize dry-run workflow privileges
6a8de049 ci: align prerelease and stable release channels
41201c0a ci: normalize cloud release evidence refs
8517603d ci: close cloud release failure recovery gaps
58d9efa3 ci: preserve reusable workflow token permissions
7a8cb8fd ci: pin cloud release recovery to npm source
56170ea5 0.1.20-beta.0
557c7269 Merge branch 'main' into test
4d993bcd ci: add auditable cloud release quality gates
066db592 feat: implement deduplication for agent_end snapshots and enhance API call timeout handling
8aee50e2 ci: require recovery mode for missing release metadata
ca0f2357 ci: suppress tag fetch warnings when local tags exist
b06dcf7d ci: avoid tag fetch warnings in originless tests
74d25dd5 ci: validate manual cloud release note categories
98549947 ci: cover publish confirmation guard dry runs
7c9830f4 ci: require confirmation for real cloud releases
34e0f7b2 ci: request candidate self-checks for cloud release notes
0dde13cc ci: harden cloud plugin release previews
fd4bad4c Merge pull request MemTensor#148 from MemTensor/docs-sync/openclaw-cloud-plugin-semver-previous-tag
c20bf70c fix: compare release tags with semver precedence
becc6f18 Merge pull request MemTensor#147 from MemTensor/docs-sync/openclaw-cloud-plugin-release
ef831b5d ci: validate telemetry credentials before packaging
2f43ff8c ci: resolve annotated release tags to commits
252e9608 ci: read release tag evidence from commits
7f29b992 ci: add cloud plugin release dry-run automation
d0f2cea7 ci: add OpenClaw cloud plugin release workflow
18cb8c7f Merge pull request MemTensor#140 from MemTensor/test
3b978092 Merge pull request MemTensor#135 from EF1874/test
0c2cd2a1 0.1.19
c4ab3104 0.1.19-beta.0
d053b0a2 feat: enhance OpenClaw system prompt detection and handling
e1e7fb0f 0.1.18
ce0a9e16 Merge pull request MemTensor#132 from Hun-ger/dev_gyh_260617
5152641c feat: add config UI update check
9b9e4ab2 Merge pull request MemTensor#131 from MemTensor/test
2af0cb2a Merge pull request MemTensor#129 from EF1874/test
3b0e068e 0.1.17
f7fd95e2 0.1.17-beta.0
70fb1840 feat: update MEMOS_SOURCE to append platform-specific suffixes and add corresponding tests
31d5f6a0 Merge branch 'test' of https://github.com/MemTensor/MemOS-Cloud-OpenClaw-Plugin into test
8b18998d Merge pull request MemTensor#127 from EF1874/test
e43380d8 Merge pull request MemTensor#123 from EF1874/test
ec9764d3 0.1.16
0d74ab93 0.1.16-beta.1
ed52b9c1 feat: extend system command detection to include 'clear' command and add internal prompt patterns for session management
00edb855 0.1.16-beta.0
9c773370 feat: enhance memory section handling by adding tool memory support and simplifying filtering logic
f7c1edb9 feat: refactor system event detection logic into dedicated functions for clarity and reuse
eb2bddc8 feat: add function to strip leading system notes from text input
bf25eb78 feat: implement system event detection in recall and agent end hooks to skip processing for heartbeat and command events
869217d7 Merge pull request MemTensor#122 from MemTensor/test
306841f2 feat: update recall hook registration to use before_prompt_build for newer OpenClaw hosts and add tests for version compatibility
7e8304a7 Merge pull request MemTensor#120 from EF1874/test
a63116fc 0.1.15
5d2bb28e 0.1.15-beta.0
b4af645e feat: add activation hooks to plugin configurations and improve hook policy handling in index.js
083b6e4b Merge pull request MemTensor#119 from MemTensor/test
3b5ddaa4 Merge pull request MemTensor#118 from EF1874/test
e931499a 0.1.14
1a86dc0d 0.1.14-beta.0
d0b88342 feat: add version detection and comparison utilities for host CLI
f7d19029 refactor: enhance configuration UI and improve session handling logic
d982aa0f chore: remove HOOK.md file and clean up package.json by eliminating unused hooks
03fcc33c Merge pull request MemTensor#115 from MemTensor/test
1e77054b 0.1.13
19e8eb38 0.1.13-beta.1
b32b493a Merge pull request MemTensor#113 from Hun-ger/fix_cloud_plugin_filter
23a48675 fix:fix filter params
de07588e 0.1.13-beta.0
4451c8a5 Merge pull request MemTensor#111 from Hun-ger/fix_cloud_plugin_filter
4c84c6c3 fix typos
9f663e50 Merge pull request MemTensor#110 from Hun-ger/fix_cloud_plugin_filter
92e66d30 feat: Add shared support knowledgebase for multi-agent reuse

git-subtree-dir: apps/MemOS-Cloud-OpenClaw-Plugin
git-subtree-split: e4b4d8b2ad3c50449a1b75f04eee985ebdb324a9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:stale Auto-marked stale after 30d inactivity; closes 7d later unless exempt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants