Usage Examples
Complete, working code for four common Long-Term Memory scenarios: automatic persistence, account-scoped identity, memory seeding before first session, and targeted resets.
Long-Term Memory in Practice
Example 1: Zero-Config Automatic Persistence
1
2
3
Example 2: Custom Identity Provider for Authenticated Users
using System;
using System.Collections.Generic;
using Convai.Domain.Identity;
using Convai.Runtime.Components;
using UnityEngine;
// --- Identity provider ---
// Returns the server-assigned account ID, which is stable across devices and re-logins.
public class EmployeeIdentityProvider : IEndUserIdentityProvider
{
private readonly string _accountId;
public EmployeeIdentityProvider(string accountId)
{
_accountId = accountId;
}
public string GetEndUserId() => _accountId;
}
// --- Metadata provider ---
// Attaches name and department to the end-user record.
// The "name" key is displayed in the editor's Long-Term Memory tab.
public class EmployeeMetadataProvider : IEndUserMetadataProvider
{
private readonly string _name;
private readonly string _department;
public EmployeeMetadataProvider(string name, string department)
{
_name = name;
_department = department;
}
public IReadOnlyDictionary<string, object> GetEndUserMetadata()
{
return new Dictionary<string, object>
{
{ "name", _name },
{ "department", _department }
};
}
}
// --- Scene setup ---
public class OnboardingSessionSetup : MonoBehaviour
{
[SerializeField] private ConvaiManager _convaiManager;
// Call this after your authentication layer resolves the signed-in employee.
// Must be called BEFORE ConvaiManager opens a session.
public void OnEmployeeSignedIn(string accountId, string fullName, string department)
{
_convaiManager.SetEndUserIdentityProvider(
new EmployeeIdentityProvider(accountId));
_convaiManager.SetEndUserMetadataProvider(
new EmployeeMetadataProvider(fullName, department));
}
}Example 3: Seeding Memories Before a First Session
Example 4: Resetting a User for a Fresh Simulation Run
Goal
Method
Conclusion
Last updated
Was this helpful?