From 9f79dcf4a8f1cec481d5201ba7688e62c5bbccd8 Mon Sep 17 00:00:00 2001 From: Haiping Chen <101423@smsassist.com> Date: Thu, 28 Mar 2024 14:09:13 -0500 Subject: [PATCH 1/2] Save function result to Storage --- .../BotSharp.Core/Routing/RoutingService.InvokeFunction.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs index 690308eb..931eb2b0 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs @@ -68,6 +68,10 @@ public partial class RoutingService message.FunctionName = originalFunctionName; } + // Save to Storage as well + var storage = _services.GetRequiredService(); + storage.Append(Context.ConversationId, message); + return result; } } From 16e3a70ce7b61f1297c9c643f08f759396086571 Mon Sep 17 00:00:00 2001 From: Haiping Chen <101423@smsassist.com> Date: Thu, 28 Mar 2024 14:09:53 -0500 Subject: [PATCH 2/2] human_intervention_needed --- .../Routing/Handlers/HumanInterventionNeededHandler.cs | 2 +- .../BotSharp.Core/Routing/RoutingService.InvokeAgent.cs | 6 ++++-- .../templates/planner_prompt.naive.liquid | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs index 39a50a30..2ef07fb9 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs @@ -12,7 +12,7 @@ public class HumanInterventionNeededHandler : RoutingHandlerBase, IRoutingHandle { new ParameterPropertyDef("reason", "why need customer service"), new ParameterPropertyDef("summary", "the whole conversation summary with important information"), - new ParameterPropertyDef("response", "tell the user that you are being transferred to customer service") + new ParameterPropertyDef("response", "confirm with user that whether to connect with customer service") }; public HumanInterventionNeededHandler(IServiceProvider services, ILogger logger, RoutingSettings settings) diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index 8518d769..c99c8a91 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -74,9 +74,11 @@ public partial class RoutingService else { // Save to memory dialogs - dialogs.Add(RoleDialogModel.From(message, + var msg = RoleDialogModel.From(message, role: AgentRole.Function, - content: message.Content)); + content: message.Content); + + dialogs.Add(msg); // Send to Next LLM var agentId = routing.Context.GetCurrentAgentId(); diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.naive.liquid b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.naive.liquid index 6502c493..3f977398 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.naive.liquid +++ b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.naive.liquid @@ -3,4 +3,5 @@ Route to the last handling agent in priority. {% if expected_next_action_agent != empty -%} Expected next action agent is {{ expected_next_action_agent }}. {%- endif %} -If user wants to speak to customer service, use function human_intervention_needed. \ No newline at end of file +If user wants to speak to customer service, use function human_intervention_needed. +If user wants to or is processing with a specific task that can be handled by agents, respond with appropriate agents. \ No newline at end of file