Add SelfId in IInstructHook.
This commit is contained in:
parent
2bc2367536
commit
4c54a62557
|
|
@ -4,6 +4,7 @@ namespace BotSharp.Abstraction.Instructs;
|
|||
|
||||
public interface IInstructHook
|
||||
{
|
||||
string SelfId { get; }
|
||||
Task BeforeCompletion(RoleDialogModel message);
|
||||
Task AfterCompletion(InstructResult result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Agent> LoadAgent(string id)
|
||||
{
|
||||
var hooks = _services.GetServices<IAgentHook>();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ public partial class InstructService : IInstructService
|
|||
var hooks = _services.GetServices<IInstructHook>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue