diff --git a/agents/my_basic_agent_1_2_9.py b/agents/my_basic_agent_1_2_9.py index e6a9a58..c174646 100644 --- a/agents/my_basic_agent_1_2_9.py +++ b/agents/my_basic_agent_1_2_9.py @@ -1018,6 +1018,16 @@ async def entrypoint(ctx: JobContext, avatar_dispatcher_url: str = None, vision_ initial_instructions = participant.attributes.get("instructions") logger.info(f"User selected instructions: {initial_instructions}") + # Read talking_mode from frontend state + initial_talking_mode = DEFAULT_TALKING_MODE + if participant.attributes.get("talking_mode"): + frontend_talking_mode = participant.attributes.get("talking_mode") + if frontend_talking_mode in ["push_to_talk", "realtime"]: + initial_talking_mode = frontend_talking_mode + logger.info(f"Initializing talking_mode from frontend: {initial_talking_mode}") + else: + logger.warning(f"Invalid talking_mode from frontend: {frontend_talking_mode}, using default: {initial_talking_mode}") + # Replace the datetime and weekday placeholders to avoid KeyError from other braces in the prompt initial_instructions = initial_instructions.replace("{datetime}", current_time) initial_instructions = initial_instructions.replace("{weekday}", current_weekday) @@ -1128,7 +1138,7 @@ async def entrypoint(ctx: JobContext, avatar_dispatcher_url: str = None, vision_ ) # disable input audio at the start - _talking_mode = DEFAULT_TALKING_MODE + _talking_mode = initial_talking_mode if _talking_mode == "push_to_talk": session.input.set_audio_enabled(False) else: diff --git a/src/components/playground/PhoneSimulator.tsx b/src/components/playground/PhoneSimulator.tsx index c9e71be..5b35fd4 100644 --- a/src/components/playground/PhoneSimulator.tsx +++ b/src/components/playground/PhoneSimulator.tsx @@ -78,6 +78,32 @@ export function PhoneSimulator({ } }, [config.settings.attributes]); + // Set talking_mode attribute when connected or when mode changes + useEffect(() => { + if (roomState === ConnectionState.Connected && localParticipant) { + const talkingMode = isPushToTalkMode ? "push_to_talk" : "realtime"; + try { + // Get current attributes to preserve them + const currentAttributes: Record = {}; + // Note: LiveKit's setAttributes replaces all attributes, so we need to merge + // with existing ones from config if any + const configAttributes = config.settings.attributes || []; + configAttributes.forEach(attr => { + if (attr.key && attr.value) { + currentAttributes[attr.key] = attr.value; + } + }); + // Set talking_mode along with other attributes + localParticipant.setAttributes({ + ...currentAttributes, + talking_mode: talkingMode, + }); + } catch (error) { + console.error("Failed to set talking_mode attribute:", error); + } + } + }, [roomState, localParticipant, isPushToTalkMode, config.settings.attributes]); + const [currentTime, setCurrentTime] = useState(""); const [visualizerPosition, setVisualizerPosition] = useState({ @@ -1255,7 +1281,7 @@ export function PhoneSimulator({ )} {/* Realtime Mode Layout */} - {!isPushToTalkMode && ( + {!isPushToTalkMode && phoneMode !== "hand_off" && ( <> {/* Important Message Mode - Centered End Call Button */} {phoneMode === "important_message" ? ( @@ -1270,22 +1296,20 @@ export function PhoneSimulator({ ) : (
{/* Mic Toggle */} - {phoneMode !== "hand_off" && ( - - )} + {/* End Call Button */}