Merge pull request #1048 from hchen2020/master

Avoid duplicated utility templates.
This commit is contained in:
Haiping 2025-05-07 14:33:54 -05:00 committed by GitHub
commit d7e42b06eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View file

@ -35,12 +35,15 @@ public class BasicAgentHook : AgentHookBase
foreach (var prompt in templates)
{
agent.SecondaryInstructions.Add(prompt);
if (!agent.SecondaryInstructions.Any(x => x.Contains(prompt.Content, StringComparison.OrdinalIgnoreCase)))
{
agent.SecondaryInstructions.Add(prompt.Content);
}
}
}
private (IEnumerable<FunctionDef>, IEnumerable<string>) GetUtilityContent(Agent agent)
private (IEnumerable<FunctionDef>, IEnumerable<AgentTemplate>) GetUtilityContent(Agent agent)
{
var db = _services.GetRequiredService<IBotSharpRepository>();
var (functionNames, templateNames) = GetUniqueContent(agent.Utilities);
@ -60,7 +63,7 @@ public class BasicAgentHook : AgentHookBase
var ua = db.GetAgent(BuiltInAgentId.UtilityAssistant);
var functions = ua?.Functions?.Where(x => functionNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.ToList() ?? [];
var templates = ua?.Templates?.Where(x => templateNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.Select(x => x.Content)?.ToList() ?? [];
var templates = ua?.Templates?.Where(x => templateNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))?.ToList() ?? [];
return (functions, templates);
}

View file

@ -167,6 +167,12 @@ public class TwilioInboundController : TwilioController
new("twilio_call_sid", request.CallSid),
};
if (request.Direction == "inbound")
{
states.Add(new MessageState("calling_phone_from", request.From));
states.Add(new MessageState("calling_phone_to", request.To));
}
var requestStates = ParseStates(request.States);
foreach (var s in requestStates)
{