Skip to content

fix(memory): apply config defaults in UpdateMemoryTool, fix event memory IDs, expose backend constants#17

Merged
nkanu17 merged 1 commit into
mainfrom
fix/memory-backend-tool-fixes
Jun 18, 2026
Merged

fix(memory): apply config defaults in UpdateMemoryTool, fix event memory IDs, expose backend constants#17
nkanu17 merged 1 commit into
mainfrom
fix/memory-backend-tool-fixes

Conversation

@nkanu17

@nkanu17 nkanu17 commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to the selectable-memory-backends work (#16). These are code fixes that were developed alongside that PR but did not make it into the merge. They were recovered from a local stash and applied selectively (see "Deliberately excluded" below).

Changes

Bug fixes

  • UpdateMemoryTool ignored configured defaults. On the managed redis-agent-memory backend, namespace/user_id were read only from the caller's args, so default_namespace / default_owner_id / default_user_id were never applied when the model omitted them. The tool now resolves both through _get_namespace / _get_user_id. Covered by an updated assertion in tests/tools/test_memory_tools.py (update_kwargs now includes namespace/owner_id).
  • Event memory ID collisions. RedisLongTermMemoryService built the events memory ID using len(events), so two distinct event batches of equal length collided to the same ID and overwrote each other. The ID now incorporates each event's id and timestamp.

Type safety / public API

  • REDIS_AGENT_MEMORY_BACKEND and OPENSOURCE_AGENT_MEMORY_BACKEND are typed as Literal[...].
  • REDIS_AGENT_MEMORY_BACKEND, OPENSOURCE_AGENT_MEMORY_BACKEND, and MemoryBackendName are re-exported from adk_redis and adk_redis.memory.

Examples / tests

  • Examples and tests use the public constants instead of bare string literals.
  • Integration conftest.py accepts AGENT_MEMORY_API_KEY / AGENT_MEMORY_STORE_ID as fallbacks for the canonical REDIS_AGENT_MEMORY_* vars.

Deliberately excluded

The originating stash also contained cosmetic or [] / or {} / or "" removals in long_term_memory.py, working_memory.py, get.py, prompt.py, search.py, and a dead-code cleanup in delete.py. These were left out: several are behavior regressions (e.g. str(read_field(record, "text", "")) yields the string "None" when the field is explicitly None, and dropping or [] on for x in read_field(..., "events", []) would crash on a None field). Only the fingerprinting change from long_term_memory.py was taken.

Validation

make check is green: pyink/isort, ruff, mypy (31 source files, no issues), pytest (115 passed, 10 skipped).

…memory IDs

- UpdateMemoryTool now resolves namespace/user_id through _get_namespace and
  _get_user_id so configured default_namespace/default_owner_id/default_user_id
  are applied on the managed redis-agent-memory backend when the caller omits
  them
- RedisLongTermMemoryService derives the events memory ID from event ids and
  timestamps instead of len(events), preventing collisions between distinct
  event batches of equal length
- Type the backend constants as Literal and re-export
  REDIS_AGENT_MEMORY_BACKEND, OPENSOURCE_AGENT_MEMORY_BACKEND, and
  MemoryBackendName from adk_redis and adk_redis.memory
- Use the public constants in examples and tests; add AGENT_MEMORY_* fallbacks
  for API key and store ID in the integration conftest
Copilot AI review requested due to automatic review settings June 18, 2026 18:40
@nkanu17 nkanu17 merged commit 320ca15 into main Jun 18, 2026
4 checks passed
@nkanu17 nkanu17 deleted the fix/memory-backend-tool-fixes branch June 18, 2026 18:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR is a follow-up set of fixes and small API improvements for the selectable memory backends work, focused on making backend selection safer/less error-prone and fixing correctness issues in managed vs self-hosted memory behavior.

Changes:

  • Fix UpdateMemoryTool to apply configured default namespace and user identity when the caller omits them (managed backend).
  • Fix opensource-backend event-session ID collisions by fingerprinting event batches using event identifiers and timestamps rather than only batch length.
  • Expose backend-name constants and the MemoryBackendName type via public imports, and update tests/examples to use those constants instead of string literals.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/adk_redis/tools/memory/update.py Applies configured defaults via _get_namespace / _get_user_id and simplifies the opensource update call.
src/adk_redis/memory/long_term_memory.py Fixes event-session ID collisions for the opensource backend by using per-event IDs and timestamps in the stable ID input.
src/adk_redis/memory/_backends.py Types backend constants as Literal[...] and defines MemoryBackendName.
src/adk_redis/memory/__init__.py Re-exports backend constants and MemoryBackendName from adk_redis.memory.
src/adk_redis/__init__.py Re-exports backend constants and MemoryBackendName from the package root.
tests/tools/test_memory_tools.py Uses public backend constants and tightens the UpdateMemoryTool assertion to include resolved defaults.
tests/sessions/test_working_memory.py Uses public backend constants in config tests and backend selection cases.
tests/memory/test_long_term_memory.py Uses public backend constants for default and opensource backend assertions.
tests/integration/test_memory_backends_end_to_end.py Uses public backend constants for end-to-end backend configuration.
tests/integration/conftest.py Allows AGENT_MEMORY_API_KEY / AGENT_MEMORY_STORE_ID as fallbacks for managed-backend integration runs.
examples/travel_agent_memory_tools/travel_agent/agent.py Replaces backend string literal with exported constant default.
examples/travel_agent_memory_hybrid/travel_agent/agent.py Replaces backend string literal with exported constant default.
examples/travel_agent_memory_hybrid/main.py Uses exported backend constant as the default for env-based backend selection.
examples/simple_redis_memory/main.py Uses exported backend constant as the default for env-based backend selection.
examples/managed_memory_quickstart/main.py Replaces backend string literal with exported managed-backend constant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants