Overview

Create a new session by calling init({ sessionName, ... }). This initializes the SDK (if needed) and returns a session ID.

Syntax

await lai.init({ sessionName: string, ... }: InitParams): Promise<string>

Parameters

config
SessionConfig
required
Session configuration object with the following properties:

Returns

Returns a Promise that resolves to the session ID (string).

Examples

Basic Session Creation

import * as lai from 'lucidicai';

// Create a session
const sessionId = await lai.init({
  sessionName: "Document Analysis",
  task: "Extract insights from PDF documents"
});

With Full Configuration

const sessionId = await lai.init({
  sessionName: "Customer Support Session",
  task: "Resolve billing inquiry",
  tags: ["billing", "priority-high", "enterprise"],
  rubrics: ["response-quality", "resolution-time"]
});

For Testing

const sessionId = await lai.init({
  sessionName: "Unit Test Run",
  tags: ["test", "ci-cd"],
  productionMonitoring: false
});

With Mass Simulation

// First create a mass simulation
const massSimId = "mass-sim-123";

// Create sessions as part of the simulation
for (let i = 0; i < 10; i++) {
  const sessionId = await lai.init({
    sessionName: `Test Session ${i}`,
    massSimId: massSimId,
    task: "Evaluate model performance"
  });
  
  // Run your workflow...
  
  await lai.endSession();
}

With Experiment

// Experiments must be created in the dashboard first
// The experiment ID can be found in the URL after creation
const EXPERIMENT_ID = "exp-123abc-456def"; // From dashboard URL

// Add sessions to the experiment
const sessionId = await lai.init({
  sessionName: "Performance Test 1",
  experimentId: EXPERIMENT_ID,
  task: "Test checkout flow performance"
});

// Your agent workflow here
await processCheckout();

// End the session with evaluation
await lai.endSession({
  sessionEvalReason: "Checkout completed successfully"
});

Differences from init()

Featureinit()
SDK Initialization✅ Initializes SDK
Session Creation✅ Creates session when sessionName provided
Provider Setup✅ Configures
Multiple Sessions❌ One at a time

Error Handling

try {
  const sessionId = await lai.init({ sessionName: "My Session" });
} catch (error) {
  console.error("Failed to create session:", error);
}

Notes

  • Only one session can be active at a time
  • Previous session must be ended before creating a new one
  • The returned session ID can be stored to resume later with init({ sessionId })

See Also