Skip to content

API Reference parrot_tools.computer.agent

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

parrot_tools.computer.agent

View source

ComputerAgent — Agent subclass for vision-based browser automation (FEAT-227).

Configured for Google Gemini computer-use models. Composes ComputerInteractionToolkit + optional WebScrapingToolkit. Manages screenshot memory pruning and safety decision handling.

Class ComputerAgent

Agent configured for vision-based browser automation via computer-use.

Uses a Google Gemini computer-use model (default: gemini-3.8-flash). Composes :class:ComputerInteractionToolkit for all 13 predefined browser actions plus screenshot, recording, and loop execution. Optionally composes :class:~parrot_tools.scraping.toolkit.WebScrapingToolkit for hybrid selector-based extraction workflows.

Features:

  • Lazy browser start via _pre_execute in the toolkit.
  • Screenshot memory pruning: conversation history is pruned to keep only the last max_screenshot_turns turns that contain screenshots.
  • Safety mode (the model can flag an action with safety_decision.decision == "require_confirmation"): "auto" — log and auto-acknowledge safety decisions. "interactive" — emit an event; use safety_callback if provided, otherwise fall back to a terminal y/n prompt. "hitl" — route the confirmation through a :class:~parrot.human.manager.HumanInteractionManager (an APPROVAL interaction on safety_channel), falling back to a terminal prompt when no manager is available. Approved actions are acknowledged back to Gemini with safety_acknowledgement="true"; rejected actions are skipped.
Parameter Type Default Description
model str 'gemini-3.8-flash' Gemini computer-use model identifier.
viewport tuple[int, int] (1280, 720) Browser viewport as (width, height) in pixels.
headless bool True Whether to run the browser in headless mode.
initial_url str 'https://www.google.com' URL to open when the browser first starts.
safety_mode Literal['auto', 'interactive', 'hitl'] 'auto' "auto", "interactive", or "hitl".
max_screenshot_turns int 3 Number of turns whose screenshots to retain in the conversation history.
include_scraping bool False If True, include WebScrapingToolkit tools.
safety_callback Optional[Callable[..., Any]] None Optional callable consulted in "interactive" mode.
human_manager Optional[Any] None Optional :class:HumanInteractionManager used in "hitl" mode (defaults to the process-wide manager).
safety_channel str 'cli' HITL channel name for "hitl" mode (default "cli" — prompts in the terminal).
safety_approvers Optional[List[str]] None Respondent ids for the HITL APPROVAL interaction.
safety_timeout float 300.0 Seconds to wait for the human decision.
**kwargs Any {} Forwarded to Agent.

Attributes:

Attribute Type Description
agent_id str

Method ComputerAgent.configure

Configure the agent and wire the computer-use safety handler.

After the base configuration resolves the Google client, registers :meth:_safety_handler on it so flagged safety_decision actions are routed back here for auto / interactive / HITL confirmation.

configure(app: Any = None) -> None

Parameter Type Default Description
app Any None

Method ComputerAgent.agent_tools

Return the tools available to the ComputerAgent.

Always includes all tools from ComputerInteractionToolkit. When include_scraping=True, also adds the cached :class:~parrot_tools.scraping.toolkit.WebScrapingToolkit tools for hybrid selector-based extraction.

agent_tools() -> List[AbstractTool]

Returns: List[AbstractTool] — List of AbstractTool instances.

Method ComputerAgent.prune_screenshots

Remove old screenshots from conversation history.

Walks history backwards, keeps screenshots in the last max_screenshot_turns turns, strips screenshot data from older turns to prevent context-window bloat (~100-500KB per PNG).

prune_screenshots(history: list) -> list

Parameter Type Default Description
history list List of conversation turn dicts (arbitrary structure).

Returns: list — Pruned history list.

Method ComputerAgent.handle_safety_decision

Process a safety decision from the model.

In "auto" mode, logs the decision and returns True (proceed).

In "interactive" mode, emits a "safety_decision" event and then invokes self._safety_callback(decision) if one was provided at construction time — returning its boolean result. When no callback is set, defaults to True and logs a warning. Pass safety_callback= to the constructor to get real abort behaviour in interactive mode.

handle_safety_decision(decision: dict) -> bool

Parameter Type Default Description
decision dict A dict describing the safety decision from the model.

Returns: bool — True to proceed, False to abort. "auto" mode always returns True. "interactive" mode returns the callback's result, or True when no callback is configured.

Alias ComputerInteractionToolkit

Re-exported from parrot_tools.computer.toolkit.ComputerInteractionToolkit.

Attribute logger

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