diff --git a/src/Infrastructure/BotSharp.Core/Agents/AgentConversationHook.cs b/src/Infrastructure/BotSharp.Core/Agents/AgentConversationHook.cs deleted file mode 100644 index 0a06e811..00000000 --- a/src/Infrastructure/BotSharp.Core/Agents/AgentConversationHook.cs +++ /dev/null @@ -1,26 +0,0 @@ - -namespace BotSharp.Core.Agents; - -public class AgentConversationHook : ConversationHookBase -{ - private readonly IServiceProvider _services; - - public AgentConversationHook(IServiceProvider services) - { - _services = services; - } - - public override async Task OnStateChanged(string name, string preValue, string currentValue) - { - // Apply new states to agent TemplateDict - var routing = _services.GetRequiredService(); - var agentId = routing.GetCurrentAgentId(); - if (string.IsNullOrEmpty(agentId)) - { - return; - } - var agentService = _services.GetRequiredService(); - var agent = agentService.LoadAgent(agentId).Result; - agent.TemplateDict[name] = currentValue; - } -} diff --git a/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs b/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs index 92323fb4..7df5fa02 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs @@ -21,7 +21,6 @@ public class AgentPlugin : IBotSharpPlugin { services.AddScoped(); services.AddScoped(); - services.AddScoped(); services.AddScoped(provider => { diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index cb91a5a7..5d618611 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -95,12 +95,24 @@ public partial class AgentService // render liquid template var render = _services.GetRequiredService(); var template = agent.Templates.First(x => x.Name == templateName).Content; + // update states + var conv = _services.GetRequiredService(); + foreach (var t in conv.States.GetStates()) + { + agent.TemplateDict[t.Key] = t.Value; + } return render.Render(template, agent.TemplateDict); } public string RenderedInstruction(Agent agent) { var render = _services.GetRequiredService(); + // update states + var conv = _services.GetRequiredService(); + foreach (var t in conv.States.GetStates()) + { + agent.TemplateDict[t.Key] = t.Value; + } return render.Render(agent.Instruction, agent.TemplateDict); } diff --git a/src/Infrastructure/BotSharp.Core/Routing/Planning/HFPlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/HFPlanner.cs index 4e508662..dd156054 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Planning/HFPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/HFPlanner.cs @@ -1,8 +1,3 @@ -using BotSharp.Abstraction.Agents.Models; -using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Repositories; -using BotSharp.Abstraction.Repositories.Filters; -using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Planning; using BotSharp.Abstraction.Templating; @@ -93,6 +88,12 @@ public class HFPlanner : IPlaner { var template = router.Templates.First(x => x.Name == "planner_prompt.hf").Content; var render = _services.GetRequiredService(); + // update states + var conv = _services.GetRequiredService(); + foreach (var t in conv.States.GetStates()) + { + router.TemplateDict[t.Key] = t.Value; + } var prompt = render.Render(template, router.TemplateDict); return prompt.Trim(); } diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 0328c409..d7f62bac 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -54,6 +54,7 @@ public class UserService : IUserService db.CreateUser(record); + _logger.LogWarning($"Created new user account: {record.Id} {record.UserName}"); Utilities.ClearCache(); return record;