Skip to main content
POST
https://api.memoclaw.com
/
v1
/
context
Assemble Context
curl --request POST \
  --url https://api.memoclaw.com/v1/context \
  --header 'Content-Type: application/json' \
  --data '
{
  "query": "<string>",
  "namespace": "<string>",
  "session_id": "<string>",
  "agent_id": "<string>",
  "max_memories": 123,
  "max_tokens": 123,
  "format": "<string>",
  "include_metadata": true,
  "summarize": true
}
'
{
  "context": "<string>",
  "memories_used": 123,
  "tokens": 123
}
Price: $0.01 USDC Automatically assemble relevant memories into a context block ready for LLM prompts. This is useful for building AI assistants that need contextual memory.

Request Body

query
string
Natural language query describing what context is needed. Used to find relevant memories.
namespace
string
Filter by namespace.
session_id
string
Filter by session ID.
agent_id
string
Filter by agent ID.
max_memories
number
Maximum number of memories to include. Default: 10. Max: 100.
max_tokens
number
Target maximum tokens for the context. Default: 4000. Range: 100-16000.
format
string
Output format: text (plain text) or structured (JSON with metadata). Default: text.
include_metadata
boolean
Include memory metadata (tags, importance, type) in the output. Default: false.
summarize
boolean
Use LLM to summarize multiple similar memories into fewer entries. Default: false.

Response (200 OK)

context
string
The assembled context text or JSON.
memories_used
number
Number of memories included in the context.
tokens
number
Approximate token count of the context.

Example

curl -X POST https://api.memoclaw.com/v1/context \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "query": "user preferences and project context",
    "max_memories": 5,
    "max_tokens": 2000,
    "format": "text"
  }'
Response
{
  "context": "User preferences:\n- Prefers dark mode\n- Uses vim keybindings\n- Timezone: PST\n\nProject context:\n- Using PostgreSQL 15 with pgvector\n- Deploy to staging before production",
  "memories_used": 5,
  "tokens": 180
}
Response (structured format)
{
  "context": {
    "memories": [
      {
        "content": "User prefers dark mode",
        "importance": 0.8,
        "memory_type": "preference",
        "tags": ["ui"],
        "source": "recall"
      },
      {
        "content": "Uses vim keybindings",
        "importance": 0.7,
        "memory_type": "preference",
        "tags": ["editor"],
        "source": "recall"
      }
    ]
  },
  "memories_used": 2,
  "tokens": 85
}