Skip to content

Memory 3: Service Layer #562

Description

@gotsysdba

Create a package resembling:

src/server/app/memory/
|-- adapters.py
|-- config.py
|-- registry.py
|-- schemas.py
+-- service.py

Responsibilities:

  • Resolve the configured database pool and model credentials.
  • Translate the repository's LiteLlmModelSpec and embedding configuration into SDK Llm and Embedder instances.
  • Cache components by database, model, and configuration identity, not by user.
  • Invalidate the cache after relevant configuration or credential changes.
  • Close SDK components during application shutdown.
  • Require a MemoryPrincipal on every scoped call.
  • Always search with exact user_id matching.
  • Return project-owned Pydantic DTOs rather than exposing SDK objects directly.
  • Map SDK exceptions into stable API error categories.
  • Never log prompts, stored content, search queries, metadata, user IDs, or thread IDs.

Recommended service methods:

  • create_thread
  • get_thread
  • append_turn
  • get_messages
  • add_memory
  • search_memories
  • update_memory
  • delete_memory
  • delete_thread
  • get_summary
  • get_context_card

Include request or turn IDs and deterministic message IDs for retry safety. This matters for streaming reconnects and multi-replica deployments.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions