Assembles conversation context from memory (default sources: episodic, semantic; include stm in enabled_sources for recent turns). The project scope is carried by the route id path parameter and the org is derived from that project. Provide a non-empty query (typically the latest user message) and the user_id whose memory to assemble.
Body
Required
Context build request
-
EnabledSources selects memory sources (stm, episodic, semantic, taxonomic, procedural); omitted defaults to episodic, semantic.
-
MaxTokens is the gross context-construction budget (not a fetch cost). After retrieval and ranking the memory server subtracts a 500-token formatting reserve, then greedily selects whole memory chunks that fit. Positive values at or below 500 leave no budget for memories. Values above 500 can still yield empty context when no chunk fits.
Minimum value is
1. -
Additional properties are allowed.
-
Minimum value is
1, maximum value is200.
Responses
-
Unsupported or malformed API version, an operation unavailable in the selected published contract, or an unacceptable representation (including unsupported media-type parameters or excluded SSE). Existing authentication, authorization, and rate-limit failures take precedence.
-
Assembled context payload
-
Invalid request body, missing user_id/query, or top_k outside 1-200
-
Missing or invalid credentials
-
Caller lacks read access to the project
-
Internal error
-
Memory service unreachable
curl \
--request POST 'https://agentengine.mongodb.com/api/v1/projects/{id}/memory/context' \
--header "Authorization: $API_KEY" \
--header "Content-Type: application/json" \
--data '{
"enabled_sources": [
"string"
],
"format_style": "string",
"include_memories": true,
"max_tokens": 42,
"metadata_filter": {},
"model_type": "string",
"query": "string",
"query_embedding": [
42.0
],
"session_id": "string",
"similarity_threshold": 42.0,
"top_k": 42,
"user_id": "string",
"visibility": "string"
}'
{
"enabled_sources": [
"string"
],
"format_style": "string",
"include_memories": true,
"max_tokens": 42,
"metadata_filter": {},
"model_type": "string",
"query": "string",
"query_embedding": [
42.0
],
"session_id": "string",
"similarity_threshold": 42.0,
"top_k": 42,
"user_id": "string",
"visibility": "string"
}
{
"detail": "This operation is not available in API version 2026-09-20-preview.",
"error": 406,
"errorCode": "OPERATION_NOT_IN_API_VERSION",
"parameters": [
"Accept"
],
"reason": "Not Acceptable"
}
{
"detail": "This operation supports text/event-stream, which the Accept header excludes. Remove unsupported media-type parameters or accept this type with a positive q value.",
"error": 406,
"errorCode": "UNACCEPTABLE_MEDIA_TYPE",
"parameters": [
"Accept"
],
"reason": "Not Acceptable"
}
{
"detail": "The requested API version is not supported. Supported versions: 2026-09-20-preview.",
"error": 406,
"errorCode": "UNSUPPORTED_API_VERSION",
"parameters": [
"Accept"
],
"reason": "Not Acceptable"
}
{
"detail": "This operation is not available in API version 2026-09-20-preview.",
"error": 406,
"errorCode": "OPERATION_NOT_IN_API_VERSION",
"parameters": [
"Accept"
],
"reason": "Not Acceptable"
}
{}
{}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}
{
"code": "string",
"error": "string",
"success": true
}