Session and Identity types for multi-tenant, multi-participant agents. Lightweight handles with scoping helpers for store names.

Functions

agent-key

fn (agent-name: Str, suffix: Str): Str

Build an agent-scoped store name: agent:{agent}:{suffix}.

Example

::ai::session/agent-key("support-bot", "kb")  // "agent:support-bot:kb"

session-key

fn (agent-name: Str, session: Session, suffix: Str): Str

Build a session-scoped store name: agent:{agent}:session:{sid}:{suffix}.

Example

session ::ai::session/Session({id: "C123"})
::ai::session/session-key("support-bot", session, "memory")  // "agent:support-bot:session:C123:memory"

session-user-key

fn (agent-name: Str, session: Session, identity: Identity, suffix: Str): Str

Build a (session, user)-scoped store name: agent:{agent}:session:{sid}:user:{uid}:{suffix}.

Use this for anything that's "this user, in this session" — most notably per-user conversation threads (/ask multi-turn context) and per-(session, user) profile data. Without this scoping, a person who's in a Telegram group AND a Slack channel would have their /ask follow-ups bleed across the two.

Example

session ::ai::session/Session({id: "C123"})
identity ::ai::session/Identity({id: "U456"})
::ai::session/session-user-key("support-bot", session, identity, "thread")
// "agent:support-bot:session:C123:user:U456:thread"

user-key

fn (agent-name: Str, identity: Identity, suffix: Str): Str

Build a user-scoped store name: agent:{agent}:user:{uid}:{suffix}.

Use this for data that genuinely follows the user across every session — e.g. global preferences, language, opt-out flags. For anything tied to a specific conversation (per-chat conversation threads, per-channel role / tone), use session-user-key instead so the same person in two different sessions doesn't collide.

Example

identity ::ai::session/Identity({id: "U456"})
::ai::session/user-key("support-bot", identity, "prefs")  // "agent:support-bot:user:U456:prefs"

Types

Identity

Identity type {
    id: Str,
    name: Str?,
    meta: Map?
}

A specific participant. Persistent across sessions.

Session

Session type {
    id: Str,
    meta: Map?
}

Conversation container. A Slack channel, Telegram group, DM thread, etc.