Skip to main content

Session Memory

Session Memory stores structured snapshots of an agent's working state — files modified, commands run, decisions made, and open tasks. Agents can restore full context after a session ends or a compaction event fires.

Store a Session Snapshot

curl -X POST https://api.ainative.studio/api/v1/public/memory/v2/session \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"session_id": "session-abc123",
"project_path": "/Users/dev/myapp",
"files_modified": ["app/main.py", "app/api/router.py"],
"key_decisions": [
"Switched to async endpoints for better throughput",
"Added Redis caching layer"
],
"open_tasks": ["Write tests for /api/v1/models/available"],
"event": "pre_compact"
}'

event values:

  • pre_compact — fired before context window compaction
  • session_end — agent session ending cleanly
  • checkpoint — manual mid-session save

Get the Latest Session

curl "https://api.ainative.studio/api/v1/public/memory/v2/session/latest" \
-H "x-api-key: $API_KEY"

Get a Specific Session

curl "https://api.ainative.studio/api/v1/public/memory/v2/session/{session_id}" \
-H "x-api-key: $API_KEY"

Python SDK

import requests

API_KEY = "your-api-key"
BASE = "https://api.ainative.studio/api/v1/public/memory/v2/session"
headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}

# Save session state before compaction
requests.post(BASE, headers=headers, json={
"session_id": "my-session-001",
"project_path": "/Users/dev/project",
"files_modified": ["src/main.py"],
"key_decisions": ["Refactored auth middleware to use JWT"],
"open_tasks": ["Add rate limiting to /api/v1/messages"],
"event": "pre_compact"
})

# Restore on next session start
latest = requests.get(f"{BASE}/latest", headers=headers).json()
print(f"Restoring session: {latest['session_id']}")
print(f"Open tasks: {latest['session_data']['open_tasks']}")

Request Fields

FieldTypeRequiredDescription
session_idstringYesUnique session identifier
project_pathstringNoWorking directory path
files_modifiedstring[]NoFiles changed this session
key_decisionsstring[]NoImportant decisions made
open_tasksstring[]NoUnfinished tasks at save time
eventstringNopre_compact, session_end, checkpoint

Endpoints

MethodPathDescription
POST/memory/v2/sessionStore session snapshot
GET/memory/v2/session/latestGet most recent session for user
GET/memory/v2/session/{session_id}Get session by ID