fix(mem0_memory): create console per call so STRANDS_TOOL_CONSOLE_MODE is honored#508
Open
kimnamu wants to merge 1 commit into
Open
fix(mem0_memory): create console per call so STRANDS_TOOL_CONSOLE_MODE is honored#508kimnamu wants to merge 1 commit into
kimnamu wants to merge 1 commit into
Conversation
…E is honored The Rich console was created once at module import time, so console_util.create() read STRANDS_TOOL_CONSOLE_MODE before the env var was set by the application and the frozen console ignored later changes. Create the console inside the tool function, matching the memory.py sibling tool, so each call honors the env var. Fixes strands-agents#377 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for maintaining
strands-agents/tools. This is a small, low-risk fix for #377.Problem (reproduced)
mem0_memoryignoresSTRANDS_TOOL_CONSOLE_MODE: the tool keeps printing verbose Rich panels even when the env var is set todisabled(per @javierlarota's report).Cause — import-time vs call-time
src/strands_tools/mem0_memory.pycreated the Rich console once at module import time:console_util.create()readsSTRANDS_TOOL_CONSOLE_MODEat call time. Because the tool is imported during agent setup — before the application sets the env var — the console is frozen to the value present at import and never reflects later changes.This is a single missing spot in an already-established convention: the sibling
memory.pytool already creates its console inside the tool function (memory.py~L683:console = console_util.create()), so it honors the env var on every call.mem0_memory.pywas the only one creating it at import time.Change
Move the console creation from module scope into the
mem0_memory()function, exactly matching thememory.pysibling. Source change is-3 / +2lines.Before / After
Minimal repro (no mem0 backend needed — isolates the console mechanism): import the module with
STRANDS_TOOL_CONSOLE_MODE=enabled, then set it todisabledafter import (the report's situation):=disabledmemory.pyTOOL_SPECToolResultcontent / status / orderingTests (red / green)
Added
test_console_mode_read_at_call_timeintests/test_mem0.py(reuses the existing fixtures). It spies onconsole_util.createand asserts it runs during the tool call, observing the env var value set after import.Reverting only the source fix (keeping the new test) shows it catches the bug:
With the fix restored, the full mem0 suite passes:
ruff format --checkandruff checkpass on both changed files.A larger, more complete rework (e.g. threading a console through, or native runtime config) would be out of scope; this PR is the minimal change that resolves the reported issue by aligning with the existing sibling pattern.
Fixes #377
This contribution was prepared with the help of an AI agent (Claude Code); a human reviewed the change, the reasoning, and the test results (red/green) before submitting.