From 3d99747cf355e7d86f482f44c68593aab13d2465 Mon Sep 17 00:00:00 2001 From: Joanna Ren <101223@smsassist.com> Date: Thu, 10 Oct 2024 09:59:42 -0500 Subject: [PATCH] Add Refined Knowledge memorize and search. Update Planner terms --- .../Knowledges/Models/ExtractedKnowledge.cs | 3 + .../TwoStagePlanner/FirstStagePlan.cs | 5 +- .../Services/MySqlService.cs | 2 +- .../BotSharp.Plugin.KnowledgeBase.csproj | 4 ++ .../Functions/GenerateKnowledgeFn.cs | 65 +++++++++++++++++++ .../Functions/MemorizeKnowledgeFn.cs | 4 +- .../templates/knowledge.generation.liquid | 12 ++++ .../Functions/SecondaryStagePlanFn.cs | 2 +- .../Functions/SummaryPlanFn.cs | 14 +++- .../TwoStaging/Models/FirstStagePlan.cs | 5 +- .../TwoStaging/Models/SecondStagePlan.cs | 3 + .../instructions/instruction.liquid | 8 ++- .../templates/two_stage.1st.plan.liquid | 11 ++-- .../templates/two_stage.2nd.plan.liquid | 2 +- .../templates/two_stage.summarize.liquid | 4 ++ .../templates/plan_secondary_stage.fn.liquid | 3 +- .../Functions/LookupDictionaryFn.cs | 2 +- .../Hooks/SqlDictionaryLookupHook.cs | 2 +- .../functions/sql_dictionary_lookup.json | 4 +- .../templates/sql_dictionary_lookup.fn.liquid | 11 ++-- 20 files changed, 140 insertions(+), 26 deletions(-) create mode 100644 src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/GenerateKnowledgeFn.cs create mode 100644 src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.liquid diff --git a/src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/ExtractedKnowledge.cs b/src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/ExtractedKnowledge.cs index 0043c437a..eecd56d17 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/ExtractedKnowledge.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/ExtractedKnowledge.cs @@ -7,4 +7,7 @@ public class ExtractedKnowledge [JsonPropertyName("answer")] public string Answer { get; set; } = string.Empty; + + [JsonPropertyName("refined_collection")] + public string RefinedCollection { get; set; } = string.Empty; } diff --git a/src/Infrastructure/BotSharp.Core/Routing/Planning/TwoStagePlanner/FirstStagePlan.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/TwoStagePlanner/FirstStagePlan.cs index 1ae18e842..a0e5412cc 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Planning/TwoStagePlanner/FirstStagePlan.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/TwoStagePlanner/FirstStagePlan.cs @@ -13,9 +13,12 @@ public class FirstStagePlan [JsonPropertyName("step")] public int Step { get; set; } = -1; - [JsonPropertyName("need_additional_information")] + [JsonPropertyName("need_breakdown_task")] public bool ContainMultipleSteps { get; set; } = false; + [JsonPropertyName("need_lookup_dictionary")] + public bool NeedLookupDictionary { get; set; } = false; + [JsonPropertyName("related_tables")] public string[] Tables { get; set; } = new string[0]; diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs index 9ca55a66c..7ba8aaf48 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs @@ -215,7 +215,7 @@ private List ParseSheetColumn(ISheet sheet) } private string CreateDBTableSqlString(string tableName, List headerColumns, List? columnTypes = null, bool isMemory = false) { - _columnTypes = columnTypes.IsNullOrEmpty() ? headerColumns.Select(x => "VARCHAR(512)").ToList() : columnTypes; + _columnTypes = columnTypes.IsNullOrEmpty() ? headerColumns.Select(x => "VARCHAR(128)").ToList() : columnTypes; /*if (!headerColumns.Any(x => x.Equals("id", StringComparison.OrdinalIgnoreCase))) { diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj b/src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj index 29c81ec73..c5c0a2d26 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj @@ -21,6 +21,7 @@ + @@ -37,6 +38,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/GenerateKnowledgeFn.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/GenerateKnowledgeFn.cs new file mode 100644 index 000000000..cd43fca1d --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/GenerateKnowledgeFn.cs @@ -0,0 +1,65 @@ +using BotSharp.Abstraction.Templating; +using BotSharp.Core.Infrastructures; + +namespace BotSharp.Plugin.KnowledgeBase.Functions; + +public class GenerateKnowledgeFn : IFunctionCallback +{ + public string Name => "generate_knowledge"; + + public string Indication => "generating knowledge"; + + private readonly IServiceProvider _services; + private readonly KnowledgeBaseSettings _settings; + + public GenerateKnowledgeFn(IServiceProvider services, KnowledgeBaseSettings settings) + { + _services = services; + _settings = settings; + } + + public async Task Execute(RoleDialogModel message) + { + var args = JsonSerializer.Deserialize(message.FunctionArgs ?? "{}"); + var agentService = _services.GetRequiredService(); + var llmAgent = await agentService.GetAgent(BuiltInAgentId.Planner); + var generateKnowledgePrompt = await GetGenerateKnowledgePrompt(args.Question, args.Answer); + var agent = new Agent + { + Id = message.CurrentAgentId ?? string.Empty, + Name = "sqlDriver_DictionarySearch", + Instruction = generateKnowledgePrompt, + LlmConfig = llmAgent.LlmConfig + }; + var response = await GetAiResponse(agent); + message.Data = response.Content.JsonArrayContent(); + message.Content = response.Content; + return true; + } + + private async Task GetGenerateKnowledgePrompt(string userQuestions, string sqlAnswer) + { + var agentService = _services.GetRequiredService(); + var render = _services.GetRequiredService(); + + var agent = await agentService.GetAgent(BuiltInAgentId.Learner); + var template = agent.Templates.FirstOrDefault(x => x.Name == "knowledge.generation")?.Content ?? string.Empty; + + return render.Render(template, new Dictionary + { + { "user_questions", userQuestions }, + { "sql_answer", sqlAnswer }, + }); + } + private async Task GetAiResponse(Agent agent) + { + var text = "Generate question and answer pair"; + var message = new RoleDialogModel(AgentRole.User, text); + + var completion = CompletionProvider.GetChatCompletion(_services, + provider: agent.LlmConfig.Provider, + model: agent.LlmConfig.Model); + + return await completion.GetChatCompletions(agent, new List { message }); + } +} diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/MemorizeKnowledgeFn.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/MemorizeKnowledgeFn.cs index 0af59975d..e432abc1d 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/MemorizeKnowledgeFn.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/MemorizeKnowledgeFn.cs @@ -19,7 +19,9 @@ public async Task Execute(RoleDialogModel message) { var args = JsonSerializer.Deserialize(message.FunctionArgs ?? "{}"); - var collectionName = _settings.Default.CollectionName ?? KnowledgeCollectionName.BotSharp; + var collectionName = !string.IsNullOrEmpty(args.RefinedCollection) + ? args.RefinedCollection + : _settings.Default.CollectionName ?? KnowledgeCollectionName.BotSharp; var knowledgeService = _services.GetRequiredService(); var result = await knowledgeService.CreateVectorCollectionData(collectionName, new VectorCreateModel { diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.liquid b/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.liquid new file mode 100644 index 000000000..82afe7e6a --- /dev/null +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/data/agents/01acc3e5-0af7-49e6-ad7a-a760bd12dc40/templates/knowledge.generation.liquid @@ -0,0 +1,12 @@ +You are a knowledge generator for knowledge base. Extract the answer in "SQL Answer" to answer the User Questions +Replace alias with the actual table name. Output json array only, formatting as [{"question":"string", "answer":"string/sql statement"}]. +Skip the question/answer for tmp table. +Don't include tmp table in the answer. + +===== +User Questions: +{{ user_questions }} + +===== +SQL Answer: +{{ sql_answer }} diff --git a/src/Plugins/BotSharp.Plugin.Planner/Functions/SecondaryStagePlanFn.cs b/src/Plugins/BotSharp.Plugin.Planner/Functions/SecondaryStagePlanFn.cs index ba7c70474..918b33e59 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/Functions/SecondaryStagePlanFn.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/Functions/SecondaryStagePlanFn.cs @@ -31,7 +31,7 @@ public async Task Execute(RoleDialogModel message) // Search knowledgebase var knowledges = await knowledgeService.SearchVectorKnowledge(taskSecondary.SolutionQuestion, collectionName, new VectorSearchOptions { - Confidence = 0.6f + Confidence = 0.7f }); var knowledgeResults = string.Join("\r\n\r\n=====\r\n", knowledges.Select(x => x.ToQuestionAnswer())); diff --git a/src/Plugins/BotSharp.Plugin.Planner/Functions/SummaryPlanFn.cs b/src/Plugins/BotSharp.Plugin.Planner/Functions/SummaryPlanFn.cs index fd464e23b..22ddc3c32 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/Functions/SummaryPlanFn.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/Functions/SummaryPlanFn.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Knowledges; using BotSharp.Abstraction.Planning; using BotSharp.Plugin.Planner.TwoStaging; using BotSharp.Plugin.Planner.TwoStaging.Models; @@ -54,7 +55,7 @@ public async Task Execute(RoleDialogModel message) ddlStatements += "\r\n" + msgCopy.Content; // Summarize and generate query - var summaryPlanPrompt = await GetSummaryPlanPrompt(taskRequirement, relevantKnowledge, dictionaryItems, ddlStatements, excelImportResult); + var summaryPlanPrompt = await GetSummaryPlanPrompt(msgCopy, taskRequirement, relevantKnowledge, dictionaryItems, ddlStatements, excelImportResult); _logger.LogInformation($"Summary plan prompt:\r\n{summaryPlanPrompt}"); var plannerAgent = new Agent @@ -74,10 +75,11 @@ await HookEmitter.Emit(_services, x => return true; } - private async Task GetSummaryPlanPrompt(string taskDescription, string relevantKnowledge, string dictionaryItems, string ddlStatement, string excelImportResult) + private async Task GetSummaryPlanPrompt(RoleDialogModel message, string taskDescription, string relevantKnowledge, string dictionaryItems, string ddlStatement, string excelImportResult) { var agentService = _services.GetRequiredService(); var render = _services.GetRequiredService(); + var knowledgeHooks = _services.GetServices(); var agent = await agentService.GetAgent(BuiltInAgentId.Planner); var template = agent.Templates.FirstOrDefault(x => x.Name == "two_stage.summarize")?.Content ?? string.Empty; @@ -89,10 +91,18 @@ await HookEmitter.Emit(_services, async x => additionalRequirements.Add(requirement); }); + var globalKnowledges = new List(); + foreach (var hook in knowledgeHooks) + { + var k = await hook.GetGlobalKnowledges(message); + globalKnowledges.AddRange(k); + } + return render.Render(template, new Dictionary { { "task_description", taskDescription }, { "summary_requirements", string.Join("\r\n", additionalRequirements) }, + { "global_knowledges", globalKnowledges }, { "relevant_knowledges", relevantKnowledge }, { "dictionary_items", dictionaryItems }, { "table_structure", ddlStatement }, diff --git a/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/FirstStagePlan.cs b/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/FirstStagePlan.cs index 754e5308a..9588b8113 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/FirstStagePlan.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/FirstStagePlan.cs @@ -11,9 +11,12 @@ public class FirstStagePlan [JsonPropertyName("step")] public int Step { get; set; } = -1; - [JsonPropertyName("need_additional_information")] + [JsonPropertyName("need_breakdown_task")] public bool NeedAdditionalInformation { get; set; } = false; + [JsonPropertyName("need_lookup_dictionary")] + public bool NeedLookupDictionary { get; set; } = false; + [JsonPropertyName("related_tables")] public string[] Tables { get; set; } = []; diff --git a/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/SecondStagePlan.cs b/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/SecondStagePlan.cs index 9076a6b45..652d4e7d5 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/SecondStagePlan.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/SecondStagePlan.cs @@ -5,6 +5,9 @@ public class SecondStagePlan [JsonPropertyName("related_tables")] public string[] Tables { get; set; } = []; + [JsonPropertyName("need_lookup_dictionary")] + public bool NeedLookupDictionary { get; set; } = false; + [JsonPropertyName("description")] public string Description { get; set; } = ""; diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid index 2f4c7a414..5dda81e3a 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid @@ -1,9 +1,11 @@ Use the TwoStagePlanner approach to plan the overall implementation steps, follow the below steps strictly. 1. Call plan_primary_stage to generate the primary plan. -2. If need_additional_information is true, call plan_secondary_stage for the specific primary stage. -3. Repeat step 2 until you processed all the primary stages. -4. If need_lookup_dictionary is true, call sql_dictionary_lookup to verify or get the enum/term/dictionary value. Pull id and name. + If you've already got the plan to meet the user goal, directly go to step 5. +2. If need_lookup_dictionary is True, call verify_dictionary_term to verify or get the enum/term/dictionary value. Pull id and name. If you no items retured, you can pull all the list and find the match. + If need_lookup_dictionary is False, skip calling verify_dictionary_term. +3. If need_breakdown_task is true, call plan_secondary_stage for the specific primary stage. +4. Repeat step 3 until you processed all the primary stages. 5. You must call plan_summary for you final planned output. *** IMPORTANT *** diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid index f6e8f5579..656a6fe41 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid @@ -4,11 +4,12 @@ Thinking process: 1. Reference to "Task Knowledge" if there is relevant knowledge; 2. Breakdown task into subtasks. - The subtask should contain all needed parameters for subsequent steps. - - If limited information provided and there are furture information needed, or miss relationship between steps, set the need_additional_information to true. - - If there is extra knowledge or relationship needed between steps, set the need_additional_information to true for both steps. - - If the solution mentioned "related solutions" is needed, set the need_additional_information to true. - - You should find the relationships between data structure based on the task knowledge strictly. If lack of information, set the need_additional_information to true. - - If you need to lookup the dictionary to verify or get the enum/term/dictionary value, set the need_additional_information to true. + - If limited information provided and there are furture information needed, or miss relationship between steps, set the need_breakdown_task to true. + - If there is extra knowledge or relationship needed between steps, set the need_breakdown_task to true for both steps. + - If the solution mentioned "related solutions" is needed, set the need_breakdown_task to true. + - You should find the relationships between data structure based on the task knowledge strictly. If lack of information, set the need_breakdown_task to true. + - If you need to lookup the dictionary to verify or get the enum/term/dictionary value, set the need_lookup_dictionary to true. + - Seperate the dictionary lookup and need additional information/knowledge into different subtask. 3. Input argument must reference to corresponding variable name that retrieved by previous steps, variable name must start with '@'; 4. Output all the subtasks as much detail as possible in JSON: [{{ response_format }}] 5. You can NOT generate the final query before calling function plan_summary. diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.2nd.plan.liquid b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.2nd.plan.liquid index d4bd15b54..113767aed 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.2nd.plan.liquid +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.2nd.plan.liquid @@ -3,7 +3,7 @@ Reference to "Primary Planning" and the additional knowledge included. Breakdown * The parameters can be extracted from the original task. * You need to list all the steps in detail. Finding relationships should also be a step. * When generate the steps, you should find the relationships between data structure based on the provided knowledge strictly. -* If need_lookup_dictionary is true, call sql_dictionary_lookup to verify or get the enum/term/dictionary value. Pull id and name/code. +* If need_lookup_dictionary is true, call verify_dictionary_term to verify or get the enum/term/dictionary value. Pull id and name/code. * Output all the steps as much detail as possible in JSON: [{{ response_format }}] diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.summarize.liquid b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.summarize.liquid index b4b28e0e6..6b901eb84 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.summarize.liquid +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.summarize.liquid @@ -7,6 +7,10 @@ Requirements: Task description: {{ task_description }} +===== +Global Knowledges: +{{ global_knowledges }} + ===== Relevant Knowledges: {{ relevant_knowledges }} diff --git a/src/Plugins/BotSharp.Plugin.Planner/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/plan_secondary_stage.fn.liquid b/src/Plugins/BotSharp.Plugin.Planner/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/plan_secondary_stage.fn.liquid index 31aca793c..1b2e95bd5 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/plan_secondary_stage.fn.liquid +++ b/src/Plugins/BotSharp.Plugin.Planner/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/plan_secondary_stage.fn.liquid @@ -1,2 +1 @@ -For every primary step, if need_additional_information is true, you have to call plan_secondary_stage to plan the detail steps to complete the primary step. -if need_lookup_dictionary is true, you have to call sql_dictionary_lookup to verify or get the enum/term/dictionary value. Pull id and name/code. \ No newline at end of file +For every primary step, if need_breakdown_task is true, you have to call plan_secondary_stage to plan the detail steps to complete the primary step. \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/LookupDictionaryFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/LookupDictionaryFn.cs index ed1d9d4b2..c94c12db7 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/LookupDictionaryFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/LookupDictionaryFn.cs @@ -9,7 +9,7 @@ namespace BotSharp.Plugin.SqlDriver.Functions; public class LookupDictionaryFn : IFunctionCallback { - public string Name => "sql_dictionary_lookup"; + public string Name => "verify_dictionary_term"; private readonly IServiceProvider _services; public LookupDictionaryFn(IServiceProvider services) diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDictionaryLookupHook.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDictionaryLookupHook.cs index edaa0cf3f..27af8e64f 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDictionaryLookupHook.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Hooks/SqlDictionaryLookupHook.cs @@ -10,7 +10,7 @@ public class SqlDictionaryLookupHook : AgentHookBase, IAgentHook private const string SQL_EXECUTOR_TEMPLATE = "sql_dictionary_lookup.fn"; private IEnumerable _targetSqlExecutorFunctions = new List { - "sql_dictionary_lookup", + "verify_dictionary_term", }; public override string SelfId => BuiltInAgentId.Planner; diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/sql_dictionary_lookup.json b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/sql_dictionary_lookup.json index 66abe7059..1be003a44 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/sql_dictionary_lookup.json +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/functions/sql_dictionary_lookup.json @@ -1,5 +1,5 @@ { - "name": "sql_dictionary_lookup", + "name": "verify_dictionary_term", "description": "Get id from dictionary table by keyword if tool or solution mentioned this approach", "parameters": { "type": "object", @@ -10,7 +10,7 @@ }, "reason": { "type": "string", - "description": "the reason why you need to call sql_dictionary_lookup" + "description": "the reason why you need to call verify_dictionary_term" }, "tables": { "type": "array", diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/sql_dictionary_lookup.fn.liquid b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/sql_dictionary_lookup.fn.liquid index 73dcb58da..f5ceebdb2 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/sql_dictionary_lookup.fn.liquid +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/data/agents/6745151e-6d46-4a02-8de4-1c4f21c7da95/templates/sql_dictionary_lookup.fn.liquid @@ -1,8 +1,11 @@ -Dictionary Lookup Rules: +Dictionary Verification Rules: ===== -Please call function sql_dictionary_lookup if user wants to get or retrieve dictionary/enum/term from data tables. -You must return the id and name/code. The table name must come from the planning in conversation. +1. The table name must come from the planning in conversation. +2. You must return the id and name/code. You are connecting to {{ db_type }} database. You can run provided SQL statements by following {{ db_type }} rules. -Dictionary table pattern is table name starting with "data_". You can only query the dictionary table without join other non-dictionary tables. + +The dictionary table is identified by a name that begins with "data_". You are only allowed to query the dictionary table without joining it with other non-dictionary tables. + +IMPORTANT: Don't generate insert SQL. ===== \ No newline at end of file