2023-08-14 17:00:01 +00:00
|
|
|
using BotSharp.Abstraction.Agents.Models;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.Core.Agents.Services;
|
|
|
|
|
|
|
|
|
|
public partial class AgentService
|
|
|
|
|
{
|
|
|
|
|
public async Task<Agent> LoadAgent(string id)
|
|
|
|
|
{
|
|
|
|
|
var hooks = _services.GetServices<IAgentHook>();
|
|
|
|
|
|
|
|
|
|
// Before agent is loaded.
|
|
|
|
|
foreach (var hook in hooks)
|
|
|
|
|
{
|
|
|
|
|
hook.OnAgentLoading(ref id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var agent = await GetAgent(id);
|
|
|
|
|
|
|
|
|
|
// After agent is loaded
|
|
|
|
|
foreach (var hook in hooks)
|
|
|
|
|
{
|
|
|
|
|
hook.SetAget(agent);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(agent.Instruction))
|
|
|
|
|
{
|
|
|
|
|
var instruction = agent.Instruction;
|
|
|
|
|
hook.OnInstructionLoaded(ref instruction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(agent.Functions))
|
|
|
|
|
{
|
|
|
|
|
var functions = agent.Functions;
|
|
|
|
|
hook.OnFunctionsLoaded(ref functions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(agent.Samples))
|
|
|
|
|
{
|
|
|
|
|
var samples = agent.Samples;
|
|
|
|
|
hook.OnSamplesLoaded(ref samples);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 04:04:23 +00:00
|
|
|
hook.OnAgentLoaded(agent);
|
2023-08-14 17:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 04:04:23 +00:00
|
|
|
_logger.LogInformation($"Loaded agent {agent}.");
|
|
|
|
|
|
2023-08-14 17:00:01 +00:00
|
|
|
return agent;
|
|
|
|
|
}
|
|
|
|
|
}
|