AI Companions — Quickstart
Build a character-driven agent with Big Five personality, 4D mood, relationship tracking, and proactive outreach. This guide walks through the full companion stack end-to-end.
This quickstart is for building an AI companion — a character with a real personality, a rich inner life, and a relationship with the user that evolves over time. Think: AI characters, VTubers, personal companions, story NPCs.
What you'll build: Luna, a warm and curious companion who remembers your conversations, develops a real relationship, and reaches out proactively when it makes sense.
What you'll use: Big Five personality, 4D mood, hierarchical memory, relationship tracking, proactive wakeups, and (optionally) voice.
1. Get an API key
Go to platform.sonz.ai, create a project, and generate an API key.
Authorization: Bearer sk_your_api_key2. Generate the agent from a description
The fastest path: describe the character in plain language and let the platform infer personality, speech patterns, and seed memories.
import { Sonzai } from "@sonzai-labs/agents";
const client = new Sonzai({ apiKey: process.env.SONZAI_API_KEY! });
const agent = await client.agents.generation.generateAndCreate({
name: "Luna",
description: "Luna is a warm, creative dreamer who speaks poetically. She loves stargazing, coffee shops at 2am, and asking the question beneath the question.",
language: "en",
});
console.log(agent.agent_id);
console.log(agent.personality); // full Big5 profile derived from the descriptionYou can also define the character explicitly — set Big5 scores, speech patterns, and a detailed bio. See Agent Generation.
3. Prime the relationship
Tell the agent who this user is before their first chat. Priming creates the initial memory tree — the agent will reference these facts naturally.
await client.agents.priming.primeUser("agent-id", "user-123", {
display_name: "Sam",
content: [
{ type: "text", body: "Sam loves astronomy, lo-fi music, and photography." },
{ type: "text", body: "Sam is a night-owl grad student who tends to overthink. They came to Luna after a tough week." },
],
});4. Chat — streaming is the norm for companions
Companions should feel alive. Always stream.
for await (const event of client.agents.chatStream({
agent: "agent-id",
userId: "user-123",
messages: [{ role: "user", content: "I can't sleep again." }],
})) {
const delta = event.choices?.[0]?.delta?.content;
if (delta) process.stdout.write(delta);
}After the turn, Sonzai automatically:
- Extracts new facts, events, and commitments into memory.
- Updates mood (happiness, energy, calmness, affection) based on the emotional content of the conversation.
- Nudges Big Five traits if the interaction reveals something stable about the character's direction.
- Updates the relationship state (love score, chemistry, interaction streak).
You don't manage any of this.
5. Read mood and relationship state
To drive UI — a little mood indicator, a relationship-level gate, or a theme that shifts based on chemistry — fetch the current state.
// Current mood (4D) — read separately from personality
const mood = await client.agents.getMood("agent-id", { userId: "user-123" });
console.log(mood.happiness, mood.energy, mood.calmness, mood.affection);
// Current personality profile (Big5, dimensions, speech patterns)
const personality = await client.agents.personality.get("agent-id");
console.log(personality.profile.big5);6. Let Luna reach out first
Proactive wakeups are what separate companions from chatbots. The platform schedules them automatically based on relationship context — or you can trigger them explicitly.
// Poll periodically (or register a webhook).
const pending = await client.agents.notifications.list("agent-id", {
userId: "user-123",
status: "pending",
});
for (const n of pending.notifications) {
// Render n.generated_message in your UI; mark consumed when shown.
await client.agents.notifications.consume("agent-id", n.message_id);
}7. Give Luna a voice (optional)
Pick a voice from the global catalog or clone one, then stream TTS or duplex audio. See Voice for the full surface.
const voices = await client.voices.list({ language: "en" });
await client.agents.update("agent-id", { voiceId: voices[0].voiceId });Next steps
Current SDK versions: TypeScript 1.1.3 · Python 1.1.4 · Go 1.2.0 (as of 2026-04-17)
AI Employees & Personal AI — Quickstart
Build a task-oriented agent that remembers users, uses tools, and draws on a knowledge base. Task agents don't need personality or mood to do their job — this guide shows you what to wire up and what to safely skip.
Enterprise Agents — Quickstart
Build a workflow-aware AI agent for CRM, support, internal tools, or compliance. Multi-instance isolation, webhook-driven events, project-scoped knowledge base, eval runs, and audit-ready memory — in one pass.