Skip to main content
The Chatbot class manages conversation state, chat history, and system prompt configuration for voice conversations.

Class: Chatbot

Manages the conversation state machine and preprocesses messages for the LLM.

Import

Constructor

method
Creates a new Chatbot instance with empty conversation history.

Methods

conversation_state

method
Returns the current conversation state.States:
  • "waiting_for_user" - Bot is idle, waiting for user to speak
  • "user_speaking" - User is currently speaking
  • "bot_speaking" - Bot is generating/speaking a response

add_chat_message_delta

async method
Adds a text delta to the conversation history.Parameters:
  • delta (str) - Text chunk to add
  • role (Literal[“user”, “assistant”]) - Message role
  • generating_message_i (int | None) - Index of message being generated
Returns: True if a new message was started, False if appending to existing

preprocessed_messages

method
Returns the conversation history with preprocessing applied.Preprocessing includes:
  • Removing interruption markers
  • Removing silence markers
  • Trimming incomplete messages

set_instructions

method
Sets the system prompt instructions for the conversation.Parameters:
  • instructions (Instructions) - Instruction configuration object

get_instructions

method
Returns the current instructions configuration.

get_system_prompt

method
Generates the system prompt text from the current instructions.

last_message

method
Returns the content of the last message with the specified role.Parameters:
  • role (str) - Role to search for (“user” or “assistant”)

Conversation State Machine

The Chatbot tracks conversation state based on message history:

Instructions Types

The Chatbot supports multiple instruction types defined in unmute.llm.system_prompt:
  • SmalltalkInstructions - Casual conversation
  • ConstantInstructions - Fixed system prompt text
  • QuizShowInstructions - Quiz game personality
  • GuessAnimalInstructions - Animal guessing game
  • NewsInstructions - News reading personality
  • UnmuteExplanationInstructions - Explains how Unmute works
See Voices and Characters for details on configuring instructions.

Usage Example

Integration with UnmuteHandler

The Chatbot is used internally by UnmuteHandler to manage conversation state:
See UnmuteHandler for the main orchestration class.