Nuance LabsDocs

Your own prompt

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

By default the AI persona is a curious conversationalist with no name of its own. Give a conversation your own prompt to make the persona someone else: a support agent, a survey interviewer, a receptionist picking up a chat your customer started by text.

Send it as personality.system_prompt when your server mints 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;
}

endUserId is your id for the person, from your own sign-in check as in API keys and session tokens: letters, digits and _ . : -, so hash an email first.

What goes in it

Write it the way you'd brief a person before a call, in plain sentences:

  • Who the AI persona is: a name, a role, a manner. "You are Sam, the front-desk assistant at Riverside Library: calm, patient and plain-spoken."
  • Where it works and what it can do: what it helps with, what it can't do, when it hands over to a person.
  • What it knows: anything about the person or what happened before, including a conversation this one continues.
  • Examples, if you have a tone in mind: a question and how the persona answers it.

Write it for a voice

  • Give it the facts it may state. Put prices, hours, policies, contacts and steps in the prompt, or return them from a tool. The persona says it doesn't have anything you leave out: it can't look up your business's own facts.
  • Ask for plain sentences. Replies are spoken, so don't ask for lists, headings, emoji, links or code.
  • Let it 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. Your prompt and the platform's own instructions share one length limit, so a long prompt can be refused: a 400 with code prompt_too_long, whose max_characters says how long this personality's prompt may be. A prompt longer than the API reference's limit for system_prompt is refused before that, with a 422. A few thousand characters is plenty.

On this page