From 5413f4f71b309529b656891b48a5c9158a77a3f9 Mon Sep 17 00:00:00 2001 From: hchen2020 <101423@smsassist.com> Date: Mon, 28 Aug 2023 10:58:35 -0500 Subject: [PATCH] response_to_user after reasoning. --- .../Routing/Models/RetrievalArgs.cs | 3 +++ .../ConversationService.SendMessage.cs | 9 ++++++++ .../BotSharp.Core/Routing/Simulator.cs | 21 +++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RetrievalArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RetrievalArgs.cs index 835cda46..e0b3f9a1 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RetrievalArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RetrievalArgs.cs @@ -8,6 +8,9 @@ public class RetrievalArgs : RoutingArgs [JsonPropertyName("question")] public string Question { get; set; } + [JsonPropertyName("answer")] + public string Answer { get; set; } + [JsonPropertyName("reason")] public string Reason { get; set; } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index c05406a5..24376c21 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -83,6 +83,15 @@ public partial class ConversationService }, onMessageReceived); return true; } + else if (reasonedContext.FunctionName == "response_to_user") + { + await HandleAssistantMessage(new RoleDialogModel(AgentRole.Assistant, reasonedContext.Content) + { + CurrentAgentId = agent.Id, + Channel = lastDialog.Channel + }, onMessageReceived); + return true; + } else if (reasonedContext.FunctionName == "continue_execute_task") { if (reasonedContext.CurrentAgentId != agent.Id) diff --git a/src/Infrastructure/BotSharp.Core/Routing/Simulator.cs b/src/Infrastructure/BotSharp.Core/Routing/Simulator.cs index d5c3d935..4b8123d5 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Simulator.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Simulator.cs @@ -34,7 +34,7 @@ public class Simulator var response = await SendMessageToReasoner(agent); var args = JsonSerializer.Deserialize(response.Content); response.FunctionName = args.Function; - response.Content = args.Parameters.Reason; + if (args.Function == "continue_execute_task") { response.FunctionArgs = JsonSerializer.Serialize(args.Parameters.Arguments); @@ -43,6 +43,16 @@ public class Simulator var record = router.GetRecordByName(args.Parameters.AgentName); response.CurrentAgentId = record.AgentId; } + else if (args.Function == "interrupt_task_execution") + { + response.Content = args.Parameters.Reason; + response.ExecutionResult = args.Parameters.Reason; + } + else if (args.Function == "response_to_user") + { + response.Content = args.Parameters.Answer; + response.ExecutionResult = args.Parameters.Answer; + } return response; } @@ -63,7 +73,14 @@ public class Simulator var args = JsonSerializer.Deserialize(response.Content); - SaveStateByArgs(args.Parameters.Arguments); + if (args.Function == "retrieve_data_from_agent") + { + SaveStateByArgs(args.Parameters.Arguments); + } + else if (args.Function == "response_to_user") + { + return response; + } // Retrieve information from specific agent var router = _services.GetRequiredService();