Spaces method and path for this operation:
Refer to Spaces for more information.
Saves the events of an agent session, one document per event, so the session can be searched later. User and assistant messages are indexed for semantic search.
Takes 1 to 1000 events and a body of up to 10 MB. A request that fails validation is rejected as a whole. Any field an event carries beyond the documented ones, such as a tool event's result or a tool call's args, is stored as sent, whatever its JSON type.
Each event gets its own result, in request order. A failed event, for example when its content could not be embedded, does not fail the request; resend it to retry. A resent event is stored again, and readers drop duplicates by session and event id.
The route needs the contextEngine:write privilege. Without user_id the events belong to the caller's user profile, and a caller without one gets a 403. Naming another user in user_id also needs contextEngine:manage_memory. Each AI index in ai_index_ids must exist in this space, and the caller needs the Elasticsearch write privilege on its backing index. Otherwise the request is rejected and nothing is saved.
After authorization, validation, and feature-flag checks pass, each request writes one memory_save_event audit event.
Returns a 404 response when Context Engine is turned off in this space (contextEngine:enabled), when memory is turned off (contextEngine:memoryEnabled), or when an AI index in ai_index_ids does not exist.
For more information, refer to the Context Engine documentation.
[Required authorization] Route required privileges: contextEngine:write. Extended privileges (optional, expand functionality when granted): contextEngine:manage_memory.
Body
-
The AI indices the agent could use in the session. Each must exist in this space, and the caller needs the Elasticsearch
writeprivilege on its backing index.Not more than
100elements. Minimum length of each is1, maximum length of each is256. -
The events to save.
At least
1but not more than1000elements. -
The session the events belong to.
Minimum length is
1, maximum length is256. -
The Kibana user profile UID that the events belong to. Defaults to the caller's user profile. Naming another user requires
contextEngine:manage_memory.Minimum length is
1, maximum length is1024.
curl \
-X POST "https://${KIBANA_URL}/api/context_engine/memory/_save_event" \
-H "Authorization: ApiKey ${API_KEY}" \
-H "Content-Type: application/json" \
-H "kbn-xsrf: true" \
-d '{
"session_id": "3f9c2e1a-7b4d-4c8e-9a61-5d2f0b7e8c43",
"ai_index_ids": ["ops-memory"],
"events": [
{
"id": "evt-001",
"type": "user",
"turn_id": "turn-1",
"event_at": "2026-11-16T09:58:00.000Z",
"seq": 1,
"content": "Why is checkout latency up since this morning?"
},
{
"id": "evt-002",
"type": "assistant",
"turn_id": "turn-1",
"event_at": "2026-11-16T09:58:02.000Z",
"seq": 2,
"tool_calls": [
{ "id": "call-1", "name": "search_logs", "args": { "index": "logs-checkout*", "since": "now-6h" } }
]
},
{
"id": "evt-003",
"type": "tool",
"turn_id": "turn-1",
"event_at": "2026-11-16T09:58:32.000Z",
"seq": 3,
"tool_call_id": "call-1",
"tool_name": "search_logs",
"status": "failed",
"result": "Search timed out after 30 seconds",
"duration_ms": 30000
},
{
"id": "evt-004",
"type": "assistant",
"turn_id": "turn-1",
"event_at": "2026-11-16T09:58:35.000Z",
"seq": 4,
"content": "The log search timed out, so I could not confirm it from the logs. The checkout-service deploy at 08:40 is the most likely cause. Check its connection pool settings, or roll it back."
}
]
}'
POST kbn:/api/context_engine/memory/_save_event
{
"session_id": "3f9c2e1a-7b4d-4c8e-9a61-5d2f0b7e8c43",
"ai_index_ids": ["ops-memory"],
"events": [
{
"id": "evt-001",
"type": "user",
"turn_id": "turn-1",
"event_at": "2026-11-16T09:58:00.000Z",
"seq": 1,
"content": "Why is checkout latency up since this morning?"
},
{
"id": "evt-002",
"type": "assistant",
"turn_id": "turn-1",
"event_at": "2026-11-16T09:58:02.000Z",
"seq": 2,
"tool_calls": [
{ "id": "call-1", "name": "search_logs", "args": { "index": "logs-checkout*", "since": "now-6h" } }
]
},
{
"id": "evt-003",
"type": "tool",
"turn_id": "turn-1",
"event_at": "2026-11-16T09:58:32.000Z",
"seq": 3,
"tool_call_id": "call-1",
"tool_name": "search_logs",
"status": "failed",
"result": "Search timed out after 30 seconds",
"duration_ms": 30000
},
{
"id": "evt-004",
"type": "assistant",
"turn_id": "turn-1",
"event_at": "2026-11-16T09:58:35.000Z",
"seq": 4,
"content": "The log search timed out, so I could not confirm it from the logs. The checkout-service deploy at 08:40 is the most likely cause. Check its connection pool settings, or roll it back."
}
]
}
{
"ai_index_ids": [
"ops-memory"
],
"events": [
{
"content": "Why is checkout latency up since this morning?",
"event_at": "2026-11-16T09:58:00.000Z",
"id": "evt-001",
"seq": 1,
"turn_id": "turn-1",
"type": "user"
},
{
"event_at": "2026-11-16T09:58:02.000Z",
"id": "evt-002",
"seq": 2,
"tool_calls": [
{
"args": {
"index": "logs-checkout*",
"since": "now-6h"
},
"id": "call-1",
"name": "search_logs"
}
],
"turn_id": "turn-1",
"type": "assistant"
},
{
"duration_ms": 30000,
"event_at": "2026-11-16T09:58:32.000Z",
"id": "evt-003",
"result": "Search timed out after 30 seconds",
"seq": 3,
"status": "failed",
"tool_call_id": "call-1",
"tool_name": "search_logs",
"turn_id": "turn-1",
"type": "tool"
},
{
"content": "The log search timed out, so I could not confirm it from the logs. The checkout-service deploy at 08:40 is the most likely cause. Check its connection pool settings, or roll it back.",
"event_at": "2026-11-16T09:58:35.000Z",
"id": "evt-004",
"seq": 4,
"turn_id": "turn-1",
"type": "assistant"
}
],
"session_id": "3f9c2e1a-7b4d-4c8e-9a61-5d2f0b7e8c43"
}
{
"results": [
{
"id": "evt-001",
"status": "created"
},
{
"id": "evt-002",
"status": "created"
},
{
"id": "evt-003",
"status": "created"
},
{
"error": "Exception when running inference id [.elser-2-elasticsearch] on field [content.semantic_text]",
"id": "evt-004",
"status": "failed"
}
]
}
{
"results": [
{
"id": "evt-001",
"status": "created"
},
{
"id": "evt-002",
"status": "created"
},
{
"id": "evt-003",
"status": "created"
},
{
"id": "evt-004",
"status": "created"
}
]
}
{
"error": "Forbidden",
"message": "AI index 'ops-memory' is not writable. Writing to it needs the Elasticsearch 'write' privilege on its backing index.",
"statusCode": 403
}
{
"error": "Forbidden",
"message": "Acting on the memory of another user requires the [contextEngine:manage_memory] privilege.",
"statusCode": 403
}
{
"error": "Forbidden",
"message": "The caller has no user profile, so the request cannot be attributed to a user. Log in to Kibana once to create a profile, use an API key whose owner has one, or set `user_id` if you have the `contextEngine:manage_memory` privilege.",
"statusCode": 403
}
{
"error": "Not Found",
"message": "AI index 'ops-memory' not found",
"statusCode": 404
}
{
"error": "Not Found",
"message": "Not Found",
"statusCode": 404
}
{
"error": "Not Found",
"message": "Context Engine memory is turned off.",
"statusCode": 404
}