Skip to content

API Reference parrot_tools.browsing.toolkit

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.browsing.toolkit

View source

WebBrowsingToolkit — catalogued, deterministic web navigation for agents.

Extends :class:~parrot_tools.scraping.toolkit.WebScrapingToolkit with a per-site action catalog: named scripts ("guiones") written in the same BrowserAction DSL, stored on disk (one folder per site, one JSON file per action). An agent resolves a natural-language request ("inicia sesión en Hooba") to a catalogued site + action and replays it deterministically — optionally composing several actions (login -> dashboard -> CRM -> ...) into one sequence over a single persistent browser session.

Key traits:

  • Driver fixed at construction: Selenium or Playwright is chosen when the toolkit is instantiated and never switched on the fly.
  • Persistent session: one browser/driver instance serves every run_* call until :meth:close_browser (or stop()) is called, so a register-customer-then-invoice flow shares its login.
  • Chrome profile access: pass user_data_dir (and optionally profile_directory / browser_channel) to run against a real Google Chrome user profile — session cookies, saved logins, keyring.
  • Bounded loops only: every loop step is capped by max_loop_iterations at save time (strict) and clamped again at run time (defense in depth).

Alias AbstractDriver

Re-exported from parrot_tools.scraping.drivers.abstract.AbstractDriver.

Alias ActionCatalog

Re-exported from parrot_tools.browsing.catalog.ActionCatalog.

Alias ActionParam

Re-exported from parrot_tools.browsing.models.ActionParam.

Alias ActionRunSummary

Re-exported from parrot_tools.browsing.models.ActionRunSummary.

Alias ComposedRef

Re-exported from parrot_tools.browsing.models.ComposedRef.

Attribute DEFAULT_MAX_LOOP_ITERATIONS

Alias ResolvedAction

Re-exported from parrot_tools.browsing.composer.ResolvedAction.

Alias ScrapingResult

Re-exported from parrot_tools.scraping.models.ScrapingResult.

Alias SequenceRunResult

Re-exported from parrot_tools.browsing.models.SequenceRunResult.

Alias SiteAction

Re-exported from parrot_tools.browsing.models.SiteAction.

Alias SiteInfo

Re-exported from parrot_tools.browsing.models.SiteInfo.

Class WebBrowsingToolkit

Toolkit for catalogued, deterministic site automation.

Every public async method is auto-exposed as an agent tool by AbstractToolkit. On top of the inherited scraping tools (scrape, crawl, plan_*), this toolkit adds catalog management (register_site, save_site_action, ...) and deterministic execution (run_site_action, run_site_sequence).

Parameter Type Default Description
catalog_dir Union[str, Path] 'browsing_catalog' Root directory of the action catalog (one folder per site, one JSON file per action).
user_data_dir Optional[Union[str, Path]] None Path to a Google Chrome user-data directory. When set, the browser launches against that profile, giving the agent access to its session cookies, saved logins and passwords. Use a dedicated profile copy for automation when possible — Chrome locks a profile directory that is already open.
profile_directory Optional[str] None Chrome profile folder inside user_data_dir (e.g. "Default", "Profile 1").
browser_channel Optional[str] None Playwright browser channel (e.g. "chrome", "msedge") so a real installed Chrome — not bundled Chromium — opens the profile. Ignored by Selenium.
max_loop_iterations int DEFAULT_MAX_LOOP_ITERATIONS Hard cap applied to every loop step of a catalogued script.
credential_resolver Optional[Any] None Optional async resolver forwarded to authenticate steps using credential_provider (broker based credentials — never literal passwords in scripts).
human_channel Optional[Any] None Optional HumanChannel for await_human steps (e.g. MFA challenges mid-script).
session_based bool True Reuse a single browser session across every run (default True here, unlike the scraping parent). Note: catalogued runs (run_site_action / run_site_sequence) ALWAYS use session mode regardless of this flag — the persistent session is the point of the toolkit — so this only influences the inherited scrape/crawl behaviour before the first catalogued run.
headless bool False Run headless. Defaults to False — catalogued flows typically operate real, logged-in user sessions.
confirm_runs bool True Mark run_site_action / run_site_sequence with requires_confirmation routing metadata (HITL confirmation where the surface supports it). Default True: these tools act on a real, possibly authenticated browser session (form submissions, account changes), which is a larger blast radius than any catalog edit. Set to False only for trusted, fully-automated pipelines.
**kwargs Any {} Everything WebScrapingToolkit accepts (driver_type, browser, plans_dir, llm_client, timeouts, ...). The driver backend is fixed at construction.

Attributes:

Attribute Type Description
confirming_tools frozenset

Method WebBrowsingToolkit.close_browser

Close the persistent browser session.

The next run_site_action / run_site_sequence call starts a fresh browser (fresh session, unless a Chrome profile keeps cookies on disk).

close_browser() -> Dict[str, Any]

Returns: Dict[str, Any] — Dict with closed and recording_path (str or None). The recording is finalized on close when record_video=True.

Method WebBrowsingToolkit.register_site

Register (or update) a site in the browsing catalog.

register_site(base_url: str, name: Optional[str] = None, title: str = '', description: str = '', aliases: Optional[List[str]] = None) -> Dict[str, Any]

Parameter Type Default Description
base_url str Root URL of the site (e.g. https://hooba.es).
name Optional[str] None Optional explicit slug; derived from the domain when omitted.
title str '' Human-friendly site name ("Hooba").
description str '' What the site is, to aid natural-language matching.
aliases Optional[List[str]] None Alternative names users may employ ("hooba").

Returns: Dict[str, Any] — The stored site metadata as a dict.

Method WebBrowsingToolkit.list_sites

List every site registered in the browsing catalog.

list_sites() -> List[Dict[str, Any]]

Returns: List[Dict[str, Any]] — One dict per site: slug, base URL, title, description and aliases — enough for the agent to resolve user references.

Method WebBrowsingToolkit.list_site_actions

List the catalogued actions available for a site.

Use this to match a natural-language request against the site's capabilities: each entry carries the action's name, kind (navigation / operation / composite), description, declared parameters and prerequisites.

list_site_actions(site: str) -> List[Dict[str, Any]]

Parameter Type Default Description
site str Site reference — slug, alias, domain or title (e.g. "hooba").

Returns: List[Dict[str, Any]] — Compact summaries of every catalogued action.

Method WebBrowsingToolkit.get_site_action

Fetch a catalogued action's full script.

get_site_action(site: str, action: str) -> Dict[str, Any]

Parameter Type Default Description
site str Site reference (slug, alias, domain or title).
action str Action name.

Returns: Dict[str, Any] — The complete stored script, DSL steps included.

Method WebBrowsingToolkit.save_site_action

Validate and store an action script in the site's catalog.

The script is checked before anything is written: steps must be valid BrowserAction DSL, every {{placeholder}} must be a declared parameter, and every loop must be bounded by max_loop_iterations.

save_site_action(site: str, name: str, description: str, steps: Optional[List[Dict[str, Any]]] = None, kind: str = 'operation', params: Optional[Dict[str, Dict[str, Any]]] = None, compose: Optional[List[Dict[str, Any]]] = None, requires: Optional[List[str]] = None, title: str = '', tags: Optional[List[str]] = None, version: str = '1.0', source: str = 'llm', overwrite: bool = False) -> Dict[str, Any]

Parameter Type Default Description
site str Site reference (must already be registered).
name str Action name (slugified; unique within the site).
description str Natural-language description — what the action does and when to use it.
steps Optional[List[Dict[str, Any]]] None BrowserAction DSL steps (required unless kind='composite').
kind str 'operation' navigation, operation or composite.
params Optional[Dict[str, Dict[str, Any]]] None Declared parameters: {name: {description, required, default, example}}.
compose Optional[List[Dict[str, Any]]] None For composites — ordered references [{action, params}] to sibling actions.
requires Optional[List[str]] None Prerequisite action names (e.g. ["login"]).
title str '' Human-friendly action title.
tags Optional[List[str]] None Categorization tags.
version str '1.0' Script version string.
source str 'llm' Origin marker (user, llm, recorded).
overwrite bool False Replace an existing action of the same name.

Returns: Dict[str, Any] — Dict with saved, the storage path and the action summary.

Method WebBrowsingToolkit.delete_site_action

Delete a catalogued action from a site.

delete_site_action(site: str, action: str) -> Dict[str, Any]

Parameter Type Default Description
site str Site reference.
action str Action name.

Returns: Dict[str, Any] — Dict with deleted indicating whether the file existed.

Method WebBrowsingToolkit.run_site_action

Deterministically execute one catalogued action on a site.

Prerequisites (requires, e.g. login) are injected automatically and composite actions are expanded, so a single call can drive a full flow. Everything runs on the toolkit's persistent browser session.

run_site_action(site: str, action: str, params: Optional[Dict[str, Any]] = None, include_requires: bool = True, stop_on_error: bool = True) -> Dict[str, Any]

Parameter Type Default Description
site str Site reference — slug, alias, domain or title (e.g. "hooba").
action str Action name from the site's catalog.
params Optional[Dict[str, Any]] None Values for the action's declared parameters.
include_requires bool True Auto-run prerequisite actions first.
stop_on_error bool True Abort the remaining sequence when an action fails.

Returns: Dict[str, Any] — class:SequenceRunResult as a dict: per-action outcomes plus merged extracted data.

Method WebBrowsingToolkit.run_site_sequence

Execute an ordered plan of catalogued actions on one session.

Use this to fulfil multi-step requests ("login, luego ir al Dashboard, luego crear el draft de factura"): build the plan from the site's catalog and run it — prerequisites are deduplicated across the whole plan, so login runs at most once.

run_site_sequence(site: str, plan: List[Union[str, Dict[str, Any]]], params: Optional[Dict[str, Any]] = None, include_requires: bool = True, stop_on_error: bool = True) -> Dict[str, Any]

Parameter Type Default Description
site str Site reference (slug, alias, domain or title).
plan List[Union[str, Dict[str, Any]]] Ordered entries — an action name, or {"action": name, "params": {...}}.
params Optional[Dict[str, Any]] None Shared parameter values applied to every entry (entry-level params win).
include_requires bool True Auto-run prerequisite actions.
stop_on_error bool True Abort remaining actions when one fails.

Returns: Dict[str, Any] — class:SequenceRunResult as a dict.

Method WebBrowsingToolkit.execute_web_task

Execute one structured browsing request against the catalog.

This is the single deterministic entry point for agentic flows: the LLM turns natural language ("register a customer at hooba") into a structured request and the toolkit resolves the site's catalog, loads the named script(s) and replays them with the provided data — no improvised navigation.

Request shape (:class:~parrot_tools.browsing.models.WebTaskRequest)::

{"site": "hooba",
 "action": "register-customer",
 "data": {"name": "ACME", "vat": "B123..."}}

or, for a multi-step flow::

{"site": "hooba",
 "plan": [{"action": "goto-crm"},
          {"action": "register-customer", "data": {...}}],
 "data": {...shared values...}}

Every failure returns a structured, repairable error instead of raising: an unknown site lists the known sites, an unknown action lists the site's catalog, and missing parameters include each requested action's declared parameter spec — so the calling LLM can correct its request deterministically.

execute_web_task(request: Dict[str, Any]) -> Dict[str, Any]

Parameter Type Default Description
request Dict[str, Any] The structured request (validated against WebTaskRequest).

Returns: Dict[str, Any] — {"status": "ok", "result": {...SequenceRunResult...}} on success; {"status": "error", "error": {"code", "message", ...hints}} otherwise.

Alias WebScrapingToolkit

Re-exported from parrot_tools.scraping.toolkit.WebScrapingToolkit.

Alias WebTaskRequest

Re-exported from parrot_tools.browsing.models.WebTaskRequest.

Alias collect_placeholders

Re-exported from parrot_tools.browsing.templating.collect_placeholders.

Alias collect_value_placeholders

Re-exported from parrot_tools.browsing.templating.collect_value_placeholders.

Alias execute_plan_steps

Re-exported from parrot_tools.scraping.executor.execute_plan_steps.

Alias expand_sequence

Re-exported from parrot_tools.browsing.composer.expand_sequence.

Alias find_literal_credentials

Re-exported from parrot_tools.browsing.templating.find_literal_credentials.

Attribute logger

Alias render_steps

Re-exported from parrot_tools.browsing.templating.render_steps.

Alias validate_loop_bounds

Re-exported from parrot_tools.browsing.templating.validate_loop_bounds.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally