<tools>
  <tool name="browser_action">
    <description>Perform browser actions using a Playwright-controlled browser with multiple tabs.
  The browser is PERSISTENT and remains active until explicitly closed, allowing for
  multi-step workflows and long-running processes across multiple tabs.</description>
    <parameters>
      <parameter name="action" type="string" required="true">
      </parameter>
      <parameter name="url" type="string" required="false">
        <description>Required for 'launch', 'goto', and optionally for 'new_tab' actions. The URL to launch the browser at, navigate to, or load in new tab. Must include appropriate protocol (e.g., http://, https://, file://).</description>
      </parameter>
      <parameter name="coordinate" type="string" required="false">
        <description>Required for 'click', 'double_click', and 'hover' actions. Format: "x,y" (e.g., "432,321"). Coordinates should target the center of elements (buttons, links, etc.). Must be within the browser viewport resolution. Be very careful to calculate the coordinates correctly based on the previous screenshot.</description>
      </parameter>
      <parameter name="text" type="string" required="false">
        <description>Required for 'type' action. The text to type in the field.</description>
      </parameter>
      <parameter name="tab_id" type="string" required="false">
        <description>Required for 'switch_tab' and 'close_tab' actions. Optional for other actions to specify which tab to operate on. The ID of the tab to operate on. The first tab created during 'launch' has ID "tab_1". If not provided, actions will operate on the currently active tab.</description>
      </parameter>
      <parameter name="js_code" type="string" required="false">
        <description>Required for 'execute_js' action. JavaScript code to execute in the page context. The code runs in the context of the current page and has access to the DOM and all page-defined variables and functions. The last evaluated expression's value is returned in the response.</description>
      </parameter>
      <parameter name="duration" type="string" required="false">
        <description>Required for 'wait' action. Number of seconds to pause execution. Can be fractional (e.g., 0.5 for half a second).</description>
      </parameter>
      <parameter name="key" type="string" required="false">
        <description>Required for 'press_key' action. The key to press. Valid values include: - Single characters: 'a'-'z', 'A'-'Z', '0'-'9' - Special keys: 'Enter', 'Escape', 'ArrowLeft', 'ArrowRight', etc. - Modifier keys: 'Shift', 'Control', 'Alt', 'Meta' - Function keys: 'F1'-'F12'</description>
      </parameter>
      <parameter name="file_path" type="string" required="false">
        <description>Required for 'save_pdf' action. The file path where to save the PDF.</description>
      </parameter>
      <parameter name="clear" type="boolean" required="false">
        <description>For 'get_console_logs' action: whether to clear console logs after retrieving them. Default is False (keep logs).</description>
      </parameter>
    </parameters>
    <returns type="Dict[str, Any]">
      <description>Response containing: - screenshot: Base64 encoded PNG of the current page state - url: Current page URL - title: Current page title - viewport: Current browser viewport dimensions - tab_id: ID of the current active tab - all_tabs: Dict of all open tab IDs and their URLs - message: Status message about the action performed - js_result: Result of JavaScript execution (for execute_js action) - pdf_saved: File path of saved PDF (for save_pdf action) - console_logs: Array of console messages (for get_console_logs action)   Limited to 50KB total and 200 most recent logs. Individual messages truncated at 1KB. - page_source: HTML source code (for view_source action)   Large pages are truncated to 100KB (keeping beginning and end sections).</description>
    </returns>
    <notes>
  Important usage rules:
  1. PERSISTENCE: The browser remains active and maintains its state until
     explicitly closed with the 'close' action. This allows for multi-step workflows
     across multiple tool calls and tabs.
  2. Browser interaction MUST start with 'launch' and end with 'close'.
  3. Only one action can be performed per call.
  4. To visit a new URL not reachable from current page, either:
     - Use 'goto' action
     - Open a new tab with the URL
     - Close browser and relaunch
  5. Click coordinates must be derived from the most recent screenshot.
  6. You MUST click on the center of the element, not the edge. You MUST calculate
     the coordinates correctly based on the previous screenshot, otherwise the click
     will fail. After clicking, check the new screenshot to verify the click was
     successful.
  7. Tab management:
     - First tab from 'launch' is "tab_1"
     - New tabs are numbered sequentially ("tab_2", "tab_3", etc.)
     - Must have at least one tab open at all times
     - Actions affect the currently active tab unless tab_id is specified
  8. JavaScript execution (following Playwright evaluation patterns):
     - Code runs in the browser page context, not the tool context
     - Has access to DOM (document, window, etc.) and page variables/functions
     - The LAST EVALUATED EXPRESSION is automatically returned - no return statement needed
     - For simple values: document.title (returns the title)
     - For objects: {title: document.title, url: location.href} (returns the object)
     - For async operations: Use await and the promise result will be returned
     - AVOID explicit return statements - they can break evaluation
     - object literals must be wrapped in paranthesis when they are the final expression
     - Variables from tool context are NOT available - pass data as parameters if needed
     - Examples of correct patterns:
       * Single value: document.querySelectorAll('img').length
       * Object result: {images: document.images.length, links: document.links.length}
       * Async operation: await fetch(location.href).then(r => r.status)
       * DOM manipulation: document.body.style.backgroundColor = 'red'; 'background changed'

  9. Wait action:
     - Time is specified in seconds
     - Can be used to wait for page loads, animations, etc.
     - Can be fractional (e.g., 0.5 seconds)
     - Screenshot is captured after the wait
  10. The browser can operate concurrently with other tools. You may invoke
      terminal, python, or other tools (in separate assistant messages) while maintaining
      the active browser session, enabling sophisticated multi-tool workflows.
  11. Keyboard actions:
      - Use press_key for individual key presses
      - Use type for typing regular text
      - Some keys have special names based on Playwright's key documentation
  12. All code in the js_code parameter is executed as-is - there's no need to
      escape special characters or worry about formatting. Just write your JavaScript
      code normally. It can be single line or multi-line.
  13. For form filling, click on the field first, then use 'type' to enter text.
  14. The browser runs in headless mode using Chrome engine for security and performance.
  15. RESOURCE MANAGEMENT:
      - ALWAYS close tabs you no longer need using 'close_tab' action.
      - ALWAYS close the browser with 'close' action when you have completely finished
        all browser-related tasks. Do not leave the browser running if you're done with it.
      - If you opened multiple tabs, close them as soon as you've extracted the needed
        information from each one.
    </notes>
    <examples>
  # Launch browser at URL (creates tab_1)
  <function=browser_action>
  <parameter=action>launch</parameter>
  <parameter=url>https://example.com</parameter>
  </function>

  # Navigate to different URL
  <function=browser_action>
  <parameter=action>goto</parameter>
  <parameter=url>https://github.com</parameter>
  </function>

  # Open new tab with different URL
  <function=browser_action>
  <parameter=action>new_tab</parameter>
  <parameter=url>https://another-site.com</parameter>
  </function>

  # Wait for page load
  <function=browser_action>
  <parameter=action>wait</parameter>
  <parameter=duration>2.5</parameter>
  </function>

  # Click login button at coordinates from screenshot
  <function=browser_action>
  <parameter=action>click</parameter>
  <parameter=coordinate>450,300</parameter>
  </function>

  # Click username field and type
  <function=browser_action>
  <parameter=action>click</parameter>
  <parameter=coordinate>400,200</parameter>
  </function>

  <function=browser_action>
  <parameter=action>type</parameter>
  <parameter=text>user@example.com</parameter>
  </function>

  # Click password field and type
  <function=browser_action>
  <parameter=action>click</parameter>
  <parameter=coordinate>400,250</parameter>
  </function>

  <function=browser_action>
  <parameter=action>type</parameter>
  <parameter=text>mypassword123</parameter>
  </function>

  # Press Enter key
  <function=browser_action>
  <parameter=action>press_key</parameter>
  <parameter=key>Enter</parameter>
  </function>

  # Execute JavaScript to get page stats (correct pattern - no return statement)
  <function=browser_action>
  <parameter=action>execute_js</parameter>
  <parameter=js_code>const images = document.querySelectorAll('img');
const links = document.querySelectorAll('a');
{
    images: images.length,
    links: links.length,
    title: document.title
}</parameter>
  </function>

  # Scroll down
  <function=browser_action>
  <parameter=action>scroll_down</parameter>
  </function>

  # Get console logs
  <function=browser_action>
  <parameter=action>get_console_logs</parameter>
  </function>

  # View page source
  <function=browser_action>
  <parameter=action>view_source</parameter>
  </function>
    </examples>
  </tool>
</tools>
