Skip to content

Commit 5023ee9

Browse files
Merge pull request #1 from jackjiang-sms/feature/AII-400
AII-400
2 parents 0f9a01c + 7f6845b commit 5023ee9

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ public virtual void OnAgentLoaded(Agent agent)
5656
public virtual void OnAgentUtilityLoaded(Agent agent)
5757
{
5858
}
59+
60+
public virtual void OnAgentLoadFilter(Agent agent)
61+
{
62+
63+
}
5964
}

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ public interface IAgentHook
3333
/// <param name="agent"></param>
3434
/// <returns></returns>
3535
void OnAgentLoaded(Agent agent);
36+
37+
void OnAgentLoadFilter(Agent agent);
3638
}

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@ namespace BotSharp.Core.Agents.Services;
55

66
public partial class AgentService
77
{
8-
public static ConcurrentDictionary<string, Dictionary<string,string>> AgentParameterTypes = new();
8+
public static ConcurrentDictionary<string, Dictionary<string, string>> AgentParameterTypes = new();
99

10-
[MemoryCache(10 * 60, perInstanceCache: true)]
1110
public async Task<Agent> LoadAgent(string id)
1211
{
1312
if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString())
1413
{
1514
return null;
1615
}
1716

17+
Agent agent = await GetLoadAgent(id);
18+
OnAgentLoadFilter(agent);
19+
return agent;
20+
}
21+
22+
private void OnAgentLoadFilter(Agent? agent)
23+
{
24+
if (agent != null && agent.Type == AgentType.Routing)
25+
{
26+
var hooks = _services.GetServices<IAgentHook>();
27+
foreach (var hook in hooks)
28+
{
29+
hook.OnAgentLoadFilter(agent);
30+
}
31+
}
32+
}
33+
34+
[MemoryCache(10 * 60, perInstanceCache: true)]
35+
private async Task<Agent> GetLoadAgent(string id)
36+
{
1837
var hooks = _services.GetServices<IAgentHook>();
1938

2039
// Before agent is loaded.
@@ -106,14 +125,14 @@ private void AddOrUpdateParameters(Agent agent)
106125
{
107126
var agentId = agent.Id ?? agent.Name;
108127
if (AgentParameterTypes.ContainsKey(agentId)) return;
109-
128+
110129
AddOrUpdateRoutesParameters(agentId, agent.RoutingRules);
111130
AddOrUpdateFunctionsParameters(agentId, agent.Functions);
112131
}
113132

114133
private void AddOrUpdateRoutesParameters(string agentId, List<RoutingRule> routingRules)
115134
{
116-
if(!AgentParameterTypes.TryGetValue(agentId, out var parameterTypes))
135+
if (!AgentParameterTypes.TryGetValue(agentId, out var parameterTypes))
117136
{
118137
parameterTypes = new();
119138
}

0 commit comments

Comments
 (0)