commit
35cbee58ff
|
|
@ -1,4 +1,8 @@
|
|||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using BotSharp.Abstraction.Functions;
|
||||
using BotSharp.Abstraction.Knowledges;
|
||||
using BotSharp.Abstraction.Knowledges.Models;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
using BotSharp.Plugin.Planner.TwoStaging.Models;
|
||||
|
||||
namespace BotSharp.Plugin.Planner.Functions;
|
||||
|
|
@ -27,18 +31,26 @@ public class PrimaryStagePlanFn : IFunctionCallback
|
|||
|
||||
state.SetState("max_tokens", "4096");
|
||||
var task = JsonSerializer.Deserialize<PrimaryRequirementRequest>(message.FunctionArgs);
|
||||
|
||||
// Get knowledge from vectordb
|
||||
var collectionName = knowledgeSettings.Default.CollectionName ?? KnowledgeCollectionName.BotSharp; ;
|
||||
var knowledges = await knowledgeService.SearchVectorKnowledge(task.Requirements, collectionName, new VectorSearchOptions
|
||||
|
||||
//get knowledge from vectordb
|
||||
var knowledges = new List<string>();
|
||||
foreach (var question in task.Questions)
|
||||
{
|
||||
Confidence = 0.1f
|
||||
});
|
||||
message.Content = string.Join("\r\n\r\n=====\r\n", knowledges.Select(x => x.ToQuestionAnswer()));
|
||||
var retrievalMessage = new RoleDialogModel(AgentRole.User, question)
|
||||
{
|
||||
FunctionArgs = JsonSerializer.Serialize(new ExtractedKnowledge
|
||||
{
|
||||
Question = question
|
||||
}),
|
||||
Content = ""
|
||||
};
|
||||
await fn.InvokeFunction("knowledge_retrieval", retrievalMessage);
|
||||
knowledges.Add(retrievalMessage.Content);
|
||||
}
|
||||
|
||||
// Send knowledge to AI to refine and summarize the primary planning
|
||||
var currentAgent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||
var firstPlanningPrompt = await GetFirstStagePlanPrompt(task, message);
|
||||
var firstPlanningPrompt = await GetFirstStagePlanPrompt(task, knowledges);
|
||||
var plannerAgent = new Agent
|
||||
{
|
||||
Id = BuiltInAgentId.Planner,
|
||||
|
|
@ -53,7 +65,7 @@ public class PrimaryStagePlanFn : IFunctionCallback
|
|||
return true;
|
||||
}
|
||||
|
||||
private async Task<string> GetFirstStagePlanPrompt(PrimaryRequirementRequest task, RoleDialogModel message)
|
||||
private async Task<string> GetFirstStagePlanPrompt(PrimaryRequirementRequest task, List<string> relevantKnowledges)
|
||||
{
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
var render = _services.GetRequiredService<ITemplateRender>();
|
||||
|
|
@ -78,7 +90,7 @@ public class PrimaryStagePlanFn : IFunctionCallback
|
|||
{
|
||||
{ "task_description", task.Requirements },
|
||||
{ "global_knowledges", globalKnowledges },
|
||||
{ "relevant_knowledges", new[]{ message.Content } },
|
||||
{ "relevant_knowledges", relevantKnowledges },
|
||||
{ "response_format", responseFormat }
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@ public class PrimaryRequirementRequest
|
|||
[JsonPropertyName("requirement_detail")]
|
||||
public string Requirements { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("has_knowledge_reference")]
|
||||
public bool HasKnowledgeReference { get; set; }
|
||||
|
||||
[JsonPropertyName("question")]
|
||||
public string Question { get; set; } = null!;
|
||||
[JsonPropertyName("questions")]
|
||||
public string[] Questions { get; set; } = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
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.
|
||||
You must Call plan_summary as the last step to summarize the final planning steps.
|
||||
You must Call plan_summary as the last step to summarize the final planning steps.
|
||||
|
||||
{% if global_knowledges != empty -%}
|
||||
=====
|
||||
Global Knowledge:
|
||||
{% for k in global_knowledges %}
|
||||
{{ k }}
|
||||
{% endfor %}
|
||||
{%- endif %}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "plan_primary_stage",
|
||||
"description": "Extract user's original requirements with detail specifications to make the primary plan, you have to include every important informations.",
|
||||
"description": "Plan the high level steps to finish the task",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -8,11 +8,15 @@
|
|||
"type": "string",
|
||||
"description": "User original requirements in detail, don't miss any information especially for those line items, values and numbers."
|
||||
},
|
||||
"question": {
|
||||
"type": "string",
|
||||
"description": "Question convert from requirement and reference tables for knowledge search. The question should contain all the detailed information in the requirement"
|
||||
"questions": {
|
||||
"type": "array",
|
||||
"description": "User requirements in detail, don't miss any information especially for those line items, values and numbers.",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"description": "Question converted from requirement in different ways to search in the knowledge base, be short"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [ "requirement_detail", "question" ]
|
||||
"required": [ "requirement_detail", "questions" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue