From 4668f457d1c83adda7c345abfdb84c06a6c05199 Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Fri, 21 Aug 2026 09:45:27 +0800 Subject: [PATCH] optimize AgentHookBase,InstructHookBase --- .../BotSharp.Abstraction/Agents/AgentHookBase.cs | 3 +++ .../BotSharp.Abstraction/Conversations/ConversationHookBase.cs | 3 +++ .../BotSharp.Abstraction/Conversations/IConversationHook.cs | 2 +- .../BotSharp.Abstraction/Instructs/InstructHookBase.cs | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs index d3a87f65b..5ee9dfd46 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs @@ -7,6 +7,9 @@ public abstract class AgentHookBase : IAgentHook { public abstract string SelfId { get; } + public virtual bool IsMatch(string agentId) + => string.IsNullOrEmpty(SelfId) || SelfId == agentId; + protected Agent _agent; public Agent Agent => _agent; diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs index f25a411eb..e0ca87753 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs @@ -29,6 +29,9 @@ public IConversationHook SetConversation(Conversation conversation) return this; } + public virtual Task GetConversationIntent() + => Task.FromResult(string.Empty); + public virtual Task OnStateLoaded(ConversationState state) => Task.CompletedTask; diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs index c1494f876..6ad36d0c4 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs @@ -18,7 +18,7 @@ public interface IConversationHook : IHookBase /// It will send to the conversation context to help LLM to understand the user's intent. /// /// - Task GetConversationIntent() => Task.FromResult(string.Empty); + Task GetConversationIntent(); /// /// Triggered when listing conversations. diff --git a/src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs index 8e1d50457..c56f0c247 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Instructs/InstructHookBase.cs @@ -8,6 +8,9 @@ public abstract class InstructHookBase : IInstructHook { public abstract string SelfId { get; } + public virtual bool IsMatch(string agentId) + => string.IsNullOrEmpty(SelfId) || SelfId == agentId; + public virtual async Task BeforeCompletion(Agent agent, RoleDialogModel message) { await Task.CompletedTask;