This article shows adding local AI personality to browser games using Foundry Local and vanilla JavaScript. It explains progressive enhancement, a Node.js proxy pattern, context-aware commentary generation, privacy and latency benefits, graceful degradation, and includes client and server code examples.
Browser games can now include local AI personalities for dynamic, context-aware commentary. This change uses Foundry Local and a Node.js proxy to run small language models on-device.
Main feature/change and impact
The main change is integrating on-device SLMs to generate real-time game commentary. This removes cloud costs and preserves player privacy. Latency drops to milliseconds, so commentary feels immediate. Games remain fully playable without AI, preserving compatibility. Developers get a scalable way to add personality without backend infrastructure or user data exposure.Practical implications
Developers must add a local proxy to communicate with Foundry Local. The game sends concise game state payloads for events like wave_complete or player_hit. AI responses are short, context-aware, and non-blocking. Implement graceful degradation for unavailable AI. Test for performance on mid-range hardware and ensure the core game logic never depends on AI availability to run.“You are an AI commander providing brief, encouraging commentary for a Space Invaders game. Be energetic, supportive, and sometimes humorous. Keep responses to 1-2 sentences maximum. Reference specific game metrics when relevant.”Browser games gain personality without cloud dependencies, enabling offline play and predictable costs. Next steps for teams include adding health checks, fallback messages, and telemetry-free testing on representative devices. Implement progressive enhancement and monitor CPU and memory usage when enabling SLMs.
Key points from the article:
Related Coverage:
- Benchmarking Local AI Models
- GitHub Copilot SDK and Hybrid AI in Practice: Automating README to PPT Transformation
- Claude Opus 4.6: Anthropic’s powerful model for coding, agents, and enterprise workflows is now available in Microsoft Foundry
From the Microsoft Developer Community Blog articles
