Graine AI

Identify the user: memory and conversations that continue

Tell the SDK who is signed in, let the agent remember them across chats, calls and devices, pick up the conversation where it left off, show and erase what is remembered, start a new conversation, and sign out — on every platform.

With one identifier — the trait your Who is the user? setting names — the agent knows the signed-in user on every surface: it remembers them across conversations and devices, the chat opens where they left it, and calls can be booked for them. Without one, every conversation is anonymous: nothing is kept, and nothing is shared between people.

What it needs in the dashboard

WhereSettingValue
Agent → Memory → SettingsRemembers users across chats and callsOn
Agent → Memory → SettingsWho is the user?User ID (user_id, the default), Email, Phone number, or Custom field with your trait's name (for example customer_id). The same on every agent the user talks to
Agent → Memory → SettingsDevices per user1 to 5 (2 by default): how many installs can act as one user
Agent → Memory → SettingsShared with, Keep memories for, What to rememberThis agent or the whole workspace; how long (365 days by default); what to keep and what never to

Memory → People is where your team later finds a user, sees what is remembered, forgets it and resets their devices.

What to do, in order

  1. After sign-in, call identify with the identifier under the field's name, plus any traits the prompt can use (name, plan). Pass the user's memory choice if your app asks for one. It applies to the next conversation.
  2. Talk or chat. → The agent knows the user's name (a prompt variable) and, with memory on, what it learnt before.
  3. Come back later — the same day, on another of their devices. → The chat opens on the earlier messages (the last 50 with that agent, kept 7 days after the latest) and the agent carries on; a call starts with its greeting but knows what was said.
  4. Show what is remembered with memories(); erase it with forgetMemory(), which also clears the chat on screen.
  5. Start over with newConversation() (or New conversation in the chat's header): a fresh thread; the memories stay.
  6. On sign-out, call identify(null). The device is released from the user and later conversations are anonymous.

The identifier is never a prompt variable. Graine stores the identifier your app sends so your team can see who each conversation was with — Call History shows User ID · u_8812 — and the memory service only ever receives a one-way key derived from it. Every other trait is masked on the device before it leaves it.

The code, platform by platform

1. After sign-in:

let graine = GraineInApp.shared
graine.identify(["user_id": user.id, "name": user.firstName, "plan": user.plan], memory: user.allowsMemory)

→ graine.memoryChoice is the user's stored choice (true unless they turned it off). memory: nil keeps the stored one.

4. What is remembered, and erasing it:

do {
    let memories: [GraineMemory] = try await graine.memories()     // newest first, at most 100
    for memory in memories { print(memory.text, memory.updatedAt ?? Date()) }
 
    let deleted: Int = try await graine.forgetMemory()             // also clears the chat on screen
    print("Forgot \(deleted) memories")
} catch let error as GraineServiceError {
    print(error.code, error.message)                               // identity_required, device_limit, …
}

5. A new conversation:

try await GraineInApp.shared.chat.newConversation()                // the chat clears and opens fresh

Turn memory off for this user (a privacy screen): GraineInApp.shared.setMemory(false).

6. On sign-out:

GraineInApp.shared.identify(nil)

What you'll see

MomentIn your appIn the dashboard
The first conversation after identifyThe agent uses the name you sentCall History shows User ID · u_8812 (or your field's name)
The user comes back within 7 daysThe chat opens on the earlier messages, a date line where the day changes, an earlier call as one Voice call row; no second welcome—
forgetMemory() succeedsThe chat on screen emptiesMemory → People shows nothing for the user
A device past Devices per userIt works, anonymously: no memory, no booking for the userMemory → People → Reset devices frees the slots

Troubleshooting

What you seeWhyFix
The agent does not rememberMemory is off on the agent, the user turned it off, or identify used another fieldTurn it on; check memoryChoice / memoryEnabled; send the field Who is the user? names
identity_requiredNo identifier — or a placeholder such as guest, 0, unknownidentify with a real identifier first
device_limitThis install is not one of the user's allowed devicesSign out on another device, raise Devices per user, or reset the user's devices
The website and the app are two peopleA different field or value on eachThe same Who is the user? field, and the same value, on both agents
The chat does not show earlier messagesAnonymous, memory off, more than 7 days, or the Garage hides Earlier messagesIdentify the user; Chat window → Earlier messages on

The rules in full: Identity and users · Memory · the variables the traits become: Variables.

On this page