diff --git a/src/Infrastructure/BotSharp.Abstraction/Instructs/IInstructHook.cs b/src/Infrastructure/BotSharp.Abstraction/Instructs/IInstructHook.cs index 8d5dea5e..9ea5f5de 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Instructs/IInstructHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Instructs/IInstructHook.cs @@ -4,6 +4,7 @@ namespace BotSharp.Abstraction.Instructs; public interface IInstructHook { + string SelfId { get; } Task BeforeCompletion(RoleDialogModel message); Task AfterCompletion(InstructResult result); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs index fc1f1dd5..9a973b6e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs @@ -4,6 +4,7 @@ namespace BotSharp.Abstraction.Instructs; public class InstructHookBase : IInstructHook { + public virtual string SelfId => throw new NotImplementedException("Please set SelfId as agent id!"); public virtual async Task AfterCompletion(InstructResult result) { return; diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index 91c82886..301da3b7 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -5,9 +5,7 @@ namespace BotSharp.Core.Agents.Services; public partial class AgentService { -#if !DEBUG - [MemoryCache(10 * 60)] -#endif + [MemoryCache(10 * 60, perInstanceCache: true)] public async Task LoadAgent(string id) { var hooks = _services.GetServices(); diff --git a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs b/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs index ec64f6af..3718e1fe 100644 --- a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs +++ b/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs @@ -21,6 +21,11 @@ public partial class InstructService : IInstructService var hooks = _services.GetServices(); foreach (var hook in hooks) { + if (hook.SelfId != agent.Id) + { + continue; + } + await hook.BeforeCompletion(message); // Interrupted by hook @@ -42,6 +47,11 @@ public partial class InstructService : IInstructService foreach (var hook in hooks) { + if (hook.SelfId != agent.Id) + { + continue; + } + await hook.AfterCompletion(response); }