Skip to main content

Overview

Restore sessions from saved snapshots to continue working with preserved browser state, authentication, and data.

Restoration Methods

There are two ways to restore from snapshots:

From Specific Session

Restore from a specific session’s snapshot
Use restore_from_session_id

From Default Environment

Restore from user’s default environment
Use restore_default_environment_from_user_id

Restore from Specific Session

Restore from a specific session’s snapshot by providing the session ID:
const response = await fetch('https://api.agi.tech/v1/sessions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    agent_name: 'agi-0',
    restore_from_session_id: 'session-uuid-to-restore-from'
  })
});
const session = await response.json();
Use this method when you want to restore from a specific session snapshot, not the default environment.

Restore from Default Environment

Restore from your default environment by providing your user ID:
const response = await fetch('https://api.agi.tech/v1/sessions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    agent_name: 'agi-0',
    restore_default_environment_from_user_id: 'your-user-id'
  })
});
const session = await response.json();
This is the recommended approach for most applications. Set up your default environment once, then all future sessions can automatically restore from it.

Automatic Default Restoration

To make sessions automatically restore from the default environment, always include restore_default_environment_from_user_id in your session creation:
async function createSessionWithDefault(userId, apiKey) {
  const response = await fetch('https://api.agi.tech/v1/sessions', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      agent_name: 'agi-0',
      restore_default_environment_from_user_id: userId
    })
  });
  return await response.json();
}

// Usage
const session = await createSessionWithDefault('your-user-id', apiKey);

Memory Snapshot Mode

Control whether memory snapshots are enabled when restoring:
const response = await fetch('https://api.agi.tech/v1/sessions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    agent_name: 'agi-0',
    restore_from_session_id: 'session-uuid',
    enable_memory_snapshot: true  // Default: true
  })
});
Options:
  • enable_memory_snapshot: true - Uses memory snapshots for faster restoration (recommended)
  • enable_memory_snapshot: false - Uses filesystem snapshots only (slower but more reliable)

Restoration Priority

When creating a session, the system uses this precedence order:
  1. restore_from_session_id - Explicit session ID (highest priority)
  2. restore_default_environment_from_user_id - User’s default environment
  3. Fresh session - No restoration (default)
If both restore_from_session_id and restore_default_environment_from_user_id are provided, restore_from_session_id takes precedence.

Complete Example

Complete workflow: save snapshot and restore in new session:
// Step 1: Create a session
const sessionResponse = await fetch('https://api.agi.tech/v1/sessions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ agent_name: 'agi-0' })
});
const { session_id } = await sessionResponse.json();

// Step 2: Use the session (login, navigate, etc.)
// ... perform actions that establish authentication ...

// Step 3: Save snapshot and set as default
await fetch(`https://api.agi.tech/v1/sessions/${session_id}?save_snapshot_mode=filesystem&save_as_default=true`, {
  method: 'DELETE',
  headers: { 'Authorization': `Bearer ${API_KEY}` }
});

// Step 4: Create new session that automatically restores from default
const newSessionResponse = await fetch('https://api.agi.tech/v1/sessions', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    agent_name: 'agi-0',
    restore_default_environment_from_user_id: 'your-user-id'
  })
});
const newSession = await newSessionResponse.json();