Skip to content

Conversation

jona62
Copy link
Contributor

@jona62 jona62 commented Sep 30, 2025

Description

Enhanced the get_or_create_memory method to provide true idempotency by validating existing memory strategies against provided strategies. Added comprehensive strategy validation utilities with deep comparison capabilities, camelCase/snake_case normalization, and support for custom memory strategies.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Testing

  • Unit tests pass locally
  • Integration tests pass (if applicable)
  • Test coverage remains above 80%
  • Manual testing completed

Checklist

  • My code follows the project's style guidelines (ruff/pre-commit)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Security Checklist

  • No hardcoded secrets or credentials
  • No new security warnings from bandit
  • Dependencies are from trusted sources
  • No sensitive data logged

Breaking Changes

List any breaking changes and migration instructions:

N/A - Fully backward compatible. Validation only occurs when strategies are explicitly provided to get_or_create_memory.

Additional Notes

Key Components Added:

  • strategy_validator.py (395 lines): Universal comparison utilities with camelCase/snake_case normalization
  • CustomStrategy model (119 lines): Support for advanced memory configurations
  • 1,064+ comprehensive test cases covering all validation scenarios

Behavior:

  • Existing code continues to work unchanged
  • When strategies are provided to get_or_create_memory, validates against existing memory configuration
  • Raises descriptive ValueError on strategy mismatch to prevent silent configuration drift

Files Modified: 8 files, +1,953 lines, -93 lines

@jona62 jona62 self-assigned this Sep 30, 2025
@jona62 jona62 requested a review from bergjaak September 30, 2025 06:05
class CustomSummaryStrategy(BaseStrategy):
"""Custom summary strategy with configurable consolidation.
This strategy allows customization of consolidation using custom prompts and models.

Choose a reason for hiding this comment

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

is it really only consolidation? I didn't know that

Comment on lines +18 to +25
def _camel_to_snake(name: str) -> str:
"""Convert camelCase to snake_case."""
# Handle sequences of uppercase letters (like XMLHttpRequest -> xml_http_request)
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()

@staticmethod
def normalize_field_names(data: Any) -> Any:

Choose a reason for hiding this comment

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

im kind of surprised that there's nothing like this that comes with python out of the box (only kind of surprised)

Choose a reason for hiding this comment

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

I do wonder if it would be better to just take a dependency for these things though (all the deep compare stuff)? It seems pretty complex (though I can also see the argument that this logic should never have to change, and we will never have to re-visit this logic, and this logic will actually be more stable if we directly implement this rather than take a dependency)

logger = logging.getLogger(__name__)


class UniversalComparator:

Choose a reason for hiding this comment

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

I feel like there's got to be a simpler way to evaluate equality of Strategies than this 400 line class. Would like to think about it a little more

@jona62 jona62 merged commit 29bab2e into aws:main Sep 30, 2025
9 of 10 checks passed
@jona62 jona62 deleted the feat/get_or_create_memory_idempotency branch September 30, 2025 16:09
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