Overview
The updateSession function updates properties of the active session, such as task description, tags, or completion status.
Syntax
await lai.updateSession({
  task?: string,
  sessionEval?: number,
  sessionEvalReason?: string,
  isSuccessful?: boolean,
  isSuccessfulReason?: string,
  tags?: string[],
}): Promise<void>
 
Parameters
Updated task description for the session.
 
Numeric evaluation score for the session.
 
Reason/justification for the evaluation score.
 
Tag strings to categorize the session.
 
Whether the session is finished. Usually handled by endSession().
 
Whether the session completed successfully.
 
Explanation of success or failure reason.
 
Returns
Returns a Promise that resolves to void.
Examples
Update Task Description
// Initial session
await lai.init({
  sessionName: "Data processor",
  task: "Process unknown dataset"
});
// After understanding the data
await lai.updateSession({
  task: "Process customer transaction data for Q4 2023"
});
 
// Add metadata tags
await lai.updateSession({
  tags: [
    "environment:production",
    "version:2.1.0",
    "customer:enterprise-client-123",
    "dataSize:10GB",
    "priority:high"
  ]
});
 
Progressive Updates
// Start with basic info
await lai.init({ sessionName: "Analysis workflow" });
// Add context as you learn more
await lai.updateSession({
  task: "Analyze user behavior patterns",
  tags: ["phase:discovery"]
});
// Update after initial findings
await lai.updateSession({
  task: "Analyze shopping cart abandonment patterns",
  tags: [
    "phase:analysis",
    "findingType:cart-abandonment",
    "timeRange:30-days"
  ]
});
 
Error Tracking
try {
  await performCriticalOperation();
} catch (error) {
  // Mark session state before ending
  await lai.updateSession({
    tags: [
      `error:${error.message}`,
      `errorType:${error.constructor.name}`,
      "failurePoint:critical-operation",
    ]
  });
  
  // Then end session
  await lai.endSession(false, error.message);
}
 
Workflow Phases
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({
    task: "ETL pipeline completed",
    tags: [
      "phase:complete",
      "recordsProcessed:50000",
      "duration:45min",
    ]
  });
}
 
Common Use Cases
1. A/B Testing
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({
  tags: [
    `performanceMs:${duration}`,
    `resultSize:${result.length}`,
    `cacheHit:${result.fromCache}`
  ]
});
 
3. User Context
await lai.updateSession({
  tags: [
    `userId:${user.id}`,
    `userTier:${user.subscription}`,
    `userRegion:${user.location}`,
    "sessionSource:web-app",
  ]
});
 
Best Practices
// Good - enables dashboard filtering
await lai.updateSession({
  tags: [
    "env:prod",
    "feature:chat",
    "model:gpt-4",
    `customer:${customerId}`
  ]
});
 
2. Update Task as Context Emerges
// Start generic
await lai.init({ sessionName: 'My session' });
// Update with specifics
await lai.updateSession({
  task: `Generate ${reportType} report for ${dateRange}`
});
 
3. Don’t Use for Step Data
// ❌ Wrong - use step functions instead
await lai.updateSession({ task: "Working on step 2" });
// ✅ Correct - session-level info only
await lai.updateSession({
  task: "Multi-step analysis workflow",
  tags: ["totalSteps:5"]
});
 
Notes
- Only updates the active session
 
- All parameters are optional
 
isFinished is typically handled by endSession() 
- Tags are merged with existing tags, not replaced
 
- Cannot update a finished session
 
See Also