-
Notifications
You must be signed in to change notification settings - Fork 11
Add new_session field to WorkingMemoryResponse to indicate if a session was created #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ility Add optional new_session boolean field to indicate whether a session was created (true) or already existed (false). GET endpoint now creates empty session if none exists to maintain backwards compatibility. PUT endpoint checks for existing session before setting the flag. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
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 adds a new_session
boolean field to WorkingMemoryResponse
to indicate whether a working memory session was created or already existed. The field enables better session lifecycle tracking for client applications.
- Added
new_session
field to both server and client model definitions - Modified GET endpoint to create empty sessions for backwards compatibility and set the flag appropriately
- Updated PUT endpoint to check for existing sessions before setting the flag
- Refactored client methods to return tuples instead of wrapper objects for cleaner API
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
agent_memory_server/models.py | Added new_session field to WorkingMemoryResponse model |
agent_memory_server/api.py | Updated GET/PUT endpoints to determine and set new_session flag |
agent-memory-client/agent_memory_client/models.py | Added new_session field and removed deprecated wrapper class |
agent-memory-client/agent_memory_client/client.py | Refactored methods to return tuples instead of wrapper objects |
tests/test_extraction.py | Added bertopic availability check in integration test |
tests/test_client_enhancements.py | Updated test mocks to use new tuple return format |
tests/test_client_api.py | Updated test expectations for session lifecycle behavior |
tests/test_api.py | Updated test assertions for new session creation behavior |
examples/travel_agent.py | Updated to use new tuple return format |
examples/memory_editing_agent.py | Updated to use new tuple return format |
docs/python-sdk.md | Updated documentation examples to reflect new API |
docs/memory-integration-patterns.md | Updated integration pattern examples |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
except httpx.HTTPStatusError as e: | ||
if e.response.status_code == 404: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception handling assumes the GET request will return a 404 for non-existent sessions, but based on the API changes in agent_memory_server/api.py
, the GET endpoint now creates empty sessions for backwards compatibility and should never return 404. This logic needs to be updated to match the new API behavior.
Copilot uses AI. Check for mistakes.
agent_memory_server/api.py
Outdated
# Create empty working memory for the session | ||
working_mem = WorkingMemory( | ||
messages=[], | ||
memories=[], | ||
session_id=session_id, | ||
namespace=namespace, | ||
user_id=user_id, | ||
) | ||
await working_memory.set_working_memory( | ||
working_memory=working_mem, | ||
redis_client=redis, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating and persisting an empty working memory session on every GET request when no session exists could lead to unnecessary Redis writes and storage bloat. Consider whether this backwards compatibility behavior is worth the performance cost, especially for high-traffic applications where many sessions may be created but never used.
Copilot uses AI. Check for mistakes.
…ng_memory Replace WorkingMemoryGetOrCreateResponse object access with tuple unpacking. Update documentation examples and client code to use (created, memory) format. Apply code formatting fixes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Update test to expect empty session creation instead of MemoryNotFoundError when a deleted session is accessed. The API now creates empty sessions for backwards compatibility when sessions don't exist, indicated by new_session=True in the response. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…are compatibility BREAKING CHANGES: - GET /v1/working-memory/{session_id} now returns 404 for missing sessions (proper REST behavior) - PUT /v1/working-memory/{session_id} no longer returns new_session field (not RESTful) NEW FEATURES: - Client version tracking via X-Client-Version header - Backward compatibility for old clients (<0.12.0) with deprecated behavior - New 'unsaved' field indicates when session data hasn't been persisted - Deprecation warnings logged for old client usage IMPLEMENTATION DETAILS: - Server version bumped to 0.11.0, client to 0.12.0 - Old clients get empty sessions with unsaved=true (no persistence) - New clients get 404 responses and use get_or_create_working_memory properly - Client automatically handles both 404 responses and unsaved sessions - Updated tests for both new and deprecated behavior paths This design eliminates the confusing behavior where GET would create and persist sessions, addresses performance concerns about unnecessary Redis writes, and provides proper REST semantics while maintaining backward compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Add optional new_session boolean field to indicate whether a working memory session was created (true) or already existed (false). GET endpoint creates empty session if none exists to maintain backwards compatibility. PUT endpoint checks for existing session before setting the flag.
🤖 Generated with Claude Code