Skip to Content
Nuance LabsDocs

Your own prompt

Tell the persona who it is and what is going on, with personality.system_prompt.

By default the persona is a curious conversationalist with no name. Your prompt makes it someone: a support agent, a survey interviewer, or a receptionist who continues a chat your customer started by text.

Your server sends the prompt as personality.system_prompt when it creates the session token.

// On your server: a session token whose conversation runs your own prompt.
const NUANCE_API = process.env.NUANCE_API_URL ?? "https://api.nuancelabs.ai";

const SYSTEM_PROMPT = `You are Sam, the front-desk assistant at Riverside Library: calm, patient and plain-spoken.
You help members with questions about their loans, holds and library cards. You can't change a fee or
renew a book past its limit, and you offer to hand anything else to a person.

This member is Jordan, with the library since 2019. Jordan was just chatting with us by text about a
late fee on an overdue book from October 12th, was frustrated, and asked to talk to someone.
Pick up from there rather than starting over.`;

/** Mints a token for `endUserId`, your id for the signed-in person. */
export async function mintToken(endUserId: string): Promise<string> {
  const response = await fetch(`${NUANCE_API}/session-tokens`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.NUANCE_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      personality: { system_prompt: SYSTEM_PROMPT },
      end_user_id: endUserId,
    }),
  });
  if (!response.ok) {
    throw new Error(
      `Couldn't mint a token: ${response.status} ${await response.text()}`,
    );
  }
  const { token } = (await response.json()) as { token: string };
  return token;
}

The example also sends end_user_id, your own id for the user, from your sign-in check (Quickstart). Hash an email address rather than sending it.

Give it a name

The persona has no name until your prompt gives it one, as the example does in its first words. Neither the default nor the character you pick with persona_id gives it a name, so without a name in the prompt, the persona has nothing to say when asked who it is.

What goes in the prompt

Write it the way you would brief a person before a call, in plain sentences.

  • Who it is. A name first, then a role and a manner. The example makes it the front-desk assistant at Riverside Library, "calm, patient and plain-spoken".
  • Where it works. What it helps with, what it can't do, and when it hands over to a person.
  • What it knows. Anything about the user it's talking with and what happened before, such as an earlier conversation this one picks up from.
  • Examples, when you have a tone in mind: a question and how the persona answers it.

Tips for a good prompt

  • Put in every fact the persona may state. Prices, hours, policies, contacts and steps belong in the prompt or come back from a tool. The persona can't look up your business's facts, so it says it doesn't have what you leave out.
  • Ask for plain sentences. Everything the persona says is spoken aloud, so lists, headings, emoji, links and code don't work.
  • Let the persona say it doesn't know. Lines such as "never say you don't know" or "give your best guess" lead to made-up policies and prices.
  • Keep it short; a few thousand characters is plenty. Your prompt shares a length limit with the platform's own instructions, so a long one can be refused with prompt_too_long (Errors).

On this page