fix(memory): apply config defaults in UpdateMemoryTool, fix event memory IDs, expose backend constants#17
Merged
Conversation
…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
There was a problem hiding this comment.
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
UpdateMemoryToolto 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
MemoryBackendNametype 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.
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.
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
UpdateMemoryToolignored configured defaults. On the managedredis-agent-memorybackend,namespace/user_idwere read only from the caller's args, sodefault_namespace/default_owner_id/default_user_idwere never applied when the model omitted them. The tool now resolves both through_get_namespace/_get_user_id. Covered by an updated assertion intests/tools/test_memory_tools.py(update_kwargsnow includesnamespace/owner_id).RedisLongTermMemoryServicebuilt the events memory ID usinglen(events), so two distinct event batches of equal length collided to the same ID and overwrote each other. The ID now incorporates each event'sidandtimestamp.Type safety / public API
REDIS_AGENT_MEMORY_BACKENDandOPENSOURCE_AGENT_MEMORY_BACKENDare typed asLiteral[...].REDIS_AGENT_MEMORY_BACKEND,OPENSOURCE_AGENT_MEMORY_BACKEND, andMemoryBackendNameare re-exported fromadk_redisandadk_redis.memory.Examples / tests
conftest.pyacceptsAGENT_MEMORY_API_KEY/AGENT_MEMORY_STORE_IDas fallbacks for the canonicalREDIS_AGENT_MEMORY_*vars.Deliberately excluded
The originating stash also contained cosmetic
or []/or {}/or ""removals inlong_term_memory.py,working_memory.py,get.py,prompt.py,search.py, and a dead-code cleanup indelete.py. These were left out: several are behavior regressions (e.g.str(read_field(record, "text", ""))yields the string"None"when the field is explicitlyNone, and droppingor []onfor x in read_field(..., "events", [])would crash on aNonefield). Only the fingerprinting change fromlong_term_memory.pywas taken.Validation
make checkis green: pyink/isort, ruff, mypy (31 source files, no issues), pytest (115 passed, 10 skipped).