Skip to content

Commit 2b6b92c

Browse files
authored
Merge pull request #656 from Joannall/master
Add sql dictionary lookup utility
2 parents 0e2a457 + 4c561eb commit 2b6b92c

File tree

21 files changed

+185
-141
lines changed

21 files changed

+185
-141
lines changed

src/Plugins/BotSharp.Plugin.Planner/Functions/PrimaryStagePlanFn.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public async Task<bool> Execute(RoleDialogModel message)
3333
{
3434
var list = await knowledgeService.SearchVectorKnowledge(question, collectionName, new VectorSearchOptions
3535
{
36-
Confidence = 0.2f
36+
Confidence = 0.4f
3737
});
3838
knowledges.Add(string.Join("\r\n\r\n=====\r\n", list.Select(x => x.ToQuestionAnswer())));
3939

@@ -56,7 +56,10 @@ public async Task<bool> Execute(RoleDialogModel message)
5656
LlmConfig = currentAgent.LlmConfig
5757
};
5858
var response = await GetAiResponse(plannerAgent);
59-
message.Content = response.Content;
59+
message.Content = response.Content;
60+
61+
var states = _services.GetRequiredService<IConversationStateService>();
62+
states.SetState("planning_result", response.Content);
6063

6164
return true;
6265
}

src/Plugins/BotSharp.Plugin.Planner/Functions/SecondaryStagePlanFn.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task<bool> Execute(RoleDialogModel message)
4141

4242
var knowledges = await knowledgeService.SearchVectorKnowledge(item.Task, collectionName, new VectorSearchOptions
4343
{
44-
Confidence = 0.5f
44+
Confidence = 0.6f
4545
});
4646
message.Content += string.Join("\r\n\r\n=====\r\n", knowledges.Select(x => x.ToQuestionAnswer()));
4747
}
@@ -63,6 +63,9 @@ public async Task<bool> Execute(RoleDialogModel message)
6363
var response = await GetAiResponse(plannerAgent);
6464
message.Content = response.Content;
6565
_logger.LogInformation(response.Content);
66+
67+
var states = _services.GetRequiredService<IConversationStateService>();
68+
states.SetState("planning_result", response.Content);
6669
return true;
6770
}
6871

src/Plugins/BotSharp.Plugin.Planner/Functions/SummaryPlanFn.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ public async Task<bool> Execute(RoleDialogModel message)
3030
var taskRequirement = state.GetState("requirement_detail");
3131

3232
// Get table names
33-
var steps = message.Content.JsonArrayContent<SecondStagePlan>();
33+
var states = _services.GetRequiredService<IConversationStateService>();
34+
var steps = states.GetState("planning_result").JsonArrayContent<SecondStagePlan>();
3435
var allTables = new List<string>();
3536
var ddlStatements = "";
36-
var relevantKnowledge = message.Content;
37+
var relevantKnowledge = states.GetState("planning_result");
38+
relevantKnowledge += states.GetState("dictionary_items");
39+
3740
foreach (var step in steps)
3841
{
3942
allTables.AddRange(step.Tables);

src/Plugins/BotSharp.Plugin.Planner/TwoStaging/Models/SecondaryBreakdownTask.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ public class SecondaryBreakdownTask
77

88
[JsonPropertyName("solution_search_question")]
99
public string SolutionQuestion { get; set; } = null!;
10+
11+
[JsonPropertyName("need_lookup_dictionary")]
12+
public bool NeedLookupDictionary { get; set; }
1013
}

src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/functions/plan_summary.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
"parameters": {
55
"type": "object",
66
"properties": {
7+
"related_tables": {
8+
"type": "array",
9+
"description": "table name in planning steps",
10+
"items": {
11+
"type": "string",
12+
"description": "table name"
13+
}
14+
}
715
},
8-
"required": []
16+
"required": [ "related_tables" ]
917
}
1018
}

src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/instructions/instruction.liquid

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
Use the TwoStagePlanner approach to plan the overall implementation steps, follow the below steps strictly.
22
1. Call plan_primary_stage to generate the primary plan.
33
2. If need_additional_information is true, call plan_secondary_stage for the specific primary stage.
4-
3. You must call plan_summary to generate final planned steps.
5-
4. If you can't generate the final accurate planning steps due to missing some specific informations, please ask user for more information.
4+
3. Repeat step 2 until you processed all the primary stages.
5+
4. If need_lookup_dictionary is true, call sql_dictionary_lookup to verify or get the enum/term/dictionary value. Pull id and name.
6+
If you no items retured, you can pull all the list and find the match.
7+
5. You must call plan_summary for you final planned output.
68

79
*** IMPORTANT ***
810
Don't run the planning process repeatedly if you have already got the result of user's request.

src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.1st.plan.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Thinking process:
88
- If there is extra knowledge or relationship needed between steps, set the need_additional_information to true for both steps.
99
- If the solution mentioned "related solutions" is needed, set the need_additional_information to true.
1010
- 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.
11+
- If you need to verify or get the enum/term/dictionary value, set the need_additional_information to true.
1112
3. Input argument must reference to corresponding variable name that retrieved by previous steps, variable name must start with '@';
1213
4. Output all the subtasks as much detail as possible in JSON: [{{ response_format }}]
1314
5. You can NOT generate the final query before calling function plan_summary.

src/Plugins/BotSharp.Plugin.Planner/data/agents/282a7128-69a1-44b0-878c-a9159b88f3b9/templates/two_stage.2nd.plan.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Reference to "Primary Planning" and the additional knowledge included. Breakdown
33
* The parameters can be extracted from the original task.
44
* You need to list all the steps in detail. Finding relationships should also be a step.
55
* When generate the steps, you should find the relationships between data structure based on the provided knowledge strictly.
6+
* If need_lookup_dictionary is true, call sql_dictionary_lookup to verify or get the enum/term/dictionary value. Pull id and name/code.
67
* Output all the steps as much detail as possible in JSON: [{{ response_format }}]
78

89

Original file line numberDiff line numberDiff line change
@@ -1 +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.
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.
2+
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.

src/Plugins/BotSharp.Plugin.SqlDriver/BotSharp.Plugin.SqlDriver.csproj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,27 @@
1818

1919
<ItemGroup>
2020
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\get_table_definition.json" />
21+
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\sql_dictionary_lookup.json" />
2122
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\sql_select.json" />
2223
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\get_table_definition.fn.liquid" />
24+
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\sql_dictionary_lookup.fn.liquid" />
2325
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\sql_executor.fn.liquid" />
2426
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\agent.json" />
2527
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\execute_sql.json" />
2628
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\lookup_dictionary.json" />
2729
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_insert.json" />
2830
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_select.json" />
2931
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\instructions\instruction.liquid" />
30-
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\templates\lookup_dictionary.liquid" />
32+
<None Remove="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\templates\sql_dictionary_lookup.liquid" />
3133
</ItemGroup>
3234

3335
<ItemGroup>
36+
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\sql_dictionary_lookup.json">
37+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
38+
</Content>
39+
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\sql_dictionary_lookup.fn.liquid">
40+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
41+
</Content>
3442
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\get_table_definition.json">
3543
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3644
</Content>
@@ -46,10 +54,7 @@
4654
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\instructions\instruction.liquid">
4755
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4856
</Content>
49-
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\templates\lookup_dictionary.liquid">
50-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
51-
</Content>
52-
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\lookup_dictionary.json">
57+
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\templates\sql_dictionary_lookup.liquid">
5358
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5459
</Content>
5560
<Content Include="data\agents\beda4c12-e1ec-4b4b-b328-3df4a6687c4f\functions\sql_insert.json">

0 commit comments

Comments
 (0)