Update the current session metadata
updateSession
await lai.updateSession( task?: string, tags?: Record<string, any>, isFinished?: boolean, isSuccessful?: boolean, isSuccessfulReason?: string ): Promise<void>
endSession()
// Initial session await lai.init({ sessionName: "Data processor", task: "Process unknown dataset" }); // After understanding the data await lai.updateSession( "Process customer transaction data for Q4 2023" );
// Add metadata tags await lai.updateSession( undefined, // Don't change task { environment: "production", version: "2.1.0", customer: "enterprise-client-123", dataSize: "10GB", priority: "high" } );
// Start with basic info await lai.init({ sessionName: "Analysis workflow" }); // Add context as you learn more await lai.updateSession( "Analyze user behavior patterns", { phase: "discovery" } ); // Update after initial findings await lai.updateSession( "Analyze shopping cart abandonment patterns", { phase: "analysis", findingType: "cart-abandonment", timeRange: "30-days" } );
try { await performCriticalOperation(); } catch (error) { // Mark session state before ending await lai.updateSession( undefined, { error: error.message, errorType: error.constructor.name, failurePoint: "critical-operation" } ); // Then end session await lai.endSession(false, error.message); }
async function multiPhaseWorkflow() { await lai.init({ sessionName: "ETL Pipeline" }); // Phase 1 await lai.updateSession("Extract data from sources", { phase: "extract" }); await extractData(); // Phase 2 await lai.updateSession("Transform and validate data", { phase: "transform" }); await transformData(); // Phase 3 await lai.updateSession("Load data to warehouse", { phase: "load" }); await loadData(); // Final update await lai.updateSession( "ETL pipeline completed", { phase: "complete", recordsProcessed: 50000, duration: "45min" } ); }
const variant = Math.random() > 0.5 ? 'A' : 'B'; await lai.updateSession( undefined, { experiment: "prompt-optimization", variant: variant, testGroup: "treatment" } );
const startTime = Date.now(); const result = await complexOperation(); const duration = Date.now() - startTime; await lai.updateSession( undefined, { performanceMs: duration, resultSize: result.length, cacheHit: result.fromCache } );
await lai.updateSession( undefined, { userId: user.id, userTier: user.subscription, userRegion: user.location, sessionSource: "web-app" } );
// Good - enables dashboard filtering await lai.updateSession(undefined, { env: "prod", feature: "chat", model: "gpt-4", customer: customerId });
// Start generic await lai.init({ task: "Process user request" }); // Update with specifics await lai.updateSession( `Generate ${reportType} report for ${dateRange}` );
// ❌ Wrong - use step functions instead await lai.updateSession("Working on step 2"); // ✅ Correct - session-level info only await lai.updateSession( "Multi-step analysis workflow", { totalSteps: 5 } );
isFinished