Skip to Content
Nuance LabsDocs

Configure the conversation

Set up the conversation your users will have: which persona, who it is, what it can do, and who it's talking with.

Your server sets everything about a conversation when it creates the session token with POST /session-tokens. The page can't change any of it later, except which of your tools the persona may use.

This example creates a token for a persona that has one tool and may hang up on its own.

// On your server: a session token for a Nuance Live conversation whose
// backend can run one of your tools.
const NUANCE_API = process.env.NUANCE_API_URL ?? "https://api.nuancelabs.ai";

const GET_WEATHER = {
  type: "function",
  name: "get_weather",
  description: "Looks up the current weather in a city.",
  parameters: {
    type: "object",
    properties: { city: { type: "string" } },
    required: ["city"],
  },
};

/** Mints a token for `endUserId`, your id for the signed-in person. */
export async function mintNuanceLiveToken(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({
      // The persona's instructions: say when it hands work to its backend.
      personality: {
        system_prompt:
          "You are Sam, a friendly weather assistant. When the user asks about " +
          "the weather, hand the question to your backend, then tell them what it found.",
      },
      interface_setup: {
        delegation: {
          type: "responses",
          responses: {
            // Required: any non-empty name.
            model: "default",
            instructions:
              "Use get_weather for any weather question, then answer in one short sentence.",
            tools: [GET_WEATHER],
          },
        },
        // The persona may hang up after its goodbye.
        runtime_tools: { end_call: true },
      },
      end_user_id: endUserId,
    }),
  });
  if (!response.ok) {
    throw new Error(
      `Couldn't mint a token: ${response.status} ${await response.text()}`,
    );
  }
  // `warnings` names each tool the session will run without, and why.
  const { token } = (await response.json()) as { token: string };
  return token;
}

The fields

All of these go in the body of POST /session-tokens. Leave any of them out for the default.

FieldWhat it sets
personality.persona_idWhich character the persona looks and sounds like. Personas shows each one.
personality.system_promptWho the persona is and how it behaves. See Your own prompt for tips. The persona has no name unless the prompt gives it one.
interface_setup.delegationThe tools you give the persona: functions in your own code that it can call during the conversation.
interface_setup.runtime_toolsEnable or disable the persona's built-in tools, such as letting it end the call on its own.
expressivenessHow much the persona's face and head move, from 0 (calm) to 2 (expressive). The default, 1, is the persona's own tuned level.
end_user_idYour own id for the user the conversation is with. If that user breaks the Acceptable Use Policy again and again, Nuance pauses only them, not your whole account (After repeated violations).
interface_setup.video.input.cameraWhether the persona uses the user's camera. With false, it doesn't look at the camera and the camera isn't recorded.

The response

Nuance answers with the session token, which your server passes to the page. The page has to use it soon, or it expires (Session tokens).

The response also has a list of warnings. Check them while you build: each one tells you about something you sent that won't take effect, such as a tool that was dropped and why, tools placed outside interface_setup.delegation, or a missing end_user_id.

If Nuance can't accept what you sent, you get an error instead of a token. Errors lists each one and how to fix it.

Writing the prompt around tools

When the user asks for something a tool does, the persona speaks first and then calls the tool. Its words play before your tool runs, so write for that order.

  • Say plainly in personality.system_prompt which requests need a tool. The persona decides on its own when to call one, and without clear rules it may talk about doing something and never call anything.
  • Have the persona say what it is starting, not that it is done: "Booking it now…", not "It's booked!".
  • Use delegation.responses.instructions (Tools) for how to use each tool and how to answer with what comes back.

The persona's built-in tools

Besides your tools, the persona has a few of its own. Nuance runs them; you don't have to call or respond to them yourself. Turn each one on or off in interface_setup.runtime_tools with true or false.

  • stay_quiet (on by default). Without it, the persona answers every time the user stops talking. That isn't always what you want: the user may be thinking out loud, reading something, or have asked for a minute. With stay_quiet, the persona can choose to stay silent, and it can come back later when it said it would ("I'll check back in 30 seconds").
  • end_call (off by default). The persona can end the call itself after saying goodbye. Your page sees the conversation end with the reason end_call.
  • call_time (off by default). The persona can check how long the call has run and how much time is left, for example when the user asks. It says something like "Let me check" while it looks.

Built-in tools aren't offered everywhere, so one you turn on may not be available.

On this page