Skip to content

API Reference parrot_tools.business_automation.toolkit

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

parrot_tools.business_automation.toolkit

View source

BusinessAutomationToolkit — the generic, domain-neutral automation engine.

FEAT-453, Module 5 (Goals G4, G5). Knows about "run a named business operation with these parameters, pausing for human confirmation before anything with legal effect" — nothing about any specific site. Contains zero site-specific identifiers (no vendor/product names anywhere in this package); site-specific plans live in an external, private plans directory (Module 6, TASK-2391) loaded at runtime.

Gating follows Decision D2: reuse the shipped HITL stack (:class:~parrot.auth.confirmation.ConfirmationGuard) rather than a bespoke gate. run_operation manually invokes the guard for OperationKind.SUBMIT operations before the browser is ever opened — DRAFT/READ operations never touch the guard at all.

Class BusinessAutomationToolkit

Generic engine for named, parameterized business operations.

Holds a :class:~parrot_tools.scraping.FlowExecutor, an operation registry, and a submit-gate policy backed by the shared HITL stack (Decision D2). auto_open = True opens the browser lazily on first use (FEAT-391), exactly as :class:~parrot.tools.obsidian.ObsidianToolkit does for the vault.

The operation/flow/template registries are populated either directly via the operations/flows/templates constructor kwargs (used by this task's own tests) or — once TASK-2391 lands — by a TemplatePlanStore that scans plans_dir. This task wires the seam (plans_dir is accepted and stored) but does not implement the directory scan itself; that is explicitly TASK-2391's responsibility.

Parameter Type Default Description
plans_dir Union[str, Path] External, private plans directory (Module 6). When none of the operations/flows/templates override kwargs are given, this directory is loaded via :class:~parrot_tools.business_automation.store.PlanDirectoryStore at construction time (TASK-2391) — a malformed directory (or a missing one) raises loudly, matching that store's own "never silently reject one bad file" contract, rather than booting an agent with a silently-empty operation registry.
browser Any None Live browser handle forwarded to :class:FlowExecutor.
credential_broker Optional[CredentialBroker] None Optional :class:CredentialBroker for broker-backed Authenticate steps (Module 4). When set, adapted via :func:_credential_resolver_from_broker and forwarded to :class:FlowExecutor (code-review remediation, AC-5) — without this, a credential_provider-backed Authenticate was previously unreachable from :meth:run_operation, always failing closed regardless of whether a broker was configured.
human_manager Optional[HumanInteractionManager] None Optional :class:HumanInteractionManager. None means every OperationKind.SUBMIT operation fails closed (Decision D2) — this is the safe default for a financial write, not an oversight.
checkpoint_dir Optional[Path] None Directory for :class:FlowExecutor checkpoints.
credential_user_id str 'gestoria' Canonical identity used when resolving credentials through credential_broker (see :func:_credential_resolver_from_broker). This engine is a single-operator financial agent, not a multi-tenant surface, so a fixed default ("gestoria", matching this feature's own naming convention — Module 10) is deliberate.
human_channel Optional['HumanChannel'] None Optional :class:HumanChannel forwarded to :class:FlowExecutor for mid-plan await_human steps (code-review remediation). Deliberately a separate parameter from human_manager rather than reusing one of human_manager.channels — TASK-2385 flagged that sharing a channel instance with a HumanInteractionManager risks exec_await_human's register_response_handler() call colliding with the manager's own registration on that same channel. Configure a dedicated channel instance here instead.
**kwargs Any {} Forwarded to :class:AbstractToolkit. operations, flows, and templates (mappings keyed by name) are popped here to seed the registries directly instead of scanning plans_dir — the interim seam this task's own tests (and TASK-2395/2396/2397's) still use for unit-level fixtures.

Method BusinessAutomationToolkit.list_operations

List every registered business operation.

list_operations() -> Dict[str, Any]

Returns: Dict[str, Any] — {"operations": [{"name", "kind", "description"}, ...]}.

Method BusinessAutomationToolkit.describe_operation

Describe one operation's parameters and confirmation policy.

describe_operation(name: str) -> Dict[str, Any]

Parameter Type Default Description
name str The operation name (see :meth:list_operations).

Returns: Dict[str, Any] — A dict with name, description, kind, and params, or {"status": "error", ...} if name is unknown.

Method BusinessAutomationToolkit.run_operation

Run a named business operation with these parameters.

OperationKind.SUBMIT operations pause for human confirmation (Decision D2) before the browser is opened — a denial never opens a browser. DRAFT/READ operations never touch the confirmation guard at all. The plan is validated (:meth:~parrot_tools.scraping.plan.ScrapingPlan.validate_steps) before any driver is constructed (Module 3, Goal G2). Long-running execution happens in the background — this returns a run_id immediately so a chat turn is never held open.

run_operation(name: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]

Parameter Type Default Description
name str The operation to run (see :meth:list_operations).
params Optional[Dict[str, Any]] None Parameters bound into the operation's flow templates.

Returns: Dict[str, Any] — {"status": "started", "run_id": ..., "operation": ...} on success, or an error/denial dict ("error", "cancelled", "timeout") otherwise.

Method BusinessAutomationToolkit.resume_operation

Resume a previously started (and interrupted) operation run.

resume_operation(run_id: str, resume_from: Optional[str] = None) -> Dict[str, Any]

Parameter Type Default Description
run_id str A run_id returned by a prior :meth:run_operation call.
resume_from Optional[str] None The flow node id to resume from (forwarded to :meth:FlowExecutor.run's resume_from). None lets the executor's own checkpoint discover where to continue.

Returns: Dict[str, Any] — {"status": "started", "run_id": ..., "resumed": True} on success, or an error dict if run_id or its operation cannot be resolved.

Alias BusinessOperation

Re-exported from parrot_tools.business_automation.models.BusinessOperation.

Alias CredentialResolverFn

Re-exported from parrot_tools.scraping.session_actions.CredentialResolverFn.

Alias FlowExecutor

Re-exported from parrot_tools.scraping.FlowExecutor.

Alias OperationKind

Re-exported from parrot_tools.business_automation.models.OperationKind.

Alias PlanDirectoryStore

Re-exported from parrot_tools.business_automation.store.PlanDirectoryStore.

Alias ScrapingFlow

Re-exported from parrot_tools.scraping.ScrapingFlow.

Alias TemplatePlan

Re-exported from parrot_tools.scraping.TemplatePlan.

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