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
Creates a new Chatbot instance with empty conversation history.
Methods
conversation_state
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
Adds a text delta to the conversation history.Parameters:
delta(str) - Text chunk to addrole(Literal[“user”, “assistant”]) - Message rolegenerating_message_i(int | None) - Index of message being generated
True if a new message was started, False if appending to existingpreprocessed_messages
Returns the conversation history with preprocessing applied.Preprocessing includes:
- Removing interruption markers
- Removing silence markers
- Trimming incomplete messages
set_instructions
Sets the system prompt instructions for the conversation.Parameters:
instructions(Instructions) - Instruction configuration object
get_instructions
Returns the current instructions configuration.
get_system_prompt
Generates the system prompt text from the current instructions.
last_message
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 inunmute.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
Usage Example
Integration with UnmuteHandler
The Chatbot is used internally byUnmuteHandler to manage conversation state:
Related
- UnmuteHandler - Main conversation orchestrator
- LLM Utils - LLM integration utilities
- Voices and Characters - Configure system prompts