Neocortex
IntegrationsUnity SDK

Group Chat

Put several AI characters in one conversation in Unity with the Neocortex Group Director, each with its own voice, joining, leaving and talking to each other.

Pro or Team plan

A cast of two or more characters needs a Pro or Team plan. A cast of one works like a normal single character chat on any plan.

NeocortexGroupDirector runs one conversation across several characters. Each character keeps its own NeocortexSmartAgent, with its own voice, animation and events. The director sends one turn for the whole cast and plays every reply through the character that said it, one after the other. The cast can be up to six characters.

How the server runs a group scene is covered in Web API Group Chat.

Neocortex Group Director

Setting up

Add the characters

Give each character its own NeocortexSmartAgent on its own GameObject and pick a character in its dropdown. Each agent plays its own lines through its own AudioSource, so the voices come from the right place.

Add the director

Put a NeocortexGroupDirector on an empty GameObject and drag the agents into its Agents list.

The director owns the microphone for the whole scene, so it turns Auto Voice Input off on every agent in the cast. Without that, each character would answer the player on its own.

Add the UI (optional)

Add a NeocortexGroupChatUI on the director, with a chat panel, a text input, a thinking indicator and a microphone. It finds the director and its widgets by itself. Every speaker's turn comes back as a bubble with the character's name.

Use one NeocortexGroupChatUI for the whole cast. Don't also give each character a NeocortexChatUI, or every reply shows up twice.

Talking to the group

CallWho answers
Send(message)The cast decides who answers, up to Max Turns speakers.
SendTo(agent, message)That character. Pass an agent or a character id.
Continue()Nobody is addressed: the characters talk among themselves.
SendAudio(clip)Transcribes the player's recording, raises OnPlayerSpeech, then runs it like Send.
GroupScene.cs
using System.Linq;
using UnityEngine;
using Neocortex;
using Neocortex.Data;

public class GroupScene : MonoBehaviour
{
    [SerializeField] private NeocortexGroupDirector director;
    [SerializeField] private NeocortexSmartAgent aria;

    private void Start()
    {
        director.OnTurnStarted.AddListener(() => inputField.interactable = false);
        director.OnTurnFinished.AddListener(() => inputField.interactable = true);
        director.OnSpeaker.AddListener(message =>
            subtitles.Show(message.name, string.Concat(message.lines.Select(l => l.text))));
        director.OnRequestError.AddListener(error =>
        {
            if (error.IsForbidden()) Debug.Log("Group chat needs a Pro or Team plan");
        });

        director.Send("Hi everyone, introduce yourselves");
    }

    public void AskAria() => director.SendTo(aria, "Aria, what do you think?");
}

A turn plays out in order. OnTurnStarted fires first, then OnGroupResponseReceived with the whole turn, then OnSpeaker before each character speaks its part. Each agent raises its own OnChatLineStarted, OnEmotionChanged and OnReplyFinished as it speaks, so your animation code works the same as for a single character. OnTurnFinished fires once everyone is done, and also when a turn could not run.

Input sent while a turn is running is ignored, with a warning. Lock your input on OnTurnStarted and open it again on OnTurnFinished.

Max Turns (1 to 5, default 5) caps how many characters speak in one turn.

Actions in a group

Actions are registered on each agent, not on the director. When a character asks for an action in its part of the turn, its own agent runs the handler.

Per-character actions
aria.RegisterAction("WAVE", Wave);

private IEnumerator Wave(ChatAction action)
{
    ariaAnimator.SetTrigger("Wave");
    yield return new WaitForSeconds(1.5f);
}

Changing the cast

Characters can join and leave while the conversation runs:

A character walks in
public void OnBramArrived()
{
    director.AddAgent(bram);
    director.Continue(); // the others notice the newcomer
}

RemoveAgent(agent) takes a character out of the cast. A Continue() right after a change lets the cast react straight away.

A character that joins partway through only sees the conversation from the moment it joined, so a secret shared earlier stays secret. A character that left is remembered as gone.

History and sessions

The director keeps one shared session in SessionId. It starts empty and is set by the first turn. It lives in memory only, so store it yourself if you want to resume the scene later. ClearSession() starts a new conversation on the next turn.

await director.GetHistory(limit, before) loads the shared transcript, every speaker oldest first, and raises OnHistoryReceived. It returns null before the first turn.

The full list of members and events is in the API Reference. The Group Chat sample shows a live roster, with characters walking in and out.

On this page