google/xb-add-ai
>- Implement AI behavior in an XR Blocks app. Use when adding a Gemini or OpenAI query, Gemini Live voice or vision, generated images, scene grounding, or model-requested tools that produce an observable XR outcome.
npx skills add https://github.com/google/xrblocks --skill xb-add-ai
Build complete AI behavior: intentional input → provider → validated
response → observable app outcome. Use ../xb-build-app/SKILL.md
first when the app shell or primary interaction is missing.
Name the input, provider branch, response modality, intended consumer, data sent
off-device, and user-visible waiting/unavailable/error states. Treat camera,
microphone, screenshots, prompts, and scene context as separate disclosures.
Complete this step when success changes the scene, UI, speech, or an asset—and
each disclosed input is necessary for that change.
Read ../../src/xrblocks.ts, then the relevant AI
implementation and a working app:
../../src/ai/AI.ts,../../src/ai/Gemini.ts, and
../../templates/6_ai;
../../src/addons/ai/GeminiManager.ts
and ../../templates/7_ai_live;
../../docs/docs/manual/Context.mdxand ../../src/context.
For exact current signatures and provider limits, read
references/current-api.md. For a Live, tool, or
grounded branch, also read
references/live-tools-grounding.md.
Prefer source and installed provider types when prose or an older skill differs.
Complete this step when every planned symbol is public and the selected provider
supports every required operation.
await xb.ai.query({prompt}) for either provider; useGemini multipart input for images or structured parts.
the GeminiManager addon when its capture, audio, tool, and cleanup ownership
matches the app.
generate() when the returned data URL becomes anactual texture, image, or other app asset.
narrow xb.Tool, validate its arguments again at execution, and return a
structured success or failure result.
The branch is selected when its latency, modality, provider support, and resource
ownership match the AI contract. Treat src/agent as work in progress; start
from xb.ai, xb.Tool, and the Live addon unless the app specifically needs an
existing exported agent.
Before xb.init(options), call options.enableAI() and configure
options.ai.model plus the matching provider options. At interaction time,
guard queries with xb.ai.isAvailable() and Live startup with
xb.ai.isLiveAvailable(). Lock or disable repeated triggers while a request is
in flight. Accept null, empty text, rejected requests, and disconnection as
normal observable states.
For Live, register callbacks before connecting, resolve readiness from onopen,
send nested typed realtime inputs, stop playback on interruption, and make
onerror/onclose converge on the same idempotent cleanup. Stop the Live
session, microphone capture, audio playback, camera/frame timers, and app-owned
media tracks from the app's stop/dispose path.
Prototype credentials may come from provider options, ?key=, provider-specific
URL parameters, or keys.json. Production browser code uses a server-controlled
proxy; Gemini Live clients use short-lived credentials such as ephemeral tokens.
Long-lived provider keys never ship in app code, URLs, static assets, logs, or
commits.
Complete this step when one intentional input reaches its intended consumer,
concurrent starts are controlled, and every acquired resource has one cleanup
owner.
Run code-level checks and startup smoke available without requiring a user-style
conversation. Confirm provider configuration, availability guards, request and
response types, UI states, tool validation, disclosure text, and cleanup paths
are implemented. When safe prototype credentials are already available, a
single non-interactive provider request may confirm connectivity.
Give the user the exact trigger, required credentials and permissions, data
sent off-device, expected waiting/success/error states, and recovery steps. For
Live, include open, interruption, remote close, local stop, and restart checks.
For tools, include valid, invalid, unknown, and failed tool outcomes.
Finish when the AI implementation is complete and the user can evaluate its
real provider behavior without discovering setup, disclosures, expected states,
or cleanup behavior from source.
Take google/xb-add-ai from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.