Skip to content

Commit d7e42b0

Browse files
authored
Merge pull request #1048 from hchen2020/master
Avoid duplicated utility templates.
2 parents 8a6eb7d + 36a387e commit d7e42b0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ public override void OnAgentUtilityLoaded(Agent agent)
3535

3636
foreach (var prompt in templates)
3737
{
38-
agent.SecondaryInstructions.Add(prompt);
38+
if (!agent.SecondaryInstructions.Any(x => x.Contains(prompt.Content, StringComparison.OrdinalIgnoreCase)))
39+
{
40+
agent.SecondaryInstructions.Add(prompt.Content);
41+
}
3942
}
4043
}
4144

4245

43-
private (IEnumerable<FunctionDef>, IEnumerable<string>) GetUtilityContent(Agent agent)
46+
private (IEnumerable<FunctionDef>, IEnumerable<AgentTemplate>) GetUtilityContent(Agent agent)
4447
{
4548
var db = _services.GetRequiredService<IBotSharpRepository>();
4649
var (functionNames, templateNames) = GetUniqueContent(agent.Utilities);
@@ -60,7 +63,7 @@ public override void OnAgentUtilityLoaded(Agent agent)
6063

6164
var ua = db.GetAgent(BuiltInAgentId.UtilityAssistant);
6265
var functions = ua?.Functions?.Where(x => functionNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.ToList() ?? [];
63-
var templates = ua?.Templates?.Where(x => templateNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.Select(x => x.Content)?.ToList() ?? [];
66+
var templates = ua?.Templates?.Where(x => templateNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.ToList() ?? [];
6467
return (functions, templates);
6568
}
6669

src/Plugins/BotSharp.Plugin.Twilio/Controllers/TwilioInboundController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ protected Dictionary<string, string> ParseStates(List<string> states)
167167
new("twilio_call_sid", request.CallSid),
168168
};
169169

170+
if (request.Direction == "inbound")
171+
{
172+
states.Add(new MessageState("calling_phone_from", request.From));
173+
states.Add(new MessageState("calling_phone_to", request.To));
174+
}
175+
170176
var requestStates = ParseStates(request.States);
171177
foreach (var s in requestStates)
172178
{

0 commit comments

Comments
 (0)