Finite State Machine#
FSM is the brain of the 3DAC system, governing the entire chat lifecycle and ensuring consistent behavior across all system states. It defines a series of states and makes state transitions throughout the system. The FSM uses a condition-based event queue to process external signals such as user interactions, network events, which consists of 2 stages:
System Startup: Ensures that all static and runtime assets are available before entering the chat, including environment model, character mesh, local animations(e.g., audio/motion/face for apologize behavior). It also generates an opening remark as the avatar’s first sentence.
Interactive Conversation: Triggered when the user enters the chat, the system orchestrates stream lifecycle management, synchronizes animation playback with the runtime pipeline, and applies robust error handling and recovery to deliver a seamless chat experience.
The following figure illustrates the overall workflow of FSM:
FSM
States#
INIT#
Initialize the FSM system.
Transit to:
WAITING_FOR_FRONTEND_READYwhen initialization finished.
WAITING_FOR_FRONTEND_READY#
Wait for Babylon scene to be ready.
Transit to:
SPAWN_ENVIRONMENTwhen receivedFRONTEND_READYcondition.EXITwhen scene startup timed out.
SPAWN_ENVIRONMENT#
Load HDR environment and ground model using user settings.
Transit to:
SPAWN_CHARACTERafter scene setup succeeds.EXITwhen environment setup fails.
SPAWN_CHARACTER#
Loads character configuration and assets.
Transit to:
WAITING_FOR_ALGORITHM_READY_ON_STARTwhen the character is successfully added to the scene.EXITwhen configuration fetch or model loading fails.
WAITING_FOR_ALGORITHM_READY_ON_START#
Health-check for algorithm services and validate stream buffer.
Transit to:
CHECK_AND_UPDATE_ASSETSwhen health-check and stream evaluation passed.ALGORITHM_GENERATION_FAILEDwhen health-check or stream evaluation failed.
CHECK_AND_UPDATE_ASSETS#
Sync character local motion/audio/face into runtime and generate opening remark.
Transit to:
WAITING_FOR_USER_START_GAMEwhen synchronization and generation finished.EXITif any error occurs.
WAITING_FOR_USER_START_GAME#
Wait for user to start chat and accumulate opening remark stream.
Transit to:
ACTOR_ANIMATION_STREAMINGwhen receivedUSER_START_GAMEcondition and the opening remark is still streaming.WAITING_FOR_ACTOR_ANIMATION_FINISHEDwhen receivedUSER_START_GAMEcondition and the opening remark is fully received.EXITwhen microphone check fails or opening remark data is missing.
IDLE#
Default rest state, which listens for the user input.
Transit to:
WAITING_FOR_USER_STOP_RECORDINGwhen receivedUSER_START_RECORDINGcondition.
WAITING_FOR_USER_STOP_RECORDING#
The user is uploading audio.
Transit to:
WAITING_FOR_LOCAL_ANIMATION_INTERRUPTEDwhen receivedUSER_STOP_RECORDINGcondition.
WAITING_FOR_LOCAL_ANIMATION_INTERRUPTED#
Wait for local animation to interrupt.
Transit to:
WAITING_FOR_ACTOR_RESPOND_GENERATION_FINISHEDwhen receivedANIMATION_FINISHEDsignal.
WAITING_FOR_ACTOR_RESPOND_GENERATION_FINISHED#
Wait for algorithm response generation.
Transit to:
WAITING_FOR_USER_STOP_RECORDINGwhen receivedUSER_START_RECORDINGsignal.ACTOR_ANIMATION_STREAMINGwhen the animation started streaming.WAITING_FOR_ACTOR_LEAVING_FINISHEDwhen response type from the algorithm service isleave.ALGORITHM_GENERATION_FAILEDwhen algorithm service failed to return valid stream data.WAITING_FOR_STREAMED_ANIMATION_INTERRUPTEDwhen receivedUSER_INTERRUPT_ANIMATIONsignal.
ACTOR_ANIMATION_STREAMING#
Receive and feed stream data to runtime. If the stream buffer is exhausted, handle the pause/recover event.
Transit to:
WAITING_FOR_ACTOR_ANIMATION_FINISHEDwhen stream ended or playback finished signals received.WAITING_FOR_STREAMED_ANIMATION_INTERRUPTEDwhen receivedUSER_INTERRUPT_ANIMATIONsignal.ALGORITHM_GENERATION_FAILEDon stream unavailable or unknown errors.
WAITING_FOR_STREAMED_ANIMATION_INTERRUPTED#
Interrupt streamed animation, return to listen state and restart audio recording.
Transit to:
WAITING_FOR_USER_STOP_RECORDINGwhen the interrupt event is sent to runtime and the audio recording started.
WAITING_FOR_ACTOR_ANIMATION_FINISHED#
Wait for character animation to complete and check for relationship and emotion updates.
Transit to:
IDLEwhen receivedANIMATION_FINISHEDsignal.WAITING_FOR_STREAMED_ANIMATION_INTERRUPTEDwhen receivedUSER_INTERRUPT_ANIMATIONsignal.
WAITING_FOR_ACTOR_LEAVING_FINISHED#
Wait for leaving animation to complete.
Transit to:
EXITwhen receivedANIMATION_FINISHEDsignal.
ALGORITHM_GENERATION_FAILED#
Switch to local error/apology animation.
Transit to:
WAITING_FOR_ACTOR_APOLOGIZE_FINISHEDwhen the switch animation signal is sent to runtime.
WAITING_FOR_ACTOR_APOLOGIZE_FINISHED#
Wait for apology animation to complete.
Transit to:
IDLEwhen receivedANIMATION_FINISHEDsignal.
EXIT#
Terminate state machine and notify user.
Transit to:
(terminal state)