|
1 | 1 | using BotSharp.Abstraction.Agents.Settings;
|
2 |
| -using BotSharp.Abstraction.Conversations; |
3 | 2 | using BotSharp.Abstraction.Functions.Models;
|
4 |
| -using BotSharp.Abstraction.Repositories; |
5 |
| -using BotSharp.Abstraction.Routing; |
6 |
| -using Microsoft.Extensions.DependencyInjection; |
7 |
| -using System.Data; |
8 | 3 |
|
9 | 4 | namespace BotSharp.Abstraction.Agents;
|
10 | 5 |
|
@@ -60,73 +55,5 @@ public virtual void OnAgentLoaded(Agent agent)
|
60 | 55 |
|
61 | 56 | public virtual void OnAgentUtilityLoaded(Agent agent)
|
62 | 57 | {
|
63 |
| - if (agent.Type == AgentType.Routing) return; |
64 |
| - |
65 |
| - var conv = _services.GetRequiredService<IConversationService>(); |
66 |
| - var isConvMode = conv.IsConversationMode(); |
67 |
| - if (!isConvMode) return; |
68 |
| - |
69 |
| - agent.Functions ??= []; |
70 |
| - agent.Utilities ??= []; |
71 |
| - |
72 |
| - var (functions, templates) = GetUtilityContent(agent); |
73 |
| - |
74 |
| - foreach (var fn in functions) |
75 |
| - { |
76 |
| - if (!agent.Functions.Any(x => x.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase))) |
77 |
| - { |
78 |
| - agent.Functions.Add(fn); |
79 |
| - } |
80 |
| - } |
81 |
| - |
82 |
| - foreach (var prompt in templates) |
83 |
| - { |
84 |
| - agent.Instruction += $"\r\n\r\n{prompt}\r\n\r\n"; |
85 |
| - } |
86 |
| - } |
87 |
| - |
88 |
| - private (IEnumerable<FunctionDef>, IEnumerable<string>) GetUtilityContent(Agent agent) |
89 |
| - { |
90 |
| - var db = _services.GetRequiredService<IBotSharpRepository>(); |
91 |
| - var (functionNames, templateNames) = GetUniqueContent(agent.Utilities); |
92 |
| - |
93 |
| - if (agent.MergeUtility) |
94 |
| - { |
95 |
| - var routing = _services.GetRequiredService<IRoutingContext>(); |
96 |
| - var entryAgentId = routing.EntryAgentId; |
97 |
| - if (!string.IsNullOrEmpty(entryAgentId)) |
98 |
| - { |
99 |
| - var entryAgent = db.GetAgent(entryAgentId); |
100 |
| - var (fns, tps) = GetUniqueContent(entryAgent?.Utilities); |
101 |
| - functionNames = functionNames.Concat(fns).Distinct().ToList(); |
102 |
| - templateNames = templateNames.Concat(tps).Distinct().ToList(); |
103 |
| - } |
104 |
| - } |
105 |
| - |
106 |
| - var ua = db.GetAgent(BuiltInAgentId.UtilityAssistant); |
107 |
| - var functions = ua?.Functions?.Where(x => functionNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.ToList() ?? []; |
108 |
| - var templates = ua?.Templates?.Where(x => templateNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.Select(x => x.Content)?.ToList() ?? []; |
109 |
| - return (functions, templates); |
110 |
| - } |
111 |
| - |
112 |
| - private (IEnumerable<string>, IEnumerable<string>) GetUniqueContent(IEnumerable<AgentUtility>? utilities) |
113 |
| - { |
114 |
| - if (utilities.IsNullOrEmpty()) |
115 |
| - { |
116 |
| - return ([], []); |
117 |
| - } |
118 |
| - |
119 |
| - var prefix = "util-"; |
120 |
| - utilities = utilities?.Where(x => !string.IsNullOrEmpty(x.Name) && !x.Disabled)?.ToList() ?? []; |
121 |
| - var functionNames = utilities.SelectMany(x => x.Functions) |
122 |
| - .Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.StartsWith(prefix)) |
123 |
| - .Select(x => x.Name) |
124 |
| - .Distinct().ToList(); |
125 |
| - var templateNames = utilities.SelectMany(x => x.Templates) |
126 |
| - .Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.StartsWith(prefix)) |
127 |
| - .Select(x => x.Name) |
128 |
| - .Distinct().ToList(); |
129 |
| - |
130 |
| - return (functionNames, templateNames); |
131 | 58 | }
|
132 | 59 | }
|
0 commit comments