2023-08-14 17:00:01 +00:00
|
|
|
namespace BotSharp.Abstraction.Conversations;
|
|
|
|
|
|
|
|
|
|
public interface IConversationHook
|
|
|
|
|
{
|
2023-08-31 11:40:51 +00:00
|
|
|
int Priority { get; }
|
2023-08-14 17:00:01 +00:00
|
|
|
Agent Agent { get; }
|
2023-10-16 20:07:07 +00:00
|
|
|
List<RoleDialogModel> Dialogs { get; }
|
2023-08-14 17:00:01 +00:00
|
|
|
IConversationHook SetAgent(Agent agent);
|
|
|
|
|
|
|
|
|
|
Conversation Conversation { get; }
|
|
|
|
|
IConversationHook SetConversation(Conversation conversation);
|
|
|
|
|
|
2024-11-12 22:51:33 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Get the predifined intent for the conversation.
|
|
|
|
|
/// It will send to the conversation context to help LLM to understand the user's intent.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task<string> GetConversationIntent() => Task.FromResult(string.Empty);
|
|
|
|
|
|
2023-11-27 21:00:26 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Triggered when user connects with agent first time.
|
|
|
|
|
/// This hook is the good timing to show welcome infomation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="conversation"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task OnUserAgentConnectedInitially(Conversation conversation);
|
|
|
|
|
|
2023-08-14 17:00:01 +00:00
|
|
|
/// <summary>
|
2023-10-16 20:07:07 +00:00
|
|
|
/// Triggered once for every new conversation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="conversation"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task OnConversationInitialized(Conversation conversation);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Triggered when dialog history is loaded.
|
2023-08-14 17:00:01 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dialogs"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task OnDialogsLoaded(List<RoleDialogModel> dialogs);
|
|
|
|
|
|
2024-02-06 20:42:35 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Triggered when every dialog record is loaded
|
|
|
|
|
/// It can be used to populate extra data point before presenting to user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dialog"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task OnDialogRecordLoaded(RoleDialogModel dialog);
|
|
|
|
|
|
2023-08-14 17:00:01 +00:00
|
|
|
Task OnStateLoaded(ConversationState state);
|
2024-03-28 18:16:16 +00:00
|
|
|
Task OnStateChanged(StateChangeModel stateChange);
|
2023-08-14 17:00:01 +00:00
|
|
|
|
2023-10-16 20:07:07 +00:00
|
|
|
Task OnMessageReceived(RoleDialogModel message);
|
2024-03-16 14:43:00 +00:00
|
|
|
Task OnPostbackMessageReceived(RoleDialogModel message, PostbackMessageModel replyMsg);
|
2023-10-16 20:07:07 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Triggered before LLM calls function.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <returns></returns>
|
2023-08-14 17:00:01 +00:00
|
|
|
Task OnFunctionExecuting(RoleDialogModel message);
|
2023-10-16 20:07:07 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Triggered when the function calling completed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <returns></returns>
|
2023-08-14 17:00:01 +00:00
|
|
|
Task OnFunctionExecuted(RoleDialogModel message);
|
2023-10-16 00:08:24 +00:00
|
|
|
|
2023-10-16 20:07:07 +00:00
|
|
|
Task OnResponseGenerated(RoleDialogModel message);
|
|
|
|
|
|
2024-04-08 03:15:51 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// LLM detected user requested a new task different from previous topic.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task OnNewTaskDetected(RoleDialogModel message, string reason);
|
|
|
|
|
|
2023-10-16 20:07:07 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// LLM detected the current task is completed.
|
|
|
|
|
/// It's useful for the situation of multiple tasks in the same conversation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="conversation"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-03-22 19:06:20 +00:00
|
|
|
Task OnTaskCompleted(RoleDialogModel message);
|
2023-10-16 20:07:07 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// LLM detected the whole conversation is going to be end.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="conversation"></param>
|
|
|
|
|
/// <returns></returns>
|
2023-10-23 00:31:49 +00:00
|
|
|
Task OnConversationEnding(RoleDialogModel message);
|
2023-10-16 20:07:07 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// LLM can't handle user's request or user requests human being to involve.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="conversation"></param>
|
|
|
|
|
/// <returns></returns>
|
2023-10-23 00:31:49 +00:00
|
|
|
Task OnHumanInterventionNeeded(RoleDialogModel message);
|
2024-03-11 20:32:13 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete message in a conversation
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="conversationId"></param>
|
|
|
|
|
/// <param name="messageId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task OnMessageDeleted(string conversationId, string messageId);
|
2024-03-24 13:56:21 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Brakpoint updated
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="conversationId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task OnBreakpointUpdated(string conversationId, bool resetStates);
|
2024-10-07 21:35:39 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generate a notification
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
Task OnNotificationGenerated(RoleDialogModel message);
|
2023-08-14 17:00:01 +00:00
|
|
|
}
|