using System; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.AI; namespace OnDeviceAgent.AgentCore { public sealed class SetVoiceTool : AgentToolBase { readonly Func> m_Apply; public SetVoiceTool(Func> apply) { m_Apply = apply; } public override string Name => "SetVoice"; public override string Description => "Switch the assistant's spoken voice between male and female. Use when the user asks to change voice (e.g. 'use a male voice', '남자 목소리로 바꿔줘', '여자 목소리로 바꿔줘'). Pass gender as 'male' or 'female'."; public override AITool ToAIFunction(AgentToolContext context) { Task Run([System.ComponentModel.Description("the requested voice gender: 'male' or 'female'")] string gender) { var argsJson = "{\"gender\":\"" + (gender ?? string.Empty).Replace("\"", "'") + "\"}"; Func> body = m_Apply == null ? null : () => m_Apply(gender, context.CancellationToken); return RunGuarded(context, argsJson, body, "Voice switching is not configured."); } return AIFunctionFactory.Create((Func>)Run, name: Name, description: Description); } } }