Adapter
Custom adapter
Implement provider-agnostic completion and embedding behavior.
Contracts
MemoGrafter depends on small LLM and embedding interfaces so provider SDK details remain outside the memory pipelines.
adapter.ts
class MyLLMAdapter implements LLMAdapter {
async complete(messages: Message[], system?: string): Promise<string> {
return provider.complete({ messages, system });
}
}Implementation checklist
Map MemoGrafter roles and system context to the provider request.
Return plain completion text.
Normalize provider failures without hiding useful context.
Add timeouts, retries, and observability at the adapter boundary.
Validation
Test system-prompt handling.
Test empty and long inputs.
Test rate limits and transient failures.