| using System; |
| using System.Globalization; |
| using System.Threading.Tasks; |
| using Microsoft.Extensions.AI; |
| namespace OnDeviceAgent.AgentCore |
| { |
|
|
| public sealed class GetCurrentTimeTool : AgentToolBase |
| { |
| public override string Name => "GetCurrentTime"; |
| public override string Description => |
| "Get the current local time and date. Use when the user asks the time or date (e.g. 'what time is it', " + |
| "'지금 몇시야', '오늘 며칠이야'). Always call this; never state the time or date from your own knowledge."; |
|
|
| public override AITool ToAIFunction(AgentToolContext context) |
| { |
| return AIFunctionFactory.Create( |
| new Func<Task<string>>(() => RunGuarded(context, "{}", () => |
| { |
| var now = DateTimeOffset.Now; |
| var inv = CultureInfo.InvariantCulture; |
| |
| return Task.FromResult("It is " + now.ToString("h:mm tt", inv) + |
| " on " + now.ToString("dddd, MMMM d, yyyy", inv) + |
| |
| |
| ". Report exactly hour=" + now.ToString("%h", inv) + " minute=" + now.ToString("mm", inv) + |
| " " + now.ToString("tt", inv) + "; keep these digits unchanged."); |
| })), |
| name: Name, |
| description: Description); |
| } |
| } |
| } |
|
|