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.
Create a package resembling:
Responsibilities:
LiteLlmModelSpecand embedding configuration into SDKLlmandEmbedderinstances.MemoryPrincipalon every scoped call.user_idmatching.Recommended service methods:
create_threadget_threadappend_turnget_messagesadd_memorysearch_memoriesupdate_memorydelete_memorydelete_threadget_summaryget_context_cardInclude request or turn IDs and deterministic message IDs for retry safety. This matters for streaming reconnects and multi-replica deployments.