Sky-Kim's picture
Initial commit
2e7837a
Raw
History Blame Contribute Delete
1.43 kB
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.AI;
namespace OnDeviceAgent.AgentCore
{
public sealed class SetVoiceTool : AgentToolBase
{
readonly Func<string, CancellationToken, Task<string>> m_Apply;
public SetVoiceTool(Func<string, CancellationToken, Task<string>> 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<string> Run([System.ComponentModel.Description("the requested voice gender: 'male' or 'female'")] string gender)
{
var argsJson = "{\"gender\":\"" + (gender ?? string.Empty).Replace("\"", "'") + "\"}";
Func<Task<string>> body = m_Apply == null ? null : () => m_Apply(gender, context.CancellationToken);
return RunGuarded(context, argsJson, body, "Voice switching is not configured.");
}
return AIFunctionFactory.Create((Func<string, Task<string>>)Run, name: Name, description: Description);
}
}
}