Turn-taking
aikyo implements a turn-taking system to enable multiple AI companions to engage in natural conversation flow. This system automatically determines who should speak and when.
How Turn Taking Works
Section titled “How Turn Taking Works”Overall Process
Section titled “Overall Process”- The companion receiving a message generates a
Stateobject. - All companions publish their
Stateobjects to thestatestopic. - The
TurnTakingManagercollects all collectedStates. - Based on votes, it selects the next speaker.
- The selected companion then executes its turn.
Generating State
Section titled “Generating State”Each companion determines its own state based on the entire conversation history.
State Structure
Section titled “State Structure”export const StateBodySchema = z.object({ from: z.string(), messageId: z.string().describe( "The ID of the original message this state corresponds to" ), state: z .enum(["speak", "listen"]) .describe("Whether you want to speak next or enter listening mode"), importance: z .number() .min(0) .max(10) .describe( "The priority of your next intended statement in the conversation context" ), selected: z .boolean() .describe( "Indicates whether the previous speaker has specifically called on you" ), closing: z .enum(["none", "pre-closing", "closing", "terminal"]) .default("none") .describe( "Conversation closure stage: none/pre-closing/closure/terminal" ),}).strict();export type StateBody = z.infer<typeof StateBodySchema>;Key Fields:
- state: Either
speak(wanting to speak) orlisten(entering listening mode) - importance: A score between 0-10, where higher values indicate greater priority
- selected: Indicates whether you have been specifically called upon
- closing: Indication of conversation termination intent (see Conversation Closure for details)
Speaker Selection by TurnTakingManager
Section titled “Speaker Selection by TurnTakingManager”The TurnTakingManager collects all companions’ States to determine who
should speak next.
State Collection
Section titled “State Collection”It waits until all participants have submitted their State objects, then
proceeds once all votes are in.
Speaker Selection Logic
Section titled “Speaker Selection Logic”Priority Order:
- Named companions (
selected=true): Among these, the one with the highestimportance - Companions requesting to speak (
state=speak): Among these, the one with the highestimportance - No eligible candidates: The turn ends without selection
Statement Execution
Section titled “Statement Execution”If the selected companion is yourself, you will execute your statement after a
predetermined wait period. If closing=terminal, no statement will be
delivered, and the conversation will conclude.