[Feature] Add Microsoft.Maui.Essentials.AI - Android / Gemini Nano#33609
Draft
mattleibow wants to merge 20 commits into
Draft
[Feature] Add Microsoft.Maui.Essentials.AI - Android / Gemini Nano#33609mattleibow wants to merge 20 commits into
mattleibow wants to merge 20 commits into
Conversation
This was referenced Jan 20, 2026
Open
… workflow Introduces the Essentials.AI module with a Trip Planner sample demonstrating production-ready AI integration patterns using Microsoft.Extensions.AI and Microsoft.Agents.AI. Sample Application (Essentials.AI.Sample): - 4-agent workflow: TravelPlanner → Researcher → ItineraryPlanner → Translator - RAG with embedding-based semantic search for destination matching - Streaming JSON responses with partial deserialization for progressive UI - Function calling (findPointsOfInterest tool) and structured JSON output - Conditional translation branching for non-English requests Services & Utilities: - StreamingJsonDeserializer, JsonMerger, BufferedChatClient - DataService (landmarks + embeddings), TaggingService, ItineraryService Library Skeleton (Essentials.AI): - Multi-platform TFM support with PublicAPI tracking - Foundation for future Apple Intelligence, Windows Copilot, Gemini Nano Test Infrastructure: - Unit tests: JSON streaming, merging, buffering (real AI response data) - Device tests: Reusable IChatClient/IEmbeddingGenerator base classes - Benchmarks: BenchmarkDotNet infrastructure
- Add AppleBindings.targets for reusable XcodeProject logic - Automatic XcodeProject handling (macOS only) - Pre-built artifact inclusion for Windows CI builds - IntelliSense support for generated binding files - Update Core.csproj to use XcodeProject instead of pre-built xcframework - Build MauiPlatformInterop.xcframework from source on macOS - Use downloaded artifacts on Windows CI - Update stage-pack.yml pipeline - Add pack_net_macOS job to build and publish Mac native binaries - Add download task to pack_net_Windows job to retrieve artifacts - Windows pack job now depends on macOS job completion - Remove obsolete files - Deleted MauiPlatformInterop.xcframework.zip (now built dynamically) - Deleted build-xcframework.sh (XcodeProject handles this)
Introduce AI capabilities for Android platform including: Core Components: - GeminiNanoChatClient: Chat completion client using Google MLKit GenAI (Gemini Nano) with streaming support via IChatClient - GeminiNanoExtensions: Convenience method to convert IGenerativeModel to IChatClient - (internal) GenerativeModelExtensions: C# async wrappers for Kotlin coroutine-based model operations Native Kotlin Library (AndroidNative/essentialsai): - Kotlin implementation for MLKit GenAI coroutine bridging - GenerativeModelExtensions with CancellationSignal support - Listener interfaces for async callbacks (ContentGenerationListener, StreamContentGenerationListener, ModelStatusListener, ModelWarmupListener) Samples: - Update Essentials.AI.Sample to use Gemini Nano on Android, falling back to OpenAI on other platforms - Cloud embeddings via OpenAI (Android lacks local embedding API) Note: Android/Gemini Nano does not provide a local embedding API, so embeddings still require cloud services (OpenAI/Azure).
056575f to
9c7ba64
Compare
- Wrap 'using Microsoft.Maui.Essentials.AI' in #if ANDROID since the namespace only exists on Android (GeminiNanoChatClient) - Remove condition from Android SupportedOSPlatformVersion in Directory.Build.targets to ensure all Android projects use API 23+ (required by AndroidX updates) - Update explicit minSdkVersion from 21 to 23 in affected projects and templates
- Benchmarks.Droid: Update from 21 to 23 (AndroidX requires 23) - Essentials.AI.Sample: Add explicit minSdkVersion 26 (MLKit GenAI requires 26)
Use MSBuild::VersionLessThan to only set Android minSdkVersion to 23 if the project doesn't already specify a higher value. This allows projects like Essentials.AI.Sample (API 26) to keep their higher requirement.
This was referenced May 15, 2026
This was referenced May 21, 2026
Contributor
|
/review -b feature/refactor-copilot-yml |
This comment has been minimized.
This comment has been minimized.
Contributor
|
/review -b feature/enhanced-reviewer -p android |
Collaborator
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Important
This PR is huge because it is based on 2 PRs, one of which is the main part of the code.
The true diff is dev/alt-main...dev/ai-android
Description
This PR adds Android Gemini Nano (MLKit GenAI) support to
Microsoft.Maui.Essentials.AI, enabling on-device AI chat capabilities through the Microsoft.Extensions.AI abstractions on Android.What's Added
Android Gemini Nano Integration
GeminiNanoChatClient - Full
IChatClientimplementation for Google MLKit GenAI:GetResponseAsync()for complete responsesGetStreamingResponseAsync()returnsIAsyncEnumerable<ChatResponseUpdate>for real-time UI updatesGeneration.Instance.ClientsingletonIGenerativeModelCancellationTokensupport via AndroidCancellationSignalIChatClientpipeline builders (.AsBuilder().UseLogging().Build())Extension Methods:
IGenerativeModel.AsIChatClient()- Wrap existingIGenerativeModelasIChatClientInternal C# Extensions:
GenerativeModelExtensions- Async wrappers converting Kotlin coroutines to C# Task-based patternsGenerateContentAsync()- Non-streaming content generationGenerateContentStreamAsync()- Streaming content generation asIAsyncEnumerableCheckStatusAsync()- Model availability checkWarmupAsync()- Model warmup for better first-response latencyCapabilities
GetResponseAsync()IAsyncEnumerable<ChatResponseUpdate>via Kotlin Flow bridgePromptPrefixinGenerateContentRequestTextPartDataContent→ImagePart(one per request)GenerateContentRequest.Builder.TemperatureGenerateContentRequest.Builder.TopKGenerateContentRequest.Builder.SeedCancellationSignalNote: The sample app uses OpenAI for embeddings on Android since Gemini Nano doesn't provide a local embedding API.
Architecture: Kotlin Native Layer & C# Integration
The Gemini Nano integration uses a two-layer architecture to bridge .NET with Google's Kotlin coroutine-based MLKit GenAI:
Why Kotlin is Required:
suspendfunctions,Flow<T>)Layer Responsibilities:
IChatClientimplementation, message conversion, response mappingWhy
Unified AI API: Same
IChatClientabstractions work with cloud AI (OpenAI, Azure) or on-device (Gemini Nano, Apple Intelligence, Windows Copilot Runtime)On-Device Privacy: Gemini Nano runs entirely on-device, keeping user data private
Cross-Platform Parity: Android developers get the same AI capabilities as Apple and Windows platform developers
Native Library Build
The Kotlin native library is located at
src/AI/src/AndroidNative/:Build with:
./gradlew :essentialsai:assembleReleasePublic API Surface
Namespace:
Microsoft.Maui.Essentials.AIUsage Examples:
Sample App Changes
The
Essentials.AI.Samplenow automatically uses:This is configured via conditional compilation in
MauiProgram.cs.Requirements
Files Changed
Total: 23 files changed, +1094/-2 lines