Skip to content

fix(mem0_memory): create console per call so STRANDS_TOOL_CONSOLE_MODE is honored#508

Open
kimnamu wants to merge 1 commit into
strands-agents:mainfrom
kimnamu:fix/mem0-console-mode
Open

fix(mem0_memory): create console per call so STRANDS_TOOL_CONSOLE_MODE is honored#508
kimnamu wants to merge 1 commit into
strands-agents:mainfrom
kimnamu:fix/mem0-console-mode

Conversation

@kimnamu

@kimnamu kimnamu commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Thank you for maintaining strands-agents/tools. This is a small, low-risk fix for #377.

Problem (reproduced)

mem0_memory ignores STRANDS_TOOL_CONSOLE_MODE: the tool keeps printing verbose Rich panels even when the env var is set to disabled (per @javierlarota's report).

Cause — import-time vs call-time

src/strands_tools/mem0_memory.py created the Rich console once at module import time:

# Initialize Rich console
console = console_util.create()

console_util.create() reads STRANDS_TOOL_CONSOLE_MODE at 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.py tool 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.py was the only one creating it at import time.

Change

Move the console creation from module scope into the mem0_memory() function, exactly matching the memory.py sibling. Source change is -3 / +2 lines.

Before / After

Minimal repro (no mem0 backend needed — isolates the console mechanism): import the module with STRANDS_TOOL_CONSOLE_MODE=enabled, then set it to disabled after import (the report's situation):

Item Before (import-time global) After (this PR)
Console honors env var set after import ❌ No — stays verbose despite =disabled ✅ Yes — silent
Behavior matches sibling memory.py ❌ No ✅ Yes
Public API / tool signature / TOOL_SPEC unchanged ✅ unchanged
ToolResult content / status / ordering unchanged ✅ unchanged
Other actions (store/get/list/retrieve/delete/history) unchanged ✅ unchanged
### import with =enabled, then set =disabled (the report's situation)
# BEFORE (import-time global):
import-time global still verbose? True    <- BUG: still prints despite =disabled
console_util.create() verbose now? False  <- correctly silent

# AFTER (this PR — console created per call):
no import-time global (console is created per call)
console_util.create() verbose now? False  <- correctly silent

Tests (red / green)

Added test_console_mode_read_at_call_time in tests/test_mem0.py (reuses the existing fixtures). It spies on console_util.create and 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:

# Source reverted to import-time global, test kept:
>       assert seen_modes == ["enabled"]
E       AssertionError: assert [] == ['enabled']
E         Right contains one more item: 'enabled'
FAILED tests/test_mem0.py::test_console_mode_read_at_call_time
1 failed

With the fix restored, the full mem0 suite passes:

.............                                                            [100%]
13 passed in 0.89s

ruff format --check and ruff check pass 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.

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] mem0_memory tool ignores STRANDS_TOOL_CONSOLE_MODE

1 participant