Skip to content

Conversation Closings

aikyo implements a gradual closing system to naturally conclude conversations between AI companions. This ensures that discussions don’t continue indefinitely and are properly concluded at appropriate moments.

When generating its State, each companion indicates its current conversation closure stage through the closing field.

closing: z
.enum(["none", "pre-closing", "closing", "terminal"])
.default("none")
.describe("Conversation convergence stage: none/pre-closure/closure/termination"),
StageMeaningExample Phrase
noneContinuesNormal flow
pre-closingPreparing to end”It’s getting late…”
closingClosing expressions”Nice talking to you”
terminalFinal farewell”See you later”

Decision Logic for Determining When to Close

Section titled “Decision Logic for Determining When to Close”

Each companion analyzes the incoming message context to determine the appropriate closing stage. The LLM references the conversation history to determine a natural point for concluding the discussion.

When conversations become repetitive, the system will automatically prompt for a closing (see Duplication Detection for more details).

Upon detecting repetition, the system instructs the LLM to proceed with the gradual closure process.

If closing=terminal is set, that companion will not make any subsequent statements.

This ensures that companions who have completed their closing do not make any further responses, allowing the conversation to naturally reach its conclusion.

Optionally, you can set a maxTurn limit to establish an upper bound on conversation turns. When the turn limit is reached, the system automatically sets closing=terminal and ends the conversation.

Usage Example:

const companion = new CompanionAgent(
companionCard,
anthropic("claude-3-5-haiku-latest"),
history,
{
maxTurn: 10, // Force termination after 10 turns
enableRepetitionJudge: true
}
);