diff --git a/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs b/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs index a7201f2d..7ecd27b6 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Planning/SequentialPlanner.cs @@ -30,24 +30,22 @@ public class SequentialPlanner : IPlaner if (decomposation.TotalRemainingSteps > 0 && _lastInst != null) { _lastInst.Response = decomposation.Description; - _lastInst.Reason = $"{decomposation.TotalRemainingSteps} left."; - dialogs.Add(new RoleDialogModel(AgentRole.User, decomposation.Description) - { - CurrentAgentId = router.Id, - MessageId = messageId - }); + _lastInst.Reason = $"Having {decomposation.TotalRemainingSteps} steps left."; return _lastInst; } else if (decomposation.TotalRemainingSteps == 0 || decomposation.ShouldStop) { - // Tell router all steps are done - dialogs.Add(new RoleDialogModel(AgentRole.Assistant, decomposation.StopReason) + if (!string.IsNullOrEmpty(decomposation.StopReason)) { - CurrentAgentId = router.Id, - MessageId = messageId - }); - router.TemplateDict["conversation"] = router.TemplateDict["conversation"].ToString().TrimEnd() + - $"\r\n{router.Name}: {decomposation.StopReason}"; + // Tell router all steps are done + dialogs.Add(new RoleDialogModel(AgentRole.Assistant, decomposation.StopReason) + { + CurrentAgentId = router.Id, + MessageId = messageId + }); + router.TemplateDict["conversation"] = router.TemplateDict["conversation"].ToString().TrimEnd() + + $"\r\n{router.Name}: {decomposation.StopReason}"; + } } var next = GetNextStepPrompt(router); @@ -177,7 +175,6 @@ public class SequentialPlanner : IPlaner }, dialogs); text = response.Content; - Console.WriteLine(text, Color.OrangeRed); inst = response.Content.JsonContent(); break; } diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.sequential.get_remaining_task.liquid b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.sequential.get_remaining_task.liquid index ad746a92..0c93d4e8 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.sequential.get_remaining_task.liquid +++ b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/planner_prompt.sequential.get_remaining_task.liquid @@ -6,7 +6,7 @@ Tell me what is the first remaining step from user steps that have not been comp Output in JSON { "description": "step detail with arguments", - "total_remaining_steps": -1, + "total_remaining_steps": 0, "should_stop": false, - "stop_reason": "the reason why it should total remaining steps is zero" + "stop_reason": "the reason why it should stop" } \ No newline at end of file diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs index 26690494..a1939921 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs @@ -32,7 +32,7 @@ public class PlaywrightInstance : IDisposable string tempFolderPath = $"{Path.GetTempPath()}\\playwright\\{Guid.NewGuid()}"; _context = await _playwright.Chromium.LaunchPersistentContextAsync(tempFolderPath, new BrowserTypeLaunchPersistentContextOptions { - Headless = true, + Headless = false, Channel = "chrome", IgnoreDefaultArgs = new[] { diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ClickButton.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ClickButton.cs index 367cf50a..b4a9ce9a 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ClickButton.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.ClickButton.cs @@ -27,6 +27,12 @@ public partial class PlaywrightWebDriver count = await elements.CountAsync(); } + if (count == 0) + { + elements = _instance.Page.GetByText(actionParams.Context.ElementName); + count = await elements.CountAsync(); + } + if (count == 0) { // Infer element if not found diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ChangeCheckboxFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ChangeCheckboxFn.cs index 9762c4a8..6100158c 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ChangeCheckboxFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ChangeCheckboxFn.cs @@ -22,9 +22,10 @@ public class ChangeCheckboxFn : IFunctionCallback var agent = await agentService.LoadAgent(message.CurrentAgentId); var result = await _browser.ChangeCheckbox(new BrowserActionParams(agent, args, message.MessageId)); + var content = $"{(args.UpdateValue == "check" ? "Check" : "Uncheck")} checkbox of '{args.ElementText}'"; message.Content = result ? - $"{(args.UpdateValue == "check" ? "Checked" : "Unchecked")} checkbox of '{args.ElementText}' successfully" : - "Failed"; + $"{content} successfully" : + $"{content} failed"; var webDriverService = _services.GetRequiredService(); var path = webDriverService.GetScreenshotFilePath(message.MessageId); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ChangeListValueFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ChangeListValueFn.cs index b7cbe410..94eb4522 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ChangeListValueFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ChangeListValueFn.cs @@ -22,9 +22,10 @@ public class ChangeListValueFn : IFunctionCallback var agent = await agentService.LoadAgent(message.CurrentAgentId); var result = await _browser.ChangeListValue(new BrowserActionParams(agent, args, message.MessageId)); + var content = $"Change value to '{args.UpdateValue}' for {args.ElementName}"; message.Content = result ? - $"Changed value to '{args.UpdateValue}' for {args.ElementName} successfully" : - "Failed"; + $"{content} successfully" : + $"{content} failed"; var webDriverService = _services.GetRequiredService(); var path = webDriverService.GetScreenshotFilePath(message.MessageId); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/CheckRadioButtonFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/CheckRadioButtonFn.cs index e03de004..422d90af 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/CheckRadioButtonFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/CheckRadioButtonFn.cs @@ -22,9 +22,10 @@ public class CheckRadioButtonFn : IFunctionCallback var agent = await agentService.LoadAgent(message.CurrentAgentId); var result = await _browser.CheckRadioButton(new BrowserActionParams(agent, args, message.MessageId)); - message.Content = result ? - $"Checked value of '{args.UpdateValue}' for radio button '{args.ElementName}' successfully" : - "Failed"; + var content = $"Check value of '{args.UpdateValue}' for radio button '{args.ElementName}'"; + message.Content = result ? + $"{content} successfully" : + $"{content} failed"; var webDriverService = _services.GetRequiredService(); var path = webDriverService.GetScreenshotFilePath(message.MessageId); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ClickButtonFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ClickButtonFn.cs index 2b7e5fae..f9b5ba98 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ClickButtonFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ClickButtonFn.cs @@ -22,9 +22,10 @@ public class ClickButtonFn : IFunctionCallback var agent = await agentService.LoadAgent(message.CurrentAgentId); var result = await _browser.ClickButton(new BrowserActionParams(agent, args, message.MessageId)); + var content = $"Click button of '{args.ElementName}'"; message.Content = result ? - $"Clicked button of '{args.ElementName}' successfully" : - "Failed"; + $"{content} successfully" : + $"{content} failed"; var webDriverService = _services.GetRequiredService(); var path = webDriverService.GetScreenshotFilePath(message.MessageId); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ClickElementFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ClickElementFn.cs index a5223fc2..6bc95403 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ClickElementFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ClickElementFn.cs @@ -22,9 +22,10 @@ public class ClickElementFn : IFunctionCallback var agent = await agentService.LoadAgent(message.CurrentAgentId); var result = await _browser.ClickElement(new BrowserActionParams(agent, args, message.MessageId)); + var content = $"Click element {args.MatchRule} text '{args.ElementText}'"; message.Content = result ? - $"Clicked element {args.MatchRule} text '{args.ElementText}' successfully" : - "Failed"; + $"{content} successfully" : + $"{content} failed"; var webDriverService = _services.GetRequiredService(); var path = webDriverService.GetScreenshotFilePath(message.MessageId); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserPasswordFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserPasswordFn.cs index 3c84e9b3..0a9f6779 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserPasswordFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserPasswordFn.cs @@ -22,7 +22,7 @@ public class InputUserPasswordFn : IFunctionCallback var agent = await agentService.LoadAgent(message.CurrentAgentId); var result = await _browser.InputUserPassword(new BrowserActionParams(agent, args, message.MessageId)); - message.Content = result ? "Input password successfully" : "Failed"; + message.Content = result ? "Input password successfully" : "Input password failed"; var webDriverService = _services.GetRequiredService(); var path = webDriverService.GetScreenshotFilePath(message.MessageId); diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserTextFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserTextFn.cs index df357778..0ab14505 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserTextFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/InputUserTextFn.cs @@ -29,8 +29,8 @@ public class InputUserTextFn : IFunctionCallback } message.Content = result ? - content + " successfully" : - "Failed"; + content + " successfully" : + content + " failed"; var webDriverService = _services.GetRequiredService(); var path = webDriverService.GetScreenshotFilePath(message.MessageId);