MemLibMemLib

Prepare Context

POST /memory/prepare — Context-aware memory synthesis

Endpoint

POST /v1/memory/prepare

Permission: Read


Request Body

{
  "namespace": "my-app",
  "entity": "user-123",
  "messages": [
    { "role": "user", "content": "Help me set up my workspace" }
  ],
  "maxCandidates": 20,
  "maxTokens": 500,
  "category": "preference"
}
FieldTypeRequiredDefaultDescription
namespacestringMemory namespace
entitystringEntity identifier
messagesMessage[]Conversation messages for context analysis
maxCandidatesnumber20Max memories to consider
maxTokensnumberGuide the output token budget
categorystringFilter candidates by category

Message Format

{
  "role": "user" | "assistant" | "system",
  "content": "string"
}

Response

{
  "context": "The user prefers dark mode and uses TypeScript for all projects. They work as a software engineer and their team uses React with Next.js.",
  "memoriesUsed": [
    "550e8400-e29b-41d4-a716-446655440000",
    "550e8400-e29b-41d4-a716-446655440001"
  ],
  "candidatesConsidered": 15,
  "tokenCount": 127
}
FieldTypeDescription
contextstringSynthesized briefing paragraph — ready to inject into a system prompt
memoriesUsedstring[]IDs of memories used in the synthesis
candidatesConsiderednumberTotal candidate memories evaluated
tokenCountnumberEstimated token count of the context paragraph

If no relevant memories are found, context will be empty.


curl Example

curl -X POST https://mem.anishroy.com/api/v1/memory/prepare \
  -H "Authorization: Bearer sk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "namespace": "my-app",
    "entity": "user-123",
    "messages": [
      { "role": "user", "content": "Help me plan dinner tonight" }
    ]
  }'

LLM Cost

2 LLM calls per request — one for intent analysis, one for context synthesis. See prepare() SDK reference for pipeline details.

On this page