Update click.py to pass errors back to Agent (#4723)

Instead of halting the entire program if this tool encounters an error,
it should pass the error back to the agent to decide what to do.

This may be best suited for @vowelparrot to review.
dynamic_agent_tools
d 3 n 7 1 year ago committed by GitHub
parent 3c490b5ba3
commit 435b70da47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,8 +36,11 @@ class ClickTool(BaseBrowserTool):
raise ValueError(f"Synchronous browser not provided to {self.name}")
page = get_current_page(self.sync_browser)
# Navigate to the desired webpage before using this tool
page.click(selector)
return f"Clicked element '{selector}'"
try:
page.click(selector)
return f"Clicked element '{selector}'"
except Exception as e:
return f"Error '{e}'"
async def _arun(
self,
@ -49,5 +52,8 @@ class ClickTool(BaseBrowserTool):
raise ValueError(f"Asynchronous browser not provided to {self.name}")
page = await aget_current_page(self.async_browser)
# Navigate to the desired webpage before using this tool
await page.click(selector)
return f"Clicked element '{selector}'"
try:
await page.click(selector)
return f"Clicked element '{selector}'"
except Exception as e:
return f"Error '{e}'"

Loading…
Cancel
Save