# UtilityTools

## Overview

`UtilityTools` provide a simple set of general helper functions, such as `get_current_date_time` and `get_user_location`.

This is the prompt:

```ini
#
# UtilityTools
#
[UtilityTools]
Provides generally useful tools.

[UtilityTools.get_current_date_time]
Returns the current date and time

[UtilityTools.get_user_location]
Returns the user current location
```

The `get_user_location` tool is particularly interesting because it utilizes the geolocation extension from Wisej.NET, enabling the browser to access the PC's location services. The implementation looks like this:

```csharp
[SmartTool.Tool]
[Description("[UtilityTools.get_user_location]")]
protected virtual async Task<string> get_user_location()
{
	_geolocation = _geolocation ?? new Geolocation();

	var tcs = new TaskCompletionSource<string>();
	_geolocation.GetCurrentPosition((position) =>
	{
		tcs.SetResult(position.ToString());
	});

	Application.Update(Application.Current);
	return await tcs.Task;
}
```

Notice that it employs the `TaskCompletionSource` technique to convert a callback into a `Task`. This is necessary because the browser's location services support only callbacks.

## Using UtilityTools

To enable the use of UtilityTools, simply add it to a SmartHub, SmartAdapter, or SmartPrompt.

```csharp
this.hub1.UseTools(new UtilityTools());
this.smartDataEntryAdapter1.UseTools(new UtilityTools());

Console.WriteLine(
    new SmartPrompt()
        .UseTools(new UtilityTools())
        .AskAsync(endpoint, "Where am I?")
        .Result.Text);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/built-in-smarttools/utilitytools.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
