commit
5023ee9245
|
|
@ -56,4 +56,9 @@ public abstract class AgentHookBase : IAgentHook
|
|||
public virtual void OnAgentUtilityLoaded(Agent agent)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnAgentLoadFilter(Agent agent)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,6 @@ public interface IAgentHook
|
|||
/// <param name="agent"></param>
|
||||
/// <returns></returns>
|
||||
void OnAgentLoaded(Agent agent);
|
||||
|
||||
void OnAgentLoadFilter(Agent agent);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ namespace BotSharp.Core.Agents.Services;
|
|||
|
||||
public partial class AgentService
|
||||
{
|
||||
public static ConcurrentDictionary<string, Dictionary<string,string>> AgentParameterTypes = new();
|
||||
public static ConcurrentDictionary<string, Dictionary<string, string>> AgentParameterTypes = new();
|
||||
|
||||
[MemoryCache(10 * 60, perInstanceCache: true)]
|
||||
public async Task<Agent> LoadAgent(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString())
|
||||
|
|
@ -15,6 +14,26 @@ public partial class AgentService
|
|||
return null;
|
||||
}
|
||||
|
||||
Agent agent = await GetLoadAgent(id);
|
||||
OnAgentLoadFilter(agent);
|
||||
return agent;
|
||||
}
|
||||
|
||||
private void OnAgentLoadFilter(Agent? agent)
|
||||
{
|
||||
if (agent != null && agent.Type == AgentType.Routing)
|
||||
{
|
||||
var hooks = _services.GetServices<IAgentHook>();
|
||||
foreach (var hook in hooks)
|
||||
{
|
||||
hook.OnAgentLoadFilter(agent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MemoryCache(10 * 60, perInstanceCache: true)]
|
||||
private async Task<Agent> GetLoadAgent(string id)
|
||||
{
|
||||
var hooks = _services.GetServices<IAgentHook>();
|
||||
|
||||
// Before agent is loaded.
|
||||
|
|
@ -106,14 +125,14 @@ public partial class AgentService
|
|||
{
|
||||
var agentId = agent.Id ?? agent.Name;
|
||||
if (AgentParameterTypes.ContainsKey(agentId)) return;
|
||||
|
||||
|
||||
AddOrUpdateRoutesParameters(agentId, agent.RoutingRules);
|
||||
AddOrUpdateFunctionsParameters(agentId, agent.Functions);
|
||||
}
|
||||
|
||||
private void AddOrUpdateRoutesParameters(string agentId, List<RoutingRule> routingRules)
|
||||
{
|
||||
if(!AgentParameterTypes.TryGetValue(agentId, out var parameterTypes))
|
||||
if (!AgentParameterTypes.TryGetValue(agentId, out var parameterTypes))
|
||||
{
|
||||
parameterTypes = new();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue