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
}
'import requests
url = "https://api.memoclaw.com/v1/context"
payload = {
"query": "<string>",
"namespace": "<string>",
"session_id": "<string>",
"agent_id": "<string>",
"max_memories": 123,
"max_tokens": 123,
"format": "<string>",
"include_metadata": True,
"summarize": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
query: '<string>',
namespace: '<string>',
session_id: '<string>',
agent_id: '<string>',
max_memories: 123,
max_tokens: 123,
format: '<string>',
include_metadata: true,
summarize: true
})
};
fetch('https://api.memoclaw.com/v1/context', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.memoclaw.com/v1/context",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '<string>',
'namespace' => '<string>',
'session_id' => '<string>',
'agent_id' => '<string>',
'max_memories' => 123,
'max_tokens' => 123,
'format' => '<string>',
'include_metadata' => true,
'summarize' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.memoclaw.com/v1/context"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"namespace\": \"<string>\",\n \"session_id\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"max_memories\": 123,\n \"max_tokens\": 123,\n \"format\": \"<string>\",\n \"include_metadata\": true,\n \"summarize\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.memoclaw.com/v1/context")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"namespace\": \"<string>\",\n \"session_id\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"max_memories\": 123,\n \"max_tokens\": 123,\n \"format\": \"<string>\",\n \"include_metadata\": true,\n \"summarize\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.memoclaw.com/v1/context")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"<string>\",\n \"namespace\": \"<string>\",\n \"session_id\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"max_memories\": 123,\n \"max_tokens\": 123,\n \"format\": \"<string>\",\n \"include_metadata\": true,\n \"summarize\": true\n}"
response = http.request(request)
puts response.read_body{
"context": "<string>",
"memories_used": 123,
"tokens": 123
}API Reference
Assemble Context
POST /v1/context — Assemble a context block from memories for LLM prompts.
POST
/
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
}
'import requests
url = "https://api.memoclaw.com/v1/context"
payload = {
"query": "<string>",
"namespace": "<string>",
"session_id": "<string>",
"agent_id": "<string>",
"max_memories": 123,
"max_tokens": 123,
"format": "<string>",
"include_metadata": True,
"summarize": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
query: '<string>',
namespace: '<string>',
session_id: '<string>',
agent_id: '<string>',
max_memories: 123,
max_tokens: 123,
format: '<string>',
include_metadata: true,
summarize: true
})
};
fetch('https://api.memoclaw.com/v1/context', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.memoclaw.com/v1/context",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'query' => '<string>',
'namespace' => '<string>',
'session_id' => '<string>',
'agent_id' => '<string>',
'max_memories' => 123,
'max_tokens' => 123,
'format' => '<string>',
'include_metadata' => true,
'summarize' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.memoclaw.com/v1/context"
payload := strings.NewReader("{\n \"query\": \"<string>\",\n \"namespace\": \"<string>\",\n \"session_id\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"max_memories\": 123,\n \"max_tokens\": 123,\n \"format\": \"<string>\",\n \"include_metadata\": true,\n \"summarize\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.memoclaw.com/v1/context")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"<string>\",\n \"namespace\": \"<string>\",\n \"session_id\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"max_memories\": 123,\n \"max_tokens\": 123,\n \"format\": \"<string>\",\n \"include_metadata\": true,\n \"summarize\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.memoclaw.com/v1/context")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"<string>\",\n \"namespace\": \"<string>\",\n \"session_id\": \"<string>\",\n \"agent_id\": \"<string>\",\n \"max_memories\": 123,\n \"max_tokens\": 123,\n \"format\": \"<string>\",\n \"include_metadata\": true,\n \"summarize\": true\n}"
response = http.request(request)
puts response.read_body{
"context": "<string>",
"memories_used": 123,
"tokens": 123
}This endpoint requires an x402 payment header.
Request Body
string
Natural language query describing what context is needed. Used to find relevant memories.
string
Filter by namespace.
string
Filter by session ID.
string
Filter by agent ID.
number
Maximum number of memories to include. Default:
10. Max: 100.number
Target maximum tokens for the context. Default:
4000. Range: 100-16000.string
Output format:
text (plain text) or structured (JSON with metadata). Default: text.boolean
Include memory metadata (tags, importance, type) in the output. Default:
false.boolean
Use LLM to summarize multiple similar memories into fewer entries. Default:
false.Response (200 OK)
string
The assembled context text or JSON.
number
Number of memories included in the context.
number
Approximate token count of the context.
Example
curl -X POST https://api.memoclaw.com/v1/context \
-H "Content-Type: application/json" \
-d '{
"query": "user preferences and project context",
"max_memories": 5,
"max_tokens": 2000,
"format": "text"
}'
const response = await fetch("https://api.memoclaw.com/v1/context", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: "user preferences and project context",
max_memories: 5,
max_tokens: 2000,
format: "text",
}),
});
const data = await response.json();
from memoclaw import MemoClaw
client = MemoClaw()
result = client.assemble_context(
query="user preferences and project context",
max_memories=5,
max_tokens=2000,
format="text",
)
print(result.context)
import { MemoClawClient } from "memoclaw";
const client = new MemoClawClient();
const result = await client.assembleContext({
query: "user preferences and project context",
maxMemories: 5,
maxTokens: 2000,
format: "text",
});
console.log(result.context);
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
}
⌘I