diff --git a/Directory.Build.props b/Directory.Build.props index 86eafbe7..09841a41 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ 10.0 ..\..\..\packages - 0.14.1 + 0.14.2 true \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 52e0a5c9..e829cff9 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -75,19 +75,9 @@ - - - - PreserveNewest - - - PreserveNewest - - - True diff --git a/src/Infrastructure/BotSharp.Core/Routing/PromptConst.cs b/src/Infrastructure/BotSharp.Core/Routing/PromptConst.cs new file mode 100644 index 00000000..18c10cd9 --- /dev/null +++ b/src/Infrastructure/BotSharp.Core/Routing/PromptConst.cs @@ -0,0 +1,72 @@ +namespace BotSharp.Core.Routing; + +public class PromptConst +{ + public const string ROUTER_PROMPT = @" +You're a Router with reasoning, you can dispatch request to different agent to complete the task. + +### Agents: +{% for agent in routing_records %} +* {{ agent.name }} +{{ agent.description }} +{% if agent.required_fields != empty -%}Required information: {{ agent.required_fields }}.{%- endif %} +{% endfor %} + +### Functions +{% if enable_reasoning == false -%} +* route_to_agent +Route request to appropriate agent. +Parameters: +1. agent_name: the name of the agent; +2. reason: why route to this agent; +3. args: parameters extracted from context; +{%- endif %} + +* task_end +Call this function when current task is completed. +Parameters: +1. abandoned_arguments: the arguments next task can't reuse; + +* conversation_end +Call this function when user wants to end this conversation or all tasks have been completed. + +* transfer_to_csr +Reach out to a real customer representative to help. + +{{ reasoning_functions }} + +### Your response must meet below requirements strictly +{% if enable_reasoning == false %} +* If you can find an appropriate Agent, you must call function route_to_agent with required arguments. +{% endif %} + +### Conversation context:"; + + public const string REASONING_FUNCTIONS = @" +* retrieve_data_from_agent +Retrieve data from appropriate agent. +Parameters: +1. agent_name: the name of the agent; +2. question: the question you will ask the agent to get the necessary data; +3. reason: why retrieve data; +4. args: required parameters extracted from question and hand over to the next agent. The args should be in JSON format; + +* continue_execute_task +Continue to execute user's request without further information retrival. +Parameters: +1. agent_name: the name of the agent; +2. args: required parameters extracted from question; +3. reason: why continue to execute current task; + +* interrupt_task_execution +Can't continue user's request becauase the requirements are not met. +Parameters: +1. reason: the reason why the request is interrupted; +2. answer: the content response to user; + +* response_to_user +You have already known the answer according the dialogs. +Parameters: +1. answer: the response of user's request; +2. reason: why response to user;"; +} diff --git a/src/Infrastructure/BotSharp.Core/Routing/Prompts/reasoning_functions.liquid b/src/Infrastructure/BotSharp.Core/Routing/Prompts/reasoning_functions.liquid deleted file mode 100644 index 0831261b..00000000 --- a/src/Infrastructure/BotSharp.Core/Routing/Prompts/reasoning_functions.liquid +++ /dev/null @@ -1,26 +0,0 @@ -* retrieve_data_from_agent -Retrieve data from appropriate agent. -Parameters: -1. agent_name: the name of the agent; -2. question: the question you will ask the agent to get the necessary data; -3. reason: why retrieve data; -4. args: required parameters extracted from question and hand over to the next agent. The args should be in JSON format; - -* continue_execute_task -Continue to execute user's request without further information retrival. -Parameters: -1. agent_name: the name of the agent; -2. args: required parameters extracted from question; -3. reason: why continue to execute current task; - -* interrupt_task_execution -Can't continue user's request becauase the requirements are not met. -Parameters: -1. reason: the reason why the request is interrupted; -2. answer: the content response to user; - -* response_to_user -You have already known the answer according the dialogs. -Parameters: -1. answer: the response of user's request; -2. reason: why response to user; diff --git a/src/Infrastructure/BotSharp.Core/Routing/Prompts/router_prompt.liquid b/src/Infrastructure/BotSharp.Core/Routing/Prompts/router_prompt.liquid deleted file mode 100644 index 941e7bdd..00000000 --- a/src/Infrastructure/BotSharp.Core/Routing/Prompts/router_prompt.liquid +++ /dev/null @@ -1,38 +0,0 @@ -You're a Router with reasoning, you can dispatch request to different agent to complete the task. - -### Agents: -{% for agent in routing_records %} -* {{ agent.name }} -{{ agent.description }} -{% if agent.required_fields != empty -%}Required information: {{ agent.required_fields }}.{%- endif %} -{% endfor %} - -### Functions -{% if enable_reasoning == false -%} -* route_to_agent -Route request to appropriate agent. -Parameters: -1. agent_name: the name of the agent; -2. reason: why route to this agent; -3. args: parameters extracted from context; -{%- endif %} - -* task_end -Call this function when current task is completed. -Parameters: -1. abandoned_arguments: the arguments next task can't reuse; - -* conversation_end -Call this function when user wants to end this conversation or all tasks have been completed. - -* transfer_to_csr -Reach out to a real customer representative to help. - -{{ reasoning_functions }} - -### Your response must meet below requirements strictly -{% if enable_reasoning == false %} -* If you can find an appropriate Agent, you must call function route_to_agent with required arguments. -{% endif %} - -### Conversation context: \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index 0feb3cb1..160708fa 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -224,17 +224,14 @@ public class RoutingService : IRoutingService .ToArray() }).ToArray(); - var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Routing", "Prompts"); - var template = File.ReadAllText(Path.Combine(dir, "router_prompt.liquid")); - dict["enable_reasoning"] = _settings.EnableReasoning; if (_settings.EnableReasoning) { - dict["reasoning_functions"] = File.ReadAllText(Path.Combine(dir, "reasoning_functions.liquid")); + dict["reasoning_functions"] = PromptConst.REASONING_FUNCTIONS; } var render = _services.GetRequiredService(); - router.Instruction = render.Render(template, dict); + router.Instruction = render.Render(PromptConst.ROUTER_PROMPT, dict); return router; } diff --git a/src/Plugins/BotSharp.Plugin.PaddleSharp/BotSharp.Plugin.PaddleSharp.csproj b/src/Plugins/BotSharp.Plugin.PaddleSharp/BotSharp.Plugin.PaddleSharp.csproj index 84b31e0e..8bbc072d 100644 --- a/src/Plugins/BotSharp.Plugin.PaddleSharp/BotSharp.Plugin.PaddleSharp.csproj +++ b/src/Plugins/BotSharp.Plugin.PaddleSharp/BotSharp.Plugin.PaddleSharp.csproj @@ -4,7 +4,7 @@ netstandard2.1 enable $(LangVersion) - $(PackageVersion) + $(BotSharpVersion) $(GeneratePackageOnBuild) diff --git a/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj b/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj index 2bc35d74..ac6d48a2 100644 --- a/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj +++ b/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj @@ -4,11 +4,17 @@ netstandard2.1 enable $(LangVersion) + $(BotSharpVersion) + $(GeneratePackageOnBuild) ..\..\packages + + + + - + diff --git a/tests/BotSharp.Plugin.PizzaBot/Functions/OrderFoundFn.cs b/tests/BotSharp.Plugin.PizzaBot/Functions/OrderFoundFn.cs deleted file mode 100644 index 90a85b50..00000000 --- a/tests/BotSharp.Plugin.PizzaBot/Functions/OrderFoundFn.cs +++ /dev/null @@ -1,14 +0,0 @@ -using BotSharp.Abstraction.Conversations.Models; - -namespace BotSharp.Plugin.PizzaBot.Functions; - -public class OrderFoundFn : IFunctionCallback -{ - public string Name => "order_found"; - - public async Task Execute(RoleDialogModel message) - { - message.ExecutionResult = "The order number is P123-01"; - return true; - } -} diff --git a/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs b/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs index 087b6d8a..3e0a8171 100644 --- a/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs +++ b/tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs @@ -11,7 +11,6 @@ public class PizzaBotPlugin : IBotSharpPlugin services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddScoped();