Skip to content

Conversation

cpfiffer
Copy link
Contributor

@cpfiffer cpfiffer commented Oct 1, 2025

Summary

This PR significantly enhances the AI Memory SDK with improved Letta positioning, code quality improvements, comprehensive test coverage, and practical examples.

Changes

1. Positioning & Documentation (4 commits)

  • Position SDK as lightweight wrapper around Letta's memory management

    • Updated all documentation to emphasize Letta's advanced memory capabilities
    • Clarified that SDK exposes Letta's sophisticated architecture through simplified API
  • Align terminology with Letta docs

    • Core memory → blocks in agent's context window
    • Archival memory → Letta's external long-term storage
    • Consistent use of "Letta agent" throughout
    • Replaced old "context" terminology with "subject"
  • Documentation updates

    • Main README with clear Letta positioning
    • Tutorial updated with Letta-centric language
    • TypeScript README aligned with main README
    • Python package README updated

2. Code Quality Improvements (2 commits)

  • Fixed bugs and typos

    • Fixed typo: "aleady" → "already"
    • Fixed error message to say "reset=True" instead of "unless deleted"
    • Removed unused asyncio import
  • Added timeout feature

    • wait_for_run() now has configurable timeout (300s default)
    • Raises TimeoutError when run doesn't complete in time
    • Prevents indefinite blocking
  • Enhanced docstrings

    • Improved documentation for initialize_user_memory()
    • Added comprehensive docstring for _learn_messages_sync()
    • Better parameter descriptions throughout
  • Fixed async event loop issue

    • Removed AsyncLetta client dependency
    • Converted async passage creation to synchronous
    • Fixes RuntimeError: Event loop is closed when using skip_vector_storage=False

3. Test Coverage (1 commit)

Added 13 new offline unit tests across 2 test files:

test_timeout.py (2 tests):

  • Timeout behavior in wait_for_run()
  • Default timeout handling

test_edge_cases.py (9 tests):

  • Missing subject_id error handling
  • Block reset functionality
  • Multiple blocks per subject
  • Empty block values
  • Nonexistent block returns None
  • Subject initialization with reset
  • Subject initialization without reset raises error
  • Special characters in block labels (underscores, dashes)
  • Long block values near char_limit

All tests use mocked Letta client for offline execution.

4. Practical Examples (1 commit)

Added 2 new educational examples and comprehensive guide:

archival_search.py:

  • Demonstrates semantic search with skip_vector_storage=False
  • Shows how to search conversation history
  • Example of injecting search results into context
  • ~110 lines of well-commented code

customer_support.py:

  • Real-world multi-block use case
  • Shows customer_profile, support_history, and policies blocks
  • Demonstrates how block descriptions guide agent updates
  • Production-quality example (~150 lines)

examples/README.md:

  • Complete guide to all examples (basic + advanced)
  • Selection criteria for different needs
  • Tips for building applications
  • Environment setup instructions

5. Review Cleanup (1 commit)

  • Removed unused asyncio import
  • Fixed test isolation in timeout tests
  • Updated examples list in main README

Testing

  • ✅ 13 offline unit tests passing
  • ✅ Core subject API tested
  • ✅ Timeout behavior tested
  • ✅ Edge cases and error handling tested
  • ⚠️ 1 integration test requires Letta API (test_messages.py)

Documentation

All documentation is now:

  • ✅ Consistent in terminology
  • ✅ Aligned with Letta's official docs
  • ✅ Clear about SDK being a Letta wrapper
  • ✅ Updated across Python, TypeScript, and examples

Breaking Changes

None. All changes are backward compatible.

Related Issues

Addresses documentation clarity and code quality improvements throughout the SDK.

- Context-aware APIs (Python + TS)
- Unified add_messages: user or bound-context
- Keep user-specific helpers for compatibility
- Add examples (Python/TS)
- Add offline context tests (Python/TS)
- Update docs; add src/python/README.md
- Remove sanitization; document naming conventions
…dk' to agent tags (Python + TS)\n- Include tag on initialization passages and archival messages\n- Include SDK tag in context tag helper (TS + Python)\n- Keep queries unchanged for compatibility
…+ 'user'; document SDK tagging\n\n- Python: search(user_id, query, tags=...)\n- TS: search(userId, query, tags?)\n- Docs: update search docs and add SDK tagging notes
- Python: subject_id, initialize_subject, add_messages_for_subject, subj: tags, agent name prefix
- TS: subjectId, initializeSubject, addMessagesToSubject, subj: tags, agent name prefix
- Rename examples and tests to subject variants
- Update READMEs and tutorial to Subject Model
…move user helpers down; emphasize generic memory blocks
…move user helpers down; emphasize generic memory blocks
…gement; align terminology with Letta docs (core memory, archival memory, blocks); emphasize Letta agent architecture
…t_for_run, enhance docstrings, align all docs with Letta-centric positioning
- Add test_timeout.py: verify timeout behavior in wait_for_run
- Add test_edge_cases.py: test error handling, block reset, multiple blocks, empty values, special characters, and more
- Tests run offline with mocked Letta client
- archival_search.py: demonstrates semantic search over conversation history
- customer_support.py: real-world multi-block use case (profile, history, policies)
- examples/README.md: guide to all examples with selection criteria and tips
- Remove AsyncLetta client dependency
- Convert _learn_messages to synchronous _learn_messages_sync
- Use sync client for passage creation to avoid event loop closure issues
- Passages are now created sequentially instead of in parallel (simpler and more reliable)
Change default search tags from ["ai-memory-sdk", "user"] to ["user"]
to work around Letta API issue where multi-tag searches return empty
results regardless of tag_match_mode setting.

- Update search() method to use single tag by default
- Add comprehensive bug report for Letta team
- Fixes test_messages.py::test_conversational_memory failure
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.

1 participant