Ask the guide with a key
Updated
Pressing Q sends a question to an AI agent from a script with conversation.send; the agent’s thinking, response and error events arrive through its Signal Emitter and are logged.
Click the scene, then press Q to ask the guide a question and read the answer in the log. The answer comes from the AI service: without one, the log shows why the guide could not answer.
Ask the guide with a key
#pragma lifecycle(startup, update)
const QUESTION = 'In one sentence, what can I see in this gallery?';let conversation;
function startup() { conversation = findEntity('Guide').getComponent(AIModelComponent).getConversation(); if (!conversation) return log('The guide is not available here.'); log('The guide is ready. Messages so far:', conversation.getSnapshot().messages.length);
on('guide:ai', (event) => { if (event.eventType === EventType.AIAgent.Thinking) log('The guide is thinking…'); if (event.eventType === EventType.AIAgent.Response) log('Answer:', event.data.text); if (event.eventType === EventType.AIAgent.Error) log('No answer:', event.data.text); });}
function update() { if (!conversation || !Input.keyboard.isKeyReleased(Key.Q)) return; if (conversation.getSnapshot().activeTurnId) return log('The guide is still answering.'); log('Asking:', QUESTION); conversation.send(QUESTION).catch((error) => log('Could not ask:', error.message));}How it works
Section titled “How it works”The script is explained step by step in Ask the guide with a key.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
AskTheGuide.xrproj