Fix sequential planning infinite loop.
This commit is contained in:
parent
834b4e5caf
commit
8aa7158932
|
|
@ -40,4 +40,6 @@ public interface IRoutingService
|
|||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
Task<RoleDialogModel> InstructDirect(Agent agent, RoleDialogModel message);
|
||||
|
||||
Task<string> GetConversationContent(List<RoleDialogModel> dialogs, int maxDialogCount = 50);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,4 +6,7 @@ public class DecomposedStep
|
|||
|
||||
[JsonPropertyName("total_remaining_steps")]
|
||||
public int TotalRemainingSteps { get; set; }
|
||||
|
||||
[JsonPropertyName("stop_reason")]
|
||||
public string? StopReason { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,18 @@ public class SequentialPlanner : IPlaner
|
|||
_lastInst.Reason = $"{decomposation.TotalRemainingSteps} left.";
|
||||
return _lastInst;
|
||||
}
|
||||
else if (decomposation.TotalRemainingSteps == 0)
|
||||
{
|
||||
// Tell router all steps are done
|
||||
dialogs.Add(new RoleDialogModel(AgentRole.Assistant, decomposation.StopReason)
|
||||
{
|
||||
CurrentAgentId = router.Id,
|
||||
FunctionName = nameof(SequentialPlanner),
|
||||
MessageId = messageId
|
||||
});
|
||||
router.TemplateDict["conversation"] = router.TemplateDict["conversation"].ToString().TrimEnd() +
|
||||
$"\r\n{router.Name}: {decomposation.StopReason}";
|
||||
}
|
||||
|
||||
var next = GetNextStepPrompt(router);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ If a specific step has been exectued, you will get something indicates the resul
|
|||
If there is no any result provided, it means all the steps have not been executed yet.
|
||||
You need to figure out which steps have not been completed.
|
||||
Tell me what is the first remaining step from user steps that have not been completed based on the context.
|
||||
Output in JSON { "description": "step detail with arguments", "total_remaining_steps": 0}
|
||||
Output in JSON { "description": "step detail with arguments", "total_remaining_steps": 0, "stop_reason": "the reason why it should total remaining steps is zero"}
|
||||
|
|
@ -1,4 +1,2 @@
|
|||
In order to sequentially execute user tasks,
|
||||
What is the next step based on the CONVERSATION?
|
||||
Put the next step detail in reason.
|
||||
Don't response to user if there is any step that has not been completed.
|
||||
What is the next step based on the CONVERSATION?
|
||||
|
|
@ -2,7 +2,9 @@ namespace BotSharp.Plugin.WebDriver.Drivers;
|
|||
|
||||
public interface IWebBrowser
|
||||
{
|
||||
Agent Agent { get; }
|
||||
void SetAgent(Agent agent);
|
||||
Task LaunchBrowser(string? url);
|
||||
Task InputUserText(Agent agent, BrowsingContextIn context, string messageId);
|
||||
Task InputUserPassword(Agent agent, BrowsingContextIn context, string messageId);
|
||||
Task ClickElement(Agent agent, BrowsingContextIn context, string messageId);
|
||||
Task GoToPage(Agent agent, BrowsingContextIn context, string messageId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,13 @@ public class PlaywrightInstance : IDisposable
|
|||
{
|
||||
Headless = false,
|
||||
Channel = "chrome",
|
||||
Args = new string[]
|
||||
IgnoreDefaultArgs = new[]
|
||||
{
|
||||
"enable-automation"
|
||||
},
|
||||
Args = new[]
|
||||
{
|
||||
"--disable-infobars"
|
||||
// "--start-maximized"
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,12 +12,14 @@ public partial class PlaywrightWebDriver
|
|||
// Find by text exactly match
|
||||
var elements = _instance.Page.GetByRole(AriaRole.Textbox, new PageGetByRoleOptions
|
||||
{
|
||||
Name = context.ElementName
|
||||
Name = context.ElementText
|
||||
});
|
||||
var count = await elements.CountAsync();
|
||||
|
||||
elements = _instance.Page.GetByPlaceholder(context.ElementName);
|
||||
count = await elements.CountAsync();
|
||||
if (count == 0)
|
||||
{
|
||||
elements = _instance.Page.GetByPlaceholder(context.ElementText);
|
||||
count = await elements.CountAsync();
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
|
|
@ -25,7 +27,7 @@ public partial class PlaywrightWebDriver
|
|||
var html = await FilteredInputHtml();
|
||||
var htmlElementContextOut = await driverService.InferElement(agent,
|
||||
html,
|
||||
context.ElementName,
|
||||
context.ElementText,
|
||||
messageId);
|
||||
elements = Locator(htmlElementContextOut);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,12 @@ public class InputUserTextFn : IFunctionCallback
|
|||
var agent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||
await _driver.InputUserText(agent, args, message.MessageId);
|
||||
|
||||
message.Content = $"Input text \"{args.InputText}\" successfully.";
|
||||
message.Content = $"Input text \"{args.InputText}\"";
|
||||
if (args.PressEnter.HasValue && args.PressEnter.Value)
|
||||
{
|
||||
message.Content += " and pressed Enter";
|
||||
}
|
||||
message.Content += " successfully.\"";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,9 +71,9 @@
|
|||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"element_name": {
|
||||
"element_text": {
|
||||
"type": "string",
|
||||
"description": "the html input box element name."
|
||||
"description": "text or placeholder shown in the element."
|
||||
},
|
||||
"input_text": {
|
||||
"type": "string",
|
||||
|
|
@ -84,7 +84,7 @@
|
|||
"description": "whether to press Enter key"
|
||||
}
|
||||
},
|
||||
"required": [ "element_name", "input_text" ]
|
||||
"required": [ "element_text", "input_text" ]
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -131,7 +131,7 @@
|
|||
},
|
||||
"element_text": {
|
||||
"type": "string",
|
||||
"description": "text shown in the element."
|
||||
"description": "text or placeholder shown in the element."
|
||||
},
|
||||
"match_rule": {
|
||||
"type": "string",
|
||||
|
|
|
|||
Loading…
Reference in a new issue