Skip to Content
Nuance LabsDocs

Direct the persona live

Events your page sends during a conversation: make the persona say something, tell it what's happening in your app, stop it, keep it quiet, and more.

The persona holds the conversation on its own: it hears your user and answers without any help from your code. When something happens in your app that the persona should react to, you send it an event from your page, a small JSON object. For example, you can make the persona say something right now, even if it wasn't about to:

{ "type": "response.create", "response": { "instructions": "Welcome them back and ask how the trip went." } }

With the JavaScript SDK, pass that object to conversation.sendInterfaceEvent. In a native app, Native apps shows how to send it.

Send nothing before session.started arrives. An earlier event can be lost, with no error.

Make it speak

response.create asks the persona to speak now.

{ "type": "response.create", "response": { "instructions": "Tell them their order has shipped." } }

A common use is right when the conversation starts. The persona waits for the user to speak first, so send response.create if you want the persona to open the conversation instead (Quickstart).

response.instructions is optional. It tells the persona what to do in this reply, not the exact words to say: the persona puts it in its own words. If the persona is already speaking, it finishes first and then answers.

Tell it what's going on

An append gives the persona a line of information without asking it to answer right away. Use it to tell the persona what's happening in your app.

{ "type": "session.thinking.append", "delegation_id": null, "content": "The user just scored a goal: it's 2 to 1." }

There are three kinds, depending on what you want the persona to do with the line:

  • session.thinking.append: background, such as a tap or what the screen shows. The persona may mention it or not.
  • session.instructions.append: something it should act on, speaking up on its own if it needs to.
  • session.commentary.append: something it should tell the user, in its own words, at the next chance.

Send updates as soon as they happen: the persona only knows what it was told before it started a reply. A thinking line doesn't make the persona speak; send response.create after it if you need a reply. Set delegation_id to null; it's only used when your page decides what to do.

Like every event on this page, you can send an append with conversation.sendInterfaceEvent. The SDK also has a shortcut that builds the event for you: conversation.append("thinking", "The user just scored a goal: it's 2 to 1.").

Change what it's saying mid-sentence

When what the persona is saying is no longer right, send the append with while_speaking: "revise" (the default is "finish").

{ "type": "session.thinking.append", "delegation_id": null, "content": "The user just scored a goal: it's 2 to 1.", "while_speaking": "revise" }

If you use the conversation.append shortcut, pass { whileSpeaking: "revise" } as its third argument.

The persona stops at once and a new reply picks up from your line, without repeating what the user heard. The cut reply ends with session.output_audio.done reason revised. Tool calls keep running.

Stop it

A session.output_audio.interrupt stops the persona's reply immediately and throws away the rest.

{ "type": "session.output_audio.interrupt" }

You then get session.output_audio.done with reason: "interrupted". The persona still answers the user's next words; follow with a floor hold to keep it quiet, or response.create to have it say something else. When there is something new to say, revise instead.

Keep it quiet for a while

A session.floor.hold keeps the persona from speaking up on its own until you send session.floor.release, the hold runs out, or the user speaks.

{ "type": "session.floor.hold", "seconds": 30, "reason": "The user is reading the results." }
{ "type": "session.floor.release" }

seconds sets how long the hold lasts at most, and reason tells the persona why it's waiting. With either of them, the user speaking also ends the hold; set ends_on_speech: false to keep it going. A hold sent with no fields pauses the persona without telling it why, until you release it. A hold doesn't stop a reply already playing, so stop it first if you need silence at once.

Mute the user

session.input_audio.mute makes the persona hear the microphone as silence while your page keeps publishing it. session.input_audio.unmute undoes it.

{ "type": "session.input_audio.mute" }
{ "type": "session.input_audio.unmute" }

While muted, the user can't cut the persona off or end a turn.

Let the user type

If your page has a text box or chat input, you can pass what the user types to the persona, and it answers out loud as if they had said it. Send two events: one adds the message, the other asks for an answer.

{ "type": "response.item.create", "item": { "type": "message", "role": "user", "content": "Can you make it Friday instead?" } }
{ "type": "response.create" }

This requires type: "responses" (Tools). Typed messages don't show up in the transcript events, so show them on your page yourself.

Hang up

{ "type": "session.close" }

The persona answers with session.closed, reason close_requested. With the SDK, conversation.disconnect() sends it and stops the microphone and camera.

What gets refused

A refused event gets an error carrying your event_id, and the conversation carries on. Text you send is checked, and refused with instructions_refused if it asks for another language or for the persona to name its AI model or claim to be human. Errors lists every code, and Limits every size.

Every event you can send

EventWhat it does
response.createAsks the persona to speak now, or sends your tool results.
session.thinking.appendGives the persona quiet context about what just happened in your app.
session.instructions.appendGives the persona an instruction to act on, speaking up on its own if needed.
session.commentary.appendGives the persona something to tell the user, in its own words.
response.item.createAdds a tool's result, or the user's typed words.
session.output_audio.interruptStops the persona's reply immediately.
session.floor.hold, session.floor.releaseKeeps the persona from speaking up on its own, and lets it again.
session.input_audio.mute, session.input_audio.unmuteMakes the persona hear the user's microphone as silence, and hear it again.
session.updateChanges which of your tools the persona may call (Tools that come and go).
session.closeHangs up.

The full example

This file has most of the events above as functions you can copy. Its send function comes from the example on Native apps.

// In the browser: steer a Nuance Live conversation from your page, as things
// happen in it. `send` is the session's, from nuance-live-room.ts.
import type { LiveSession } from "./nuance-live-room";

type Send = LiveSession["send"];

/** News that changes what the persona should be saying: it stops and carries on with the news. */
export function tellThePersonaNow(send: Send, news: string) {
  return send({
    type: "session.thinking.append",
    delegation_id: null,
    content: news,
    while_speaking: "revise",
  });
}

/** Context the persona's next reply reads; the reply it is giving plays on as drafted. */
export function tellThePersonaLater(send: Send, context: string) {
  return send({
    type: "session.thinking.append",
    delegation_id: null,
    content: context,
    while_speaking: "finish",
  });
}

/** Asks the persona to speak now, with a note for that reply. */
export function askThePersonaToSpeak(send: Send, note: string) {
  return send({
    type: "response.create",
    response: { instructions: note },
  });
}

/** Stops the persona's reply where it stands, and keeps the persona quiet until the user speaks. */
export async function stopThePersona(send: Send): Promise<void> {
  await send({
    type: "session.output_audio.interrupt",
  });
  await send({
    type: "session.floor.hold",
    ends_on_speech: true,
  });
}

/** Keeps the persona from taking a turn of its own for `seconds`, and tells it why. */
export function holdTheFloor(send: Send, seconds: number, reason: string) {
  return send({
    type: "session.floor.hold",
    seconds,
    reason,
  });
}

export function releaseTheFloor(send: Send) {
  return send({ type: "session.floor.release" });
}

/** While muted, the persona hears the user's microphone as silence. */
export function muteTheUser(send: Send, muted: boolean) {
  return send({
    type: muted ? "session.input_audio.mute" : "session.input_audio.unmute",
  });
}

/** The user's typed words, then a reply to them (needs a responses delegation). */
export async function sendTyped(send: Send, text: string): Promise<void> {
  await send({
    type: "response.item.create",
    item: { type: "message", role: "user", content: text },
  });
  await send({ type: "response.create" });
}

On this page