Skip to content

Commit

Permalink
add DDL to planner
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannall committed Sep 4, 2024
1 parent 99820ef commit 9e2d280
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public async Task<bool> Execute(RoleDialogModel message)
};
var retrievalMessage = new RoleDialogModel(AgentRole.User, task.Requirements)
{
FunctionArgs = JsonSerializer.Serialize(msg),
FunctionArgs = JsonSerializer.Serialize(new ExtractedKnowledge
{
Question = task.Requirements
}),
KnowledgeConfidence = 0.1f,
Content = ""
};
Expand Down
24 changes: 23 additions & 1 deletion src/Plugins/BotSharp.Plugin.Planner/Functions/SummaryPlanFn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using BotSharp.Core.Infrastructures;
using BotSharp.Plugin.Planner.TwoStaging.Models;
using Microsoft.Extensions.Logging;
using BotSharp.Abstraction.Routing;
using BotSharp.Core.Agents.Services;

namespace BotSharp.Plugin.Planner.Functions;

Expand All @@ -23,12 +25,31 @@ public SummaryPlanFn(IServiceProvider services, ILogger<PrimaryStagePlanFn> logg

public async Task<bool> Execute(RoleDialogModel message)
{
var fn = _services.GetRequiredService<IRoutingService>();
var agentService = _services.GetRequiredService<IAgentService>();
var currentAgent = await agentService.LoadAgent(message.CurrentAgentId);
//debug
var state = _services.GetRequiredService<IConversationStateService>();
state.SetState("max_tokens", "4096");

var task = state.GetState("requirement_detail");

//get DDL
var steps = message.Content.JsonArrayContent<SecondStagePlan>();

//get all the related tables
List<string> allTables = new List<string>();
foreach (var step in steps)
{
allTables.AddRange(step.Tables);
}
message.Data = allTables.Distinct().ToList();

//get table DDL and stores in content
var msg2 = RoleDialogModel.From(message);
await fn.InvokeFunction("get_table_definition", msg2);
message.SecondaryContent = msg2.Content;

// summarize and generate query
var summaryPlanningPrompt = await GetPlanSummaryPrompt(task, message);
_logger.LogInformation(summaryPlanningPrompt);
Expand All @@ -37,7 +58,8 @@ public async Task<bool> Execute(RoleDialogModel message)
Id = BuiltInAgentId.Planner,
Name = "planner_summary",
Instruction = summaryPlanningPrompt,
TemplateDict = new Dictionary<string, object>()
TemplateDict = new Dictionary<string, object>(),
LlmConfig = currentAgent.LlmConfig
};
var response_summary = await GetAIResponse(plannerAgent);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Use the TwoStagePlanner approach to plan the overall implementation steps, call plan_primary_stage.
If need_additional_information is true, call plan_secondary_stage for the specific primary stage.
Call plan_summary to summarize the final planning steps.
You must Call plan_summary as the last step to summarize the final planning steps.

0 comments on commit 9e2d280

Please sign in to comment.