| name | .NET MAUI - Local Chat Client with Tools | ||
|---|---|---|---|
| description | Chat UI demonstrating on-device Apple Intelligence function calling (tools) with weather, calculator, file listing, system info, and timers — no API keys or cloud services required. | ||
| page_type | sample | ||
| languages |
|
||
| products |
|
||
| urlFragment | local-chat-client-with-tools |
A .NET MAUI sample showing how to enhance an on-device LLM with Microsoft.Extensions.AI function calling (tools) using Apple Intelligence. All inference runs locally — no API keys, no cloud services, no cost.
| Prompt buttons | Weather tool | Calculator tool | Multi-tool calls |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
- Using
AppleIntelligenceChatClientfromMicrosoft.Maui.Essentials.AIas a localIChatClient - Supplying a set of
AIFunctiontools toIChatClientviaChatOptions.Tools - Implementing strongly described tool schemas (JSON schema) for better argument selection
- Resolving user-friendly locations to coordinates with the free open-meteo.com API
- Building a MAUI chat UI with template selectors for different message types (text, tool calls)
- Running AI inference entirely on-device with no external API keys
- .NET 10 SDK
- iOS 26.0+ or macCatalyst 26.0+ device/simulator with Apple Intelligence enabled
- No API keys or cloud accounts needed
| Tool | Name | Purpose | Notes |
|---|---|---|---|
| WeatherTool | get_weather |
Current conditions for a location | Geocodes via open-meteo.com, then fetches forecast — free, no API key |
| CalculatorTool | calculate |
Evaluate arithmetic / percentages | Sanitizes expression & returns formatted result |
| FileOperationsTool | list_files |
List files & folders in a common or given path | Limits count; resolves shortcuts (Documents, Desktop, Downloads) |
| SystemInfoTool | get_system_info |
Battery, storage, memory, device info | Returns live device values on Apple platforms |
| TimerTool | set_timer |
Create a one‑shot timer with title | Keeps in-memory timers; shows alert on completion |
Each tool is created via AIFunctionFactory.Create using strongly-typed methods and AOT-compatible JSON serialization via ToolJsonContext.
MauiProgram.cs– RegistersIChatClientviaAppleIntelligenceChatClientwithUseFunctionInvocation()for automatic tool dispatch, and registers all tool functions.Services/Tools/*.cs– Tool implementations usingAIFunctionFactory.Createfor clean, factory-based tool registration.ViewModels/ChatViewModel.cs– Collects tools and invokes_chatClient.GetStreamingResponseAsyncpassingChatOptions.Tools.ViewModels/ChatMessageViewModel.cs– Base view model for chat messages, withTextMessageViewModelandToolCallMessageViewModelsubclasses.MainPage.xaml– Chat layout withChatTemplateSelector, EmptyView sample prompts, and aCleartoolbar item (resets to EmptyView).
Try:
- "What's the weather in Seattle?"
- "Calculate 15% tip on $47.50"
- "List the files in my Documents folder"
- "Show me current battery level and available storage"
- "Set a 5-minute timer for my coffee break"
- "What's 25 × 18 + 150?"
- "Check the weather in Tokyo and Cape Town"
# iOS simulator
dotnet build -f net10.0-ios -t:Run
# macCatalyst
dotnet build -f net10.0-maccatalyst -t:RunUse a sample prompt or type your own. Use the toolbar Clear to reset and revisit the instructional prompt list.
Note: This sample only runs on Apple platforms (iOS / macCatalyst) with Apple Intelligence. Other platforms will throw
PlatformNotSupportedExceptionat startup.
- User sends natural language input.
ChatViewModelbuildsChatOptionswith the registered tool objects.AppleIntelligenceChatClient(wrapped withUseFunctionInvocation()) decides if any tool(s) should be invoked and executes them, passing JSON arguments that conform to each tool's declared schema.- Tool result objects surface in the assistant response and are bound to specialized UI cards.
- UI shows structured cards or plain text depending on
ChatMessageflags.
This sample is a local-only variant of the ChatClientWithTools sample. The key differences:
| ChatClientWithTools | LocalChatClientWithTools | |
|---|---|---|
| LLM provider | Azure OpenAI (cloud) | Apple Intelligence (on-device) |
| API keys | Required (Azure + optional OpenWeatherMap) | None |
| Weather API | OpenWeatherMap (key required) | open-meteo.com (free, keyless) |
| Platforms | Windows, iOS, macCatalyst, Android | iOS, macCatalyst only |
| NuGet packages | Azure.AI.OpenAI, Microsoft.Extensions.AI.OpenAI | Microsoft.Maui.Essentials.AI |
- EmptyView with categorized starter buttons (Weather / Calculator / Files / System Info / Timers).
- Rich result cards styled with color-coded borders.
- Toolbar "Clear" to wipe conversation state quickly (teaching scenario friendly).
- Auto-scroll to the latest message.
- Microsoft.Extensions.AI overview: https://learn.microsoft.com/dotnet/ai/microsoft-extensions-ai
- Apple Intelligence in .NET MAUI: https://learn.microsoft.com/dotnet/maui/platform-integration/communication/ai
- CommunityToolkit.Mvvm: https://learn.microsoft.com/dotnet/communitytoolkit/mvvm/
- Requires iOS 26.0+ or macCatalyst 26.0+ with Apple Intelligence available and enabled.
- All AI inference runs on-device — no data leaves the device for LLM processing.
- Weather data comes from open-meteo.com (free, open-source weather API).
- Timers are in-memory only (lost on app exit) and surface completion via a
DisplayAlertAsyncdialog. - File operations are intentionally conservative; expand with care for security.
- This sample emphasizes pedagogy over exhaustive production hardening.
For the cloud-hosted version of this sample, see ChatClientWithTools in the same folder tree.



