From 73331bbb1d55e6885eb079b17d4ce5d00bb1c2a4 Mon Sep 17 00:00:00 2001 From: hchen Date: Fri, 3 Nov 2023 09:16:16 -0500 Subject: [PATCH] Add states to chat message result --- .../Instructs/Models/InstructResult.cs | 2 -- .../BotSharp.Core/Planning/HFPlanner.cs | 2 +- .../RetrieveDataFromAgentRoutingHandler.cs | 6 +++--- .../Controllers/ConversationController.cs | 2 ++ .../Conversations/MessageResponseModel.cs | 16 ++++++++++------ .../templates/next_step_prompt.hf_planner.liquid | 1 + 6 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/next_step_prompt.hf_planner.liquid diff --git a/src/Infrastructure/BotSharp.Abstraction/Instructs/Models/InstructResult.cs b/src/Infrastructure/BotSharp.Abstraction/Instructs/Models/InstructResult.cs index 67bd2039..9c1c4a99 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Instructs/Models/InstructResult.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Instructs/Models/InstructResult.cs @@ -1,5 +1,3 @@ -using BotSharp.Abstraction.Models; - namespace BotSharp.Abstraction.Instructs.Models; public class InstructResult : ITrackableMessage diff --git a/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs b/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs index 73a2a242..9bb6f9fd 100644 --- a/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Planning/HFPlanner.cs @@ -86,7 +86,7 @@ public class HFPlanner : IPlaner private string GetNextStepPrompt(Agent router) { - var template = router.Templates.First(x => x.Name == "next_step_prompt").Content; + var template = router.Templates.First(x => x.Name == "next_step_prompt.hf_planner").Content; var render = _services.GetRequiredService(); var prompt = render.Render(template, router.TemplateDict); return prompt.Trim(); diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs index 4af4f15f..3e397089 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RetrieveDataFromAgentRoutingHandler.cs @@ -17,10 +17,10 @@ public class RetrieveDataFromAgentRoutingHandler : RoutingHandlerBase, IRoutingH public List Parameters => new List { - new ParameterPropertyDef("reason", "why retrieve data"), - new ParameterPropertyDef("question", "the question you will ask the agent to get the necessary data"), + new ParameterPropertyDef("reason", "why choose this function"), + new ParameterPropertyDef("question", "the question you will ask the next action agent to get the necessary information"), new ParameterPropertyDef("next_action_agent", "agent that can handle the question"), - + new ParameterPropertyDef("user_goal_agent", "agent that can achieve user original goal"), new ParameterPropertyDef("args", "required parameters extracted from question and hand over to the next agent") { Type = "object" diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 7b3733a4..4635c8cd 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -72,6 +72,8 @@ public class ConversationController : ControllerBase, IApiAdapter }); + var state = _services.GetRequiredService(); + response.States = state.GetStates(); response.MessageId = inputMsg.MessageId; return response; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/MessageResponseModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/MessageResponseModel.cs index 4b0c335d..120e81a3 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/MessageResponseModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/MessageResponseModel.cs @@ -1,18 +1,22 @@ using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Models; +using BotSharp.Abstraction.Instructs.Models; using System.Text.Json.Serialization; namespace BotSharp.OpenAPI.ViewModels.Conversations; -public class MessageResponseModel : ITrackableMessage +public class MessageResponseModel : InstructResult { - public string MessageId { get; set; } - public string Text { get; set; } public string Function { get; set; } - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public object Data { get; set; } + + /// + /// Planner instruction + /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public FunctionCallFromLlm Instruction { get; set; } + + /// + /// Rich message for UI rendering + /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? RichContent { get; set; } } diff --git a/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/next_step_prompt.hf_planner.liquid b/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/next_step_prompt.hf_planner.liquid new file mode 100644 index 00000000..158bf965 --- /dev/null +++ b/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/next_step_prompt.hf_planner.liquid @@ -0,0 +1 @@ +Break down the user’s most recent needs and figure out the next steps. Response must be in appropriate JSON format. \ No newline at end of file