AI Tools
Give an LLM agent read-only awareness of where the user is via Microsoft.Extensions.AI tool functions — “Where am I?”, “How far is it to the airport from here?”, “Roughly how long to cycle to the park?”. The agent can learn the current position and reason about distance and travel time to a destination, but never writes location data.
The AI layer (Shiny.Locations.Extensions.AI) sits on top of IGpsManager and reads the last cached GPS fix.
-
Install the AI extensions package
Terminal window dotnet add package Shiny.Locations.Extensions.AI -
Register GPS and the AI tools
using Shiny.Locations;using Shiny.Locations.Extensions.AI;builder.Services.AddGps();builder.Services.AddLocationAITool(); // read-only; there is no write capability for GPS -
Resolve
LocationAIToolsand hand.Toolsto your chat clientvar location = sp.GetRequiredService<LocationAITools>();var response = await chatClient.GetResponseAsync(messages,new ChatOptions { Tools = [.. location.Tools] });
Read-only by design
Section titled “Read-only by design”GPS is exposed through a single parameterless AddLocationAITool() call — there is no write capability, and therefore no builder or capability to opt-in to. Registering the tools is not an OS permission prompt; location permission is granted separately by the platform.
Generated Tools Reference
Section titled “Generated Tools Reference”| Tool | Arguments | Returns |
|---|---|---|
get_current_location | (none) | Latitude/longitude, accuracy, altitude, speed, heading, isStationary, and the reading timestamp. |
get_distance_to | latitude, longitude | Great-circle distance (km/mi/m) and compass bearing from the current location to the destination. |
estimate_travel_time | latitude, longitude, mode?, speedKmh? | Straight-line ETA. mode ∈ walking (5 km/h), cycling (15), transit (30), driving (50); speedKmh overrides mode. |
Shiny.Locations.Extensions.AI is IsAotCompatible — tool schemas are hand-built and results are emitted as JsonNode, so there is no reflection-based serialization in the tool path.