# Computer-Use Capability Engine A small computer-use automation system that uses an LLM to discover a UI workflow and represents the learned workflow as a typed, versioned capability that can later be replayed deterministically without an LLM. The project uses a synthetic legacy-style member service console as the demonstration target. All member records and balances are fake test data. ## What the demo shows The example task is: > Find a member, identify the Savings account, and return its available balance. The system demonstrates three separate execution modes: 1. **LLM discovery** – an LLM observes the UI, decides the next action, and interacts with the application. 2. **Deterministic replay** – a saved YAML capability executes the same workflow without asking an LLM what to do. 3. **Human handoff** – automation pauses while keeping the same browser session alive, a human performs an action, and automation resumes afterward. The implementation also distinguishes successful execution, expected business outcomes, and automation/application failures. ## Architecture ```text Natural-language goal | v Discovery Agent + LLM | v Observed UI workflow | v Typed Capability Artifact (YAML) | v Deterministic Replay Executor | v Surface Adapter | v Browser / Target Application ``` The browser implementation is behind a `SurfaceAdapter` abstraction so capability definitions are not directly coupled to Playwright. ## Repository structure ```text capabilities/ read_member_savings_balance.v1.yaml demo_app/ app.py templates/ static/ src/ agent/ discovery.py capabilities/ loader.py schema.py replay/ executor.py surfaces/ base.py browser.py evidence/ artifacts/ discovery/ replay/ handoff/ discover_demo.py replay_demo.py handoff_demo.py REPORT.md ``` ## Requirements - Python 3.9+ - Playwright - Flask - Pydantic - PyYAML - OpenAI Python SDK - pytest ## Setup Create and activate a virtual environment: ```bash python3 -m venv .venv source .venv/bin/activate ``` Install dependencies: ```bash pip install -r requirements.txt ``` Install the Playwright Chromium browser: ```bash playwright install chromium ``` Create the local environment file from the example: ```bash cp .env.example .env ``` Add the required OpenAI API key to `.env`. The real `.env` file is ignored by Git and must never be committed. ## Start the synthetic target application From the project root: ```bash python demo_app/app.py ``` The application runs locally at: `http://127.0.0.1:5050` Example synthetic IDs: - `48291` – valid member used for the primary demonstration - `73104` – additional synthetic member - `99999` – unknown member used to demonstrate an expected business outcome ## LLM discovery In another terminal, activate the virtual environment and load the environment variables: ```bash source .venv/bin/activate set -a source .env set +a ``` Run: ```bash python discover_demo.py --member-id 48291 ``` Expected result: ```json { "status": "success", "goal": "Find member 48291, identify their Savings account, and return the available balance as available_balance.", "outputs": { "available_balance": "4821.17" }, "steps": 3 } ``` During discovery, the model observes the current page state and chooses UI actions. Discovery evidence is written under: ```text evidence/discovery/ ``` Sensitive member identifiers are redacted from persisted discovery trace data. ## Deterministic replay Replay uses the saved capability: ```text capabilities/read_member_savings_balance.v1.yaml ``` Run the successful path: ```bash python replay_demo.py --member-id 48291 --headed ``` Expected output includes: ```json { "status": "success", "capability": "read_member_savings_balance", "outputs": { "available_balance": "4821.17" }, "step_id": null, "message": "Deterministic replay completed.", "observed": null } ``` The replay executor follows the ordered capability steps and does not ask an LLM to choose the next action. ## Expected business outcome Run: ```bash python replay_demo.py --member-id 99999 --headed ``` Expected result: ```json { "status": "business_outcome", "capability": "read_member_savings_balance", "outputs": {}, "step_id": "submit_member_search", "message": "No member found for ID 99999.", "observed": null } ``` Member-not-found is treated as an expected business result rather than incorrectly reporting it as an automation failure. ## Human handoff Run: ```bash python handoff_demo.py --member-id 48291 ``` The automation: 1. Opens the member application. 2. Enters the synthetic member ID. 3. Pauses with `human_required`. 4. Keeps the same Playwright browser session alive. 5. Asks the operator to manually click Search. 6. Waits for terminal acknowledgement. 7. Resumes automation in the same browser session. 8. Extracts the Savings balance. A successful resumed run returns: ```json { "status": "success", "outputs": { "available_balance": "4821.17" }, "message": "Automation resumed after human handoff in the same browser session.", "handoff": "completed" } ``` The handoff trace is stored in: ```text evidence/handoff/handoff-trace.json ``` The trace demonstrates: ```text automation -> navigate automation -> type_member_id handoff -> human_required human_action -> manual_search_submit handoff -> resumed automation -> resume_and_extract ``` The member identifier is redacted from the persisted handoff evidence. ## Capability artifact The example capability is: ```text capabilities/read_member_savings_balance.v1.yaml ``` It defines: - schema version - capability name and version - typed inputs and outputs - sensitive input metadata - risk classification - allowed actions - allowed origins - ordered UI steps - semantic targets and selector fallbacks - completion checkpoint The example capability is classified as `read_only`. An evidence copy of the capability is also stored under: ```text evidence/artifacts/read_member_savings_balance.v1.yaml ``` ## Result classification The runtime schema defines the following result states: - `success` - `business_outcome` - `recoverable` - `human_required` - `hard_failure` The current demos exercise successful replay, expected business outcomes, same-session human handoff, and hard-failure handling in the replay executor. ## Deterministic target resolution The replay capability does not depend entirely on one CSS selector. Targets can use semantic strategies such as: - label - role and accessible name - visible text - table-row semantics - selector fallbacks For example, the member ID input prefers its label and can fall back to: ```text input[name='member_id'] ``` The Search action prefers its button role/name and can fall back to: ```text button[type='submit'] ``` The Savings balance is extracted by locating the Savings account row and the Available Balance column. ## Safety The prototype applies several safety boundaries: - synthetic data only - read-only capability classification - explicit allowed actions - localhost target/origin restriction - sensitive member-ID metadata - redaction in persisted discovery and handoff traces - `.env` and credentials excluded from Git - selector restrictions during discovery - deterministic replay constrained by a reviewed capability artifact The example workflow performs no financial transaction and makes no irreversible application change. ## Evidence Evidence is organized under: ```text evidence/ ├── artifacts/ │ └── read_member_savings_balance.v1.yaml ├── discovery/ │ ├── discovery-trace.json │ └── final-state.png ├── handoff/ │ ├── handoff-trace.json │ └── final-state.png └── replay/ ├── success.json ├── success.png ├── business-outcome.json ├── business-outcome.png ├── replay-trace.json └── final-state.png ``` The evidence demonstrates: - model-driven discovery - redacted discovery traces - successful deterministic replay - expected member-not-found business outcome - same-session human handoff and resume - the reusable capability artifact Runtime `.log` files are ignored by Git. ## Testing Run: ```bash pytest -v ``` The current automated test validates that the versioned capability artifact loads successfully against the Pydantic capability schema. You can also compile the primary Python modules before submission: ```bash python -m py_compile \ discover_demo.py \ replay_demo.py \ handoff_demo.py \ src/agent/discovery.py \ src/replay/executor.py \ src/surfaces/browser.py \ src/capabilities/schema.py \ src/capabilities/loader.py ``` ## Quick reviewer walkthrough Start the demo application: ```bash python demo_app/app.py ``` Then, from another terminal with the virtual environment activated: ### 1. Discovery ```bash set -a source .env set +a python discover_demo.py --member-id 48291 ``` ### 2. Successful deterministic replay ```bash python replay_demo.py --member-id 48291 --headed ``` ### 3. Expected business outcome ```bash python replay_demo.py --member-id 99999 --headed ``` ### 4. Human handoff ```bash python handoff_demo.py --member-id 48291 ``` When prompted, manually click Search in the open browser and then press ENTER in the terminal. Automation resumes in the same browser session. ### 5. Tests ```bash pytest -v ``` ## Limitations This is intentionally a focused prototype rather than a production RPA platform. The current implementation uses: - one synthetic local application - one primary read-only capability - Playwright as the implemented surface adapter - local YAML capability storage - local filesystem evidence - terminal-based human handoff acknowledgement - limited automated integration testing Production extensions and architectural trade-offs are described in `REPORT.md`. ## Further design notes See `REPORT.md` for: - architecture - artifact schema - determinism and error handling - heterogeneity and multi-tenant considerations - escalation and human handoff - safety - deliberate implementation cuts