# GUI Agent Framework **English** | [中文](README_CN.md) > A modular, block-based GUI automation framework combining **VLM vision understanding**, **LLM task planning**, **Playwright browser control**, and **pyautogui desktop automation** — inspired by MIT Scratch visual programming and RPA paradigms. ## Highlights - **Block-based Automation** — Encapsulate every operation as a reusable Block with a unified interface; compose them into Pipelines like building with LEGO - **AI Decision Nodes** — Inject LLM/VLM reasoning at critical flow points for dynamic, context-aware decisions - **Human-in-the-Loop** — Auto-pause for CAPTCHAs, manual logins, or confirmation prompts; resume seamlessly - **Multi-Platform** — Unified framework for both browser (Playwright) and desktop GUI (pyautogui) automation - **Visual Editor** — Scratch-style drag-and-drop pipeline builder (HTML export) - **GUI Agent Crawler** — Autonomous browser agent using Observe→Think→Act loop with VLM + LLM + Playwright - **Multi-Agent Collaboration** — Pipeline, Parallel, and Supervised orchestration modes - **MCP Server** — 15 tools exposed via JSON-RPC/WebSocket for external AI client integration ## Project Structure ``` gui-agent-framework/ ├── modular_agent/ # Block-based GUI Agent Framework │ ├── engine/ # Pipeline execution engine & shared context │ ├── blocks/ # Reusable blocks (browser, desktop, data, control) │ ├── ai_decision/ # LLM/VLM decision nodes & human-loop │ ├── scenarios/ # Pre-built scenarios (approval, review crawling) │ └── visual/ # Scratch-style visual pipeline editor ├── foodreview_crawler/ # Food Review Crawler with GUI Agent │ ├── agent/ # GUI Agent core (vision, planner, executor, loop) │ ├── core/ # Data models & SQLite database │ ├── crawlers/ # Platform crawlers (Google Maps, OpenRice, Meituan...) │ ├── processors/ # AI processors (sentiment, keywords, translation) │ └── ui/ # NiceGUI web dashboard ├── approval_agent/ # Work Order Approval Agent (Jupyter Notebook) ├── docs/ # Documentation & Research │ ├── presentations/ # Slides & study guides │ └── research_notes/ # Multi-agent & RL research notes ├── requirements.txt └── README.md ``` ## Components ### 1. Modular Agent — Block-based Automation Framework Inspired by **MIT Scratch** and **RPA** tools, every operation is a self-contained Block: ```python from modular_agent.engine import Pipeline, PipelineContext from modular_agent.blocks import * from modular_agent.ai_decision import * pipeline = Pipeline("My Automation Flow") pipeline.add(BrowserStartBlock(headless=False)) pipeline.add(NavigateBlock(url="https://example.com")) pipeline.add(WaitBlock(ms=2000)) # AI-powered page analysis pipeline.add(VLMDecisionBlock( prompt="Is the page loaded? Is login required?", result_key="page_check", )) # Conditional branching pipeline.add(ConditionalBlock( condition=lambda ctx: ctx.get("page_check", {}).get("need_login"), if_true=HumanLoopBlock(message="Please log in manually"), )) # Data extraction pipeline.add(CommentCrawlBlock(max_scrolls=10, result_key="data")) pipeline.add(BrowserStopBlock()) ctx = PipelineContext() result = await pipeline.run(ctx) ``` #### Block Categories | Category | Blocks | Description | |----------|--------|-------------| | 🌐 Browser | `NavigateBlock`, `ClickBlock`, `TypeBlock`, `ScrollBlock`, `WaitBlock`, `ExpandMoreBlock`, `EnableElementBlock`, `EvalJSBlock`, `ScreenshotBlock` | Playwright-driven browser operations | | 🖥️ Desktop | `ImageClickBlock`, `ImageWaitBlock`, `DesktopTypeBlock`, `DesktopHotkeyBlock`, `WindowActivateBlock`, `DesktopAlertBlock` | pyautogui-driven desktop GUI operations | | 🧠 AI | `AIDecisionBlock`, `VLMDecisionBlock` | LLM/VLM decision at critical nodes | | 📊 Data | `DOMExtractBlock`, `VLMExtractBlock`, `CommentCrawlBlock`, `AutoScrollLoadBlock`, `HybridExtractBlock` | Web data extraction (DOM + VLM hybrid) | | 🔄 Control | `LoopBlock`, `ConditionalBlock`, `RetryBlock`, `SequenceBlock` | Flow control primitives | | 🤝 Human | `HumanLoopBlock`, `CaptchaBlock`, `ManualInputBlock`, `ConfirmBlock` | Human-in-the-loop intervention | ### 2. Food Review Crawler — GUI Agent System An autonomous browser agent that uses **VLM vision + LLM planning + Playwright execution** to crawl food reviews from multiple platforms. ``` ┌──────────────────────────────────────────────────┐ │ NiceGUI Web UI │ │ Dashboard │ Agent │ Crawler │ Reviews │ Reports│ └──────────┬───────────────────────────────────────┘ │ ┌──────────▼───────────────────────────────────────┐ │ GUI Agent Core Loop │ │ ┌─────────┐ ┌─────────┐ ┌──────────┐ │ │ │ Observe │──▶│ Think │──▶│ Act │ │ │ │ (VLM) │ │ (LLM) │ │(Playwright)│ │ │ └─────────┘ └─────────┘ └──────────┘ │ │ ▲ │ │ │ └────────────────────────────┘ │ └──────────────────────────────────────────────────┘ │ ┌──────────▼───────────────────────────────────────┐ │ Multi-Agent Collaboration │ │ Pipeline │ Parallel │ Supervised │ └──────────────────────────────────────────────────┘ │ ┌──────────▼───────────────────────────────────────┐ │ MCP Server (JSON-RPC/WS) │ │ 15 Tools · Supports external AI clients │ └──────────────────────────────────────────────────┘ ``` #### Supported Platforms - Google Maps - OpenRice - Meituan (美团) - Dianping (大众点评) - Ele.me (饿了么) - Douyin (抖音) - Keeta - Mfood #### CLI Commands ```bash # Launch Web GUI python foodreview_crawler/main.py # Single-store agent crawl python foodreview_crawler/cli.py agent "HEYTEA Times Square" # Batch agent crawl by region python foodreview_crawler/cli.py agent --region 北美 # Multi-agent parallel collaboration python foodreview_crawler/cli.py cowork --region 欧洲 --mode parallel --workers 3 # Start MCP Server python foodreview_crawler/cli.py mcp --port 8765 ``` #### MCP Tools | Tool | Description | |------|-------------| | `navigate` | Navigate to URL | | `click` / `click_coordinates` | CSS selector or coordinate click | | `type_text` | Input text | | `scroll` | Scroll page | | `screenshot` | Screenshot + VLM analysis | | `extract_reviews` | OCR review extraction | | `search_store` | Google Maps store search | | `batch_crawl` | Batch crawl | | `list_stores` | List stores | | `get_status` / `stop` | Agent control | ### 3. Work Order Approval Agent A desktop GUI agent for automating work order approvals on **DingTalk (钉钉)**, powered by: - **pyautogui** for image-based GUI element detection and clicking - **Coze AI Workflow** for intelligent approval decisions (approve/reject with reasoning) - **pandas** for batch data processing ```python # Automated approval flow: # 1. Read approval decisions from Excel (via Coze AI Workflow) # 2. For each ticket: filter → open details → approve/reject → fill reason → confirm # 3. Handle edge cases (missing tickets, already processed, etc.) ``` ## Quick Start ### Installation ```bash # Clone the repository git clone https://github.com/sjkncs/gui-agent-framework.git cd gui-agent-framework # Install dependencies pip install -r requirements.txt # Install Playwright browsers playwright install chromium ``` ### Environment Setup Set your API keys as environment variables: ```bash # For AI decision nodes (LLM/VLM) export OPENAI_API_KEY="sk-xxx" # or DeepSeek / Qwen API key export OPENAI_BASE_URL="https://api.deepseek.com/v1" # optional custom endpoint # For Coze workflow integration export COZE_TOKEN="pat_xxx" ``` ### Run Examples ```python # Example 1: Modular Agent - Review Crawling import asyncio from modular_agent.scenarios.review_crawl_scenario import run_review_crawl reviews, result = asyncio.run(run_review_crawl( store_url="https://www.google.com/maps/place/HEYTEA+...", store_name="HEYTEA Times Square", max_scrolls=15, headless=False, )) # Example 2: Modular Agent - Work Order Approval from modular_agent.scenarios import build_approval_pipeline pipeline, ctx = build_approval_pipeline( excel_path="approval_results.xlsx", button_dir="button_pics/", ) result = asyncio.run(pipeline.run(ctx)) ``` ## Tech Stack | Layer | Technology | |-------|------------| | Browser Automation | Playwright | | Desktop Automation | pyautogui, pygetwindow, pyperclip | | LLM | DeepSeek-V3, GPT-4, Qwen | | VLM | Qwen3-VL-Plus (multimodal vision) | | Web UI | NiceGUI | | Data Storage | SQLite, pandas, openpyxl | | Protocol | MCP (Model Context Protocol), JSON-RPC 2.0 | | AI Platform | Coze (扣子) Workflow | ## Architecture Comparison | Dimension | Traditional RPA | This Framework | |-----------|----------------|----------------| | Reusability | Hardcoded flows | Independent blocks, cross-scenario reuse | | Error Handling | Simple try/except | RetryBlock + AI decision + human loop | | Extensibility | Modify source code | Add new blocks | | Cross-platform | Browser-only or desktop-only | Unified browser + desktop | | AI Capability | None | LLM/VLM at critical nodes | | Data Extraction | Fixed DOM selectors | DOM + VLM hybrid + auto-expand | | Visualization | None | Scratch-style drag-and-drop editor | | Human Collaboration | None | CAPTCHA / manual login / confirmation | ## License MIT License ## Contributing Contributions are welcome! Please feel free to submit Pull Requests.