refine agent utility hook

This commit is contained in:
Jicheng Lu 2024-11-21 00:50:55 -06:00
parent 91e52c5547
commit 5d1430dddf
34 changed files with 176 additions and 387 deletions

View file

@ -54,7 +54,7 @@ public abstract class AgentHookBase : IAgentHook
return true;
}
public virtual void OnAgentLoaded(Agent agent)
public virtual void OnAgentLoaded(Agent agent)
{
}

View file

@ -59,5 +59,5 @@ public interface IAgentService
PluginDef GetPlugin(string agentId);
IEnumerable<string> GetAgentUtilities();
IEnumerable<AgentUtility> GetAgentUtilityOptions();
}

View file

@ -2,5 +2,5 @@ namespace BotSharp.Abstraction.Agents;
public interface IAgentUtilityHook
{
void AddUtilities(List<string> utilities);
void AddUtilities(List<AgentUtility> utilities);
}

View file

@ -57,14 +57,14 @@ public partial class AgentService : IAgentService
return userAgents;
}
public IEnumerable<string> GetAgentUtilities()
public IEnumerable<AgentUtility> GetAgentUtilityOptions()
{
var utilities = new List<string>();
var utilities = new List<AgentUtility>();
var hooks = _services.GetServices<IAgentUtilityHook>();
foreach (var hook in hooks)
{
hook.AddUtilities(utilities);
}
return utilities.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().OrderBy(x => x).ToList();
return utilities.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderBy(x => x.Name).ToList();
}
}

View file

@ -1,3 +1,4 @@
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Users.Enums;
namespace BotSharp.OpenAPI.Controllers;
@ -153,9 +154,9 @@ public class AgentController : ControllerBase
return await _agentService.DeleteAgent(agentId);
}
[HttpGet("/agent/utilities")]
public IEnumerable<string> GetAgentUtilities()
[HttpGet("/agent/utility/options")]
public IEnumerable<AgentUtility> GetAgentUtilityOptions()
{
return _agentService.GetAgentUtilities();
return _agentService.GetAgentUtilityOptions();
}
}

View file

@ -17,7 +17,6 @@ public class AudioHandlerPlugin : IBotSharpPlugin
});
services.AddScoped<IAudioCompletion, NativeWhisperProvider>();
services.AddScoped<IAgentHook, AudioHandlerHook>();
services.AddScoped<IAgentUtilityHook, AudioHandlerUtilityHook>();
}
}

View file

@ -1,27 +0,0 @@
using BotSharp.Abstraction.Agents.Settings;
namespace BotSharp.Plugin.AudioHandler.Hooks;
public class AudioHandlerHook : AgentHookBase, IAgentHook
{
private const string HANDLER_AUDIO = "handle_audio_request";
public override string SelfId => string.Empty;
public AudioHandlerHook(IServiceProvider services, AgentSettings settings)
: base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var utilityLoad = new AgentUtility
{
Name = UtilityName.AudioHandler,
Functions = [new(HANDLER_AUDIO)],
Templates = [new($"{HANDLER_AUDIO}.fn")]
};
base.OnAgentLoaded(agent);
}
}

View file

@ -2,8 +2,17 @@ namespace BotSharp.Plugin.AudioHandler.Hooks;
public class AudioHandlerUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private const string HANDLER_AUDIO = "handle_audio_request";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.AudioHandler);
var utility = new AgentUtility
{
Name = UtilityName.AudioHandler,
Functions = [new(HANDLER_AUDIO)],
Templates = [new($"{HANDLER_AUDIO}.fn")]
};
utilities.Add(utility);
}
}

View file

@ -20,7 +20,6 @@ namespace BotSharp.Plugin.EmailHandler
return settingService.Bind<EmailSenderSettings>("EmailSender");
});
services.AddScoped<IAgentHook, EmailHandlerHook>();
services.AddScoped<IAgentUtilityHook, EmailHandlerUtilityHook>();
var emailReaderSettings = new EmailReaderSettings();

View file

@ -1,30 +0,0 @@
using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Agents.Settings;
using BotSharp.Plugin.EmailHandler.Enums;
namespace BotSharp.Plugin.EmailHandler.Hooks;
public class EmailHandlerHook : AgentHookBase
{
private static string EMAIL_READER_FN = "handle_email_reader";
private static string EMAIL_SENDER_FN = "handle_email_sender";
public override string SelfId => string.Empty;
public EmailHandlerHook(IServiceProvider services, AgentSettings settings)
: base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var utilityLoad = new AgentUtility
{
Name = UtilityName.EmailHandler,
Functions = [new(EMAIL_READER_FN), new(EMAIL_SENDER_FN)],
Templates = [new($"{EMAIL_READER_FN}.fn"), new($"{EMAIL_SENDER_FN}.fn")]
};
base.OnAgentLoaded(agent);
}
}

View file

@ -5,8 +5,18 @@ namespace BotSharp.Plugin.EmailHandler.Hooks;
public class EmailHandlerUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private static string EMAIL_READER_FN = "handle_email_reader";
private static string EMAIL_SENDER_FN = "handle_email_sender";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.EmailHandler);
var utility = new AgentUtility
{
Name = UtilityName.EmailHandler,
Functions = [new(EMAIL_READER_FN), new(EMAIL_SENDER_FN)],
Templates = [new($"{EMAIL_READER_FN}.fn"), new($"{EMAIL_SENDER_FN}.fn")]
};
utilities.Add(utility);
}
}

View file

@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BotSharp.Abstraction.Plugins;
using BotSharp.Abstraction.Settings;
using BotSharp.Plugin.ExcelHandler.Helpers.MySql;
@ -30,7 +25,6 @@ public class ExcelHandlerPlugin : IBotSharpPlugin
});
services.AddScoped<IAgentUtilityHook, ExcelHandlerUtilityHook>();
services.AddScoped<IAgentHook, ExcelHandlerHook>();
services.AddScoped<ISqliteDbHelpers, SqliteDbHelpers>();
services.AddScoped<IMySqlDbHelper, MySqlDbHelpers>();
services.AddScoped<ISqliteService, SqliteService>();

View file

@ -1,25 +0,0 @@
namespace BotSharp.Plugin.ExcelHandler.Hooks;
public class ExcelHandlerHook : AgentHookBase, IAgentHook
{
private const string HANDLER_EXCEL = "handle_excel_request";
public override string SelfId => string.Empty;
public ExcelHandlerHook(IServiceProvider services, AgentSettings settings) : base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var utilityLoad = new AgentUtility
{
Name = UtilityName.ExcelHandler,
Functions = [new(HANDLER_EXCEL)],
Templates = [new($"{HANDLER_EXCEL}.fn")]
};
base.OnAgentLoaded(agent);
}
}

View file

@ -2,8 +2,17 @@ namespace BotSharp.Plugin.ExcelHandler.Hooks;
public class ExcelHandlerUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private const string HANDLER_EXCEL = "handle_excel_request";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.ExcelHandler);
var utility = new AgentUtility
{
Name = UtilityName.ExcelHandler,
Functions = [new(HANDLER_EXCEL)],
Templates = [new($"{HANDLER_EXCEL}.fn")]
};
utilities.Add(utility);
}
}

View file

@ -19,7 +19,6 @@ public class FileHandlerPlugin : IBotSharpPlugin
return settingService.Bind<FileHandlerSettings>("FileHandler");
});
services.AddScoped<IAgentHook, FileHandlerHook>();
services.AddScoped<IAgentUtilityHook, FileHandlerUtilityHook>();
}

View file

@ -1,48 +0,0 @@
namespace BotSharp.Plugin.FileHandler.Hooks;
public class FileHandlerHook : AgentHookBase, IAgentHook
{
private const string READ_IMAGE_FN = "read_image";
private const string READ_PDF_FN = "read_pdf";
private const string GENERATE_IMAGE_FN = "generate_image";
private const string EDIT_IMAGE_FN = "edit_image";
public override string SelfId => string.Empty;
public FileHandlerHook(IServiceProvider services, AgentSettings settings) : base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var utilityLoads = new List<AgentUtility>
{
new AgentUtility
{
Name = UtilityName.ImageGenerator,
Functions = [new(GENERATE_IMAGE_FN)],
Templates = [new($"{GENERATE_IMAGE_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.ImageReader,
Functions = [new(READ_IMAGE_FN)],
Templates = [new($"{READ_IMAGE_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.ImageEditor,
Functions = [new(EDIT_IMAGE_FN)],
Templates = [new($"{EDIT_IMAGE_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.PdfReader,
Functions = [new(READ_PDF_FN)],
Templates = [new($"{READ_PDF_FN}.fn")]
}
};
base.OnAgentLoaded(agent);
}
}

View file

@ -2,11 +2,42 @@ namespace BotSharp.Plugin.FileHandler.Hooks;
public class FileHandlerUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private const string READ_IMAGE_FN = "read_image";
private const string READ_PDF_FN = "read_pdf";
private const string GENERATE_IMAGE_FN = "generate_image";
private const string EDIT_IMAGE_FN = "edit_image";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.ImageGenerator);
utilities.Add(UtilityName.ImageReader);
utilities.Add(UtilityName.ImageEditor);
utilities.Add(UtilityName.PdfReader);
var items = new List<AgentUtility>
{
new AgentUtility
{
Name = UtilityName.ImageGenerator,
Functions = [new(GENERATE_IMAGE_FN)],
Templates = [new($"{GENERATE_IMAGE_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.ImageReader,
Functions = [new(READ_IMAGE_FN)],
Templates = [new($"{READ_IMAGE_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.ImageEditor,
Functions = [new(EDIT_IMAGE_FN)],
Templates = [new($"{EDIT_IMAGE_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.PdfReader,
Functions = [new(READ_PDF_FN)],
Templates = [new($"{READ_PDF_FN}.fn")]
}
};
utilities.AddRange(items);
}
}

View file

@ -1,28 +0,0 @@
using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Agents.Settings;
namespace BotSharp.Plugin.HttpHandler.Hooks;
public class HttpHandlerHook : AgentHookBase
{
private static string HTTP_HANDLER_FN = "handle_http_request";
public override string SelfId => string.Empty;
public HttpHandlerHook(IServiceProvider services, AgentSettings settings)
: base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var utilityLoad = new AgentUtility
{
Name = UtilityName.HttpHandler,
Functions = [new(HTTP_HANDLER_FN)],
Templates = [new($"{HTTP_HANDLER_FN}.fn")]
};
base.OnAgentLoaded(agent);
}
}

View file

@ -4,8 +4,17 @@ namespace BotSharp.Plugin.HttpHandler.Hooks;
public class HttpHandlerUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private static string HTTP_HANDLER_FN = "handle_http_request";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.HttpHandler);
var utility = new AgentUtility
{
Name = UtilityName.HttpHandler,
Functions = [new(HTTP_HANDLER_FN)],
Templates = [new($"{HTTP_HANDLER_FN}.fn")]
};
utilities.Add(utility);
}
}

View file

@ -20,7 +20,6 @@ public class HttpHandlerPlugin : IBotSharpPlugin
return settingService.Bind<HttpHandlerSettings>("HttpHandler");
});
services.AddScoped<IAgentHook, HttpHandlerHook>();
services.AddScoped<IAgentUtilityHook, HttpHandlerUtilityHook>();
}
}

View file

@ -1,26 +0,0 @@
namespace BotSharp.Plugin.KnowledgeBase.Hooks;
public class KnowledgeBaseAgentHook : AgentHookBase, IAgentHook
{
private const string KNOWLEDGE_RETRIEVAL_FN = "knowledge_retrieval";
public override string SelfId => string.Empty;
public KnowledgeBaseAgentHook(IServiceProvider services, AgentSettings settings)
: base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var utilityLoad = new AgentUtility
{
Name = UtilityName.KnowledgeRetrieval,
Functions = [new(KNOWLEDGE_RETRIEVAL_FN)],
Templates = [new($"{KNOWLEDGE_RETRIEVAL_FN}.fn")]
};
base.OnAgentLoaded(agent);
}
}

View file

@ -2,8 +2,17 @@ namespace BotSharp.Plugin.KnowledgeBase.Hooks;
public class KnowledgeBaseUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private const string KNOWLEDGE_RETRIEVAL_FN = "knowledge_retrieval";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.KnowledgeRetrieval);
var utility = new AgentUtility
{
Name = UtilityName.KnowledgeRetrieval,
Functions = [new(KNOWLEDGE_RETRIEVAL_FN)],
Templates = [new($"{KNOWLEDGE_RETRIEVAL_FN}.fn")]
};
utilities.Add(utility);
}
}

View file

@ -25,7 +25,6 @@ public class KnowledgeBasePlugin : IBotSharpPlugin
services.AddSingleton<IPdf2TextConverter, PigPdf2TextConverter>();
services.AddScoped<IAgentUtilityHook, KnowledgeBaseUtilityHook>();
services.AddScoped<IAgentHook, KnowledgeBaseAgentHook>();
services.AddScoped<IKnowledgeService, KnowledgeService>();
}

View file

@ -2,10 +2,6 @@ namespace BotSharp.Plugin.Planner.Hooks;
public class PlannerAgentHook : AgentHookBase
{
private const string PRIMARY_STAGE_FN = "plan_primary_stage";
private const string SECONDARY_STAGE_FN = "plan_secondary_stage";
private const string SUMMARY_FN = "plan_summary";
public override string SelfId => BuiltInAgentId.Planner;
public PlannerAgentHook(IServiceProvider services, AgentSettings settings)
@ -31,24 +27,4 @@ public class PlannerAgentHook : AgentHookBase
return true;
}
public override void OnAgentLoaded(Agent agent)
{
var utilityLoad = new AgentUtility
{
Name = UtilityName.TwoStagePlanner,
Functions = [
new(PRIMARY_STAGE_FN),
new(SECONDARY_STAGE_FN),
new(SUMMARY_FN)
],
Templates = [
new($"{PRIMARY_STAGE_FN}.fn"),
new($"{SECONDARY_STAGE_FN}.fn"),
new($"{SUMMARY_FN}.fn")
]
};
base.OnAgentLoaded(agent);
}
}

View file

@ -2,8 +2,27 @@ namespace BotSharp.Plugin.Planner.Hooks;
public class PlannerUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private const string PRIMARY_STAGE_FN = "plan_primary_stage";
private const string SECONDARY_STAGE_FN = "plan_secondary_stage";
private const string SUMMARY_FN = "plan_summary";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.TwoStagePlanner);
var utility = new AgentUtility
{
Name = UtilityName.TwoStagePlanner,
Functions = [
new(PRIMARY_STAGE_FN),
new(SECONDARY_STAGE_FN),
new(SUMMARY_FN)
],
Templates = [
new($"{PRIMARY_STAGE_FN}.fn"),
new($"{SECONDARY_STAGE_FN}.fn"),
new($"{SUMMARY_FN}.fn")
]
};
utilities.Add(utility);
}
}

View file

@ -1,51 +0,0 @@
namespace BotSharp.Plugin.PythonInterpreter.Hooks;
public class InterpreterAgentHook : AgentHookBase
{
private static string FUNCTION_NAME = "python_interpreter";
public override string SelfId => string.Empty;
public InterpreterAgentHook(IServiceProvider services, AgentSettings settings)
: base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var conv = _services.GetRequiredService<IConversationService>();
var isConvMode = conv.IsConversationMode();
var isEnabled = !agent.Utilities.IsNullOrEmpty() && agent.Utilities.Contains(UtilityName.PythonInterpreter);
if (isConvMode && isEnabled)
{
var (prompt, fn) = GetPromptAndFunction();
if (fn != null)
{
if (!string.IsNullOrWhiteSpace(prompt))
{
agent.Instruction += $"\r\n\r\n{prompt}\r\n\r\n";
}
if (agent.Functions == null)
{
agent.Functions = new List<FunctionDef> { fn };
}
else
{
agent.Functions.Add(fn);
}
}
}
base.OnAgentLoaded(agent);
}
private (string, FunctionDef?) GetPromptAndFunction()
{
var db = _services.GetRequiredService<IBotSharpRepository>();
var agent = db.GetAgent(BuiltInAgentId.UtilityAssistant);
var prompt = agent?.Templates?.FirstOrDefault(x => x.Name.IsEqualTo($"{FUNCTION_NAME}.fn"))?.Content ?? string.Empty;
var loadAttachmentFn = agent?.Functions?.FirstOrDefault(x => x.Name.IsEqualTo(FUNCTION_NAME));
return (prompt, loadAttachmentFn);
}
}

View file

@ -2,8 +2,17 @@ namespace BotSharp.Plugin.PythonInterpreter.Hooks;
public class InterpreterUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private static string FUNCTION_NAME = "python_interpreter";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.PythonInterpreter);
var utility = new AgentUtility()
{
Name = UtilityName.PythonInterpreter,
Functions = [new(FUNCTION_NAME)],
Templates = [new($"{FUNCTION_NAME}.fn")]
};
utilities.Add(utility);
}
}

View file

@ -15,7 +15,6 @@ public class InterpreterPlugin : IBotSharpAppPlugin
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
services.AddScoped<IAgentHook, InterpreterAgentHook>();
services.AddScoped<IAgentUtilityHook, InterpreterUtilityHook>();
}

View file

@ -1,48 +0,0 @@
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Agents.Settings;
namespace BotSharp.Plugin.SqlDriver.Hooks;
public class SqlDriverAgentHook : AgentHookBase, IAgentHook
{
private const string SQL_TABLE_DEFINITION_FN = "sql_table_definition";
private const string VERIFY_DICTIONARY_TERM_FN = "verify_dictionary_term";
private const string SQL_SELECT_FN = "sql_select";
public override string SelfId => BuiltInAgentId.Planner;
public SqlDriverAgentHook(IServiceProvider services, AgentSettings settings)
: base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var dbType = SqlDriverHelper.GetDatabaseType(_services);
agent.TemplateDict["db_type"] = dbType;
var utilityLoads = new List<AgentUtility>
{
new AgentUtility
{
Name = UtilityName.SqlTableDefinition,
Functions = [new(SQL_TABLE_DEFINITION_FN)],
Templates = [new($"{SQL_TABLE_DEFINITION_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.SqlDictionaryLookup,
Functions = [new(VERIFY_DICTIONARY_TERM_FN)],
Templates = [new($"{VERIFY_DICTIONARY_TERM_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.SqlExecutor,
Functions = new List<UtilityFunction> { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) },
Templates = new List<UtilityTemplate> { new($"sql_executor.fn") }
}
};
base.OnAgentLoaded(agent);
}
}

View file

@ -2,10 +2,34 @@ namespace BotSharp.Plugin.SqlDriver.Hooks;
public class SqlUtilityHook : IAgentUtilityHook
{
public void AddUtilities(List<string> utilities)
private const string SQL_TABLE_DEFINITION_FN = "sql_table_definition";
private const string VERIFY_DICTIONARY_TERM_FN = "verify_dictionary_term";
private const string SQL_SELECT_FN = "sql_select";
public void AddUtilities(List<AgentUtility> utilities)
{
utilities.Add(UtilityName.SqlExecutor);
utilities.Add(UtilityName.SqlDictionaryLookup);
utilities.Add(UtilityName.SqlTableDefinition);
var items = new List<AgentUtility>
{
new AgentUtility
{
Name = UtilityName.SqlTableDefinition,
Functions = [new(SQL_TABLE_DEFINITION_FN)],
Templates = [new($"{SQL_TABLE_DEFINITION_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.SqlDictionaryLookup,
Functions = [new(VERIFY_DICTIONARY_TERM_FN)],
Templates = [new($"{VERIFY_DICTIONARY_TERM_FN}.fn")]
},
new AgentUtility
{
Name = UtilityName.SqlExecutor,
Functions = new List<UtilityFunction> { new(SQL_SELECT_FN), new(SQL_TABLE_DEFINITION_FN) },
Templates = new List<UtilityTemplate> { new($"sql_executor.fn") }
}
};
utilities.AddRange(items);
}
}

View file

@ -25,7 +25,6 @@ public class SqlDriverPlugin : IBotSharpPlugin
services.AddScoped<SqlDriverService>();
services.AddScoped<DbKnowledgeService>();
services.AddScoped<IAgentHook, SqlDriverAgentHook>();
services.AddScoped<IPlanningHook, SqlDriverPlanningHook>();
services.AddScoped<IKnowledgeHook, SqlDriverKnowledgeHook>();
services.AddScoped<IConversationHook, SqlDriverConversationHook>();

View file

@ -1,29 +0,0 @@
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Agents.Settings;
using BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Enums;
namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Hooks
{
internal class OutboundPhoneCallHandlerHook : AgentHookBase
{
private static string OUTBOUND_PHONE_CALL_FN = "twilio_outbound_phone_call";
public override string SelfId => string.Empty;
public OutboundPhoneCallHandlerHook(IServiceProvider services, AgentSettings settings) : base(services, settings)
{
}
public override void OnAgentLoaded(Agent agent)
{
var utilityLoad = new AgentUtility
{
Name = UtilityName.OutboundPhoneCall,
Functions = [new(OUTBOUND_PHONE_CALL_FN)],
Templates = [new($"{OUTBOUND_PHONE_CALL_FN}.fn")]
};
base.OnAgentLoaded(agent);
}
}
}

View file

@ -1,12 +1,21 @@
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Enums;
namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Hooks
namespace BotSharp.Plugin.Twilio.OutboundPhoneCallHandler.Hooks;
public class OutboundPhoneCallHandlerUtilityHook : IAgentUtilityHook
{
public class OutboundPhoneCallHandlerUtilityHook : IAgentUtilityHook
private static string OUTBOUND_PHONE_CALL_FN = "twilio_outbound_phone_call";
public void AddUtilities(List<AgentUtility> utilities)
{
public void AddUtilities(List<string> utilities)
var utility = new AgentUtility
{
utilities.Add(UtilityName.OutboundPhoneCall);
}
Name = UtilityName.OutboundPhoneCall,
Functions = [new(OUTBOUND_PHONE_CALL_FN)],
Templates = [new($"{OUTBOUND_PHONE_CALL_FN}.fn")]
};
utilities.Add(utility);
}
}

View file

@ -30,7 +30,6 @@ public class TwilioPlugin : IBotSharpPlugin
services.AddSingleton<TwilioMessageQueue>();
services.AddHostedService<TwilioMessageQueueService>();
services.AddTwilioRequestValidation();
services.AddScoped<IAgentHook, OutboundPhoneCallHandlerHook>();
services.AddScoped<IAgentUtilityHook, OutboundPhoneCallHandlerUtilityHook>();
}
}