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>(() => RunGuarded(context, "{}", () => { var now = DateTimeOffset.Now; var inv = CultureInfo.InvariantCulture; // 12-hour form, parts spelled out so small models echo the digits verbatim instead of recomputing. return Task.FromResult("It is " + now.ToString("h:mm tt", inv) + " on " + now.ToString("dddd, MMMM d, yyyy", inv) + // "%h": a single-char custom format must be prefixed with '%', else .NET reads a lone // "h" as a (nonexistent) STANDARD specifier and throws FormatException. ". Report exactly hour=" + now.ToString("%h", inv) + " minute=" + now.ToString("mm", inv) + " " + now.ToString("tt", inv) + "; keep these digits unchanged."); })), name: Name, description: Description); } } }