HybridBrowserToolkit

class HybridBrowserToolkit(BaseToolkit, RegisteredAgentToolkit):
A hybrid browser toolkit that combines non-visual, DOM-based browser automation with visual, screenshot-based capabilities. This toolkit now uses TypeScript implementation with Playwright’s _snapshotForAI functionality for enhanced AI integration.

init

def __init__(self):
Initialize the HybridBrowserToolkit. Parameters:
  • headless (bool): Whether to run browser in headless mode. Defaults to True.
  • user_data_dir (Optional[str]): Directory for user data persistence. Defaults to None.
  • stealth (bool): Whether to enable stealth mode. Defaults to False.
  • web_agent_model (Optional[BaseModelBackend]): Model for web agent operations. Defaults to None.
  • cache_dir (str): Directory for caching. Defaults to “tmp/”. (default: "tmp/")
  • enabled_tools (Optional[List[str]]): List of enabled tools. Defaults to None.
  • browser_log_to_file (bool): Whether to log browser actions to file. Defaults to False.
  • session_id (Optional[str]): Session identifier. Defaults to None.
  • default_start_url (str): Default URL to start with. Defaults to “https://google.com/”.
  • default_timeout (Optional[int]): Default timeout in milliseconds. Defaults to None.
  • short_timeout (Optional[int]): Short timeout in milliseconds. Defaults to None.
  • navigation_timeout (Optional[int]): Navigation timeout in milliseconds. Defaults to None.
  • network_idle_timeout (Optional[int]): Network idle timeout in milliseconds. Defaults to None.
  • screenshot_timeout (Optional[int]): Screenshot timeout in milliseconds. Defaults to None.
  • page_stability_timeout (Optional[int]): Page stability timeout in milliseconds. Defaults to None.
  • dom_content_loaded_timeout (Optional[int]): DOM content loaded timeout in milliseconds. Defaults to None.
  • viewport_limit (bool): Whether to filter page snapshot elements to only those visible in the current viewport. When True, only elements within the current viewport bounds will be included in snapshots. When False (default), all elements on the page are included. Defaults to False.

del

def __del__(self):
Cleanup browser resources on garbage collection.

web_agent_model

def web_agent_model(self):
Get the web agent model.

web_agent_model

def web_agent_model(self, value: Optional[BaseModelBackend]):
Set the web agent model.

cache_dir

def cache_dir(self):
Get the cache directory.

clone_for_new_session

def clone_for_new_session(self, new_session_id: Optional[str] = None):
Create a new instance of HybridBrowserToolkit with a unique session. Parameters:
  • new_session_id: Optional new session ID. If None, a UUID will be generated.
Returns: A new HybridBrowserToolkit instance with the same configuration but a different session.

get_tools

def get_tools(self):
Get available function tools based on enabled_tools configuration.