[PR #450] [MERGED] fix: rename loop variable to avoid shadowing Memory object #11163

Closed
opened 2026-06-16 06:19:50 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Shubhamsaboo/awesome-llm-apps/pull/450
Author: @awesomekoder
Created: 2/1/2026
Status: Merged
Merged: 2/1/2026
Merged by: @Shubhamsaboo

Base: mainHead: fix/memory-variable-shadowing


📝 Commits (1)

  • e2dc13f fix: rename loop variable to avoid shadowing Memory object

📊 Changes

2 files changed (+6 additions, -6 deletions)

View changed files

📝 advanced_llm_apps/llm_apps_with_memory_tutorials/ai_travel_agent_memory/travel_agent_memory.py (+3 -3)
📝 advanced_llm_apps/llm_apps_with_memory_tutorials/multi_llm_memory/multi_llm_memory.py (+3 -3)

📄 Description

Summary

Fixes #449

Problem

The loop variable memory used to iterate over memory results was shadowing the Memory object from the mem0 library. This caused an AttributeError: 'dict' object has no attribute 'add' when memory.add() was called later in the code.

# Bug: 'memory' loop variable overwrites the Memory object
for memory in relevant_memories["results"]:
    if "memory" in memory:
        context += f"- {memory['memory']}\n"

# Later fails because 'memory' is now a dict, not Memory
memory.add(prompt, user_id=user_id)  # AttributeError!

Solution

Renamed the loop variable from memory to mem, which matches the pattern already used elsewhere in the codebase (e.g., in the "View My Memory" sections).

Files Changed

  • advanced_llm_apps/llm_apps_with_memory_tutorials/ai_travel_agent_memory/travel_agent_memory.py
  • advanced_llm_apps/llm_apps_with_memory_tutorials/multi_llm_memory/multi_llm_memory.py

Testing

  • Verified syntax with python -m py_compile
  • Tested logic flow to confirm memory.add() works after the loop

Thanks to @Veeksha-c for reporting this issue!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Shubhamsaboo/awesome-llm-apps/pull/450 **Author:** [@awesomekoder](https://github.com/awesomekoder) **Created:** 2/1/2026 **Status:** ✅ Merged **Merged:** 2/1/2026 **Merged by:** [@Shubhamsaboo](https://github.com/Shubhamsaboo) **Base:** `main` ← **Head:** `fix/memory-variable-shadowing` --- ### 📝 Commits (1) - [`e2dc13f`](https://github.com/Shubhamsaboo/awesome-llm-apps/commit/e2dc13fb21a6a3bc5f1d436e1bf2f3ae84571858) fix: rename loop variable to avoid shadowing Memory object ### 📊 Changes **2 files changed** (+6 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `advanced_llm_apps/llm_apps_with_memory_tutorials/ai_travel_agent_memory/travel_agent_memory.py` (+3 -3) 📝 `advanced_llm_apps/llm_apps_with_memory_tutorials/multi_llm_memory/multi_llm_memory.py` (+3 -3) </details> ### 📄 Description ## Summary Fixes #449 ## Problem The loop variable `memory` used to iterate over memory results was shadowing the `Memory` object from the mem0 library. This caused an `AttributeError: 'dict' object has no attribute 'add'` when `memory.add()` was called later in the code. ```python # Bug: 'memory' loop variable overwrites the Memory object for memory in relevant_memories["results"]: if "memory" in memory: context += f"- {memory['memory']}\n" # Later fails because 'memory' is now a dict, not Memory memory.add(prompt, user_id=user_id) # AttributeError! ``` ## Solution Renamed the loop variable from `memory` to `mem`, which matches the pattern already used elsewhere in the codebase (e.g., in the "View My Memory" sections). ## Files Changed - `advanced_llm_apps/llm_apps_with_memory_tutorials/ai_travel_agent_memory/travel_agent_memory.py` - `advanced_llm_apps/llm_apps_with_memory_tutorials/multi_llm_memory/multi_llm_memory.py` ## Testing - Verified syntax with `python -m py_compile` - Tested logic flow to confirm `memory.add()` works after the loop Thanks to @Veeksha-c for reporting this issue! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-06-16 06:19:50 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/awesome-llm-apps#11163