@@ -6,7 +6,7 @@ namespace BotSharp.Core.Agents.Services;
66
77public partial class AgentService
88{
9- public static ConcurrentDictionary < string , Dictionary < string , string > > AgentParameterTypes = new ( ) ;
9+ public static ConcurrentDictionary < string , ConcurrentDictionary < string , string > > AgentParameterTypes = new ( ) ;
1010
1111 // [SharpCache(10, perInstanceCache: true)]
1212 public async Task < Agent > LoadAgent ( string id , bool loadUtility = true )
@@ -101,26 +101,18 @@ private void AddOrUpdateParameters(Agent agent)
101101
102102 private void AddOrUpdateRoutesParameters ( string agentId , List < RoutingRule > routingRules )
103103 {
104- if ( ! AgentParameterTypes . TryGetValue ( agentId , out var parameterTypes ) )
105- {
106- parameterTypes = new ( ) ;
107- }
104+ var parameterTypes = AgentParameterTypes . GetOrAdd ( agentId , _ => new ( ) ) ;
108105
109106 foreach ( var rule in routingRules . Where ( x => x . Required ) )
110107 {
111108 if ( string . IsNullOrEmpty ( rule . FieldType ) ) continue ;
112- parameterTypes . TryAdd ( rule . Field , rule . FieldType ) ;
109+ parameterTypes [ rule . Field ] = rule . FieldType ;
113110 }
114-
115- AgentParameterTypes . TryAdd ( agentId , parameterTypes ) ;
116111 }
117112
118113 private void AddOrUpdateFunctionsParameters ( string agentId , List < FunctionDef > functions )
119114 {
120- if ( ! AgentParameterTypes . TryGetValue ( agentId , out var parameterTypes ) )
121- {
122- parameterTypes = new ( ) ;
123- }
115+ var parameterTypes = AgentParameterTypes . GetOrAdd ( agentId , _ => new ( ) ) ;
124116
125117 var parameters = functions . Select ( p => p . Parameters ) ;
126118 foreach ( var param in parameters )
@@ -131,11 +123,9 @@ private void AddOrUpdateFunctionsParameters(string agentId, List<FunctionDef> fu
131123 var node = prop . Value ;
132124 if ( node . TryGetProperty ( "type" , out var type ) )
133125 {
134- parameterTypes . TryAdd ( name , type . GetString ( ) ) ;
126+ parameterTypes [ name ] = type . GetString ( ) ;
135127 }
136128 }
137129 }
138-
139- AgentParameterTypes . TryAdd ( agentId , parameterTypes ) ;
140130 }
141131}
0 commit comments