# pas-mllr/openai-cua-sample-app architecture

> Architecture diagram of the GitHub repository pas-mllr/openai-cua-sample-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pas-mllr/openai-cua-sample-app
- Repository: https://github.com/pas-mllr/openai-cua-sample-app

## Overview

##### Main Components
- CLI / Entry Point: Represented by the “cli.py” (and “main.py”/“simple_cua_loop.py”) which initializes the application and parses command-line arguments.
- Agent Module: The “agent/agent.py” encapsulates the main agent loop (e.g., run_full_turn()) that interacts with the OpenAI API and processes responses.
- Computer Interface & Implementations: The “computers/” directory implements a Computer interface (in “computers/computer.py”) and provides different environment implementations (e.g., “local_playwright.py”, “docker.py”, “browserbase.py”, “scrapybara.py”). These components are responsible for executing the received actions.
- External Dependencies: Include external services and tools such as the OpenAI API (for both responses and function calling), Playwright (for browser control), and Docker (for containerized environments).
- Examples: The “examples/” folder can be indicated as sample usage scenarios that show how one might run experiments or further test the core logic.

##### Relationships and Interactions
- The CLI serves as the starting point where a user selects a “Computer” environment (by passing options like “local-playwright”, “docker”, etc.).
- The CLI then instantiates the Agent. The Agent is responsible for continuously processing inputs and orchestrating the execution flow.
- The Agent calls the chosen “Computer” implementation (via the Computer interface) to execute actions such as clicks, typing, and so on.
- A feedback loop exists where the Computer captures the outcome (e.g., screenshots) and returns the state back to the Agent. This agent–computer loop continues until the session ends.

##### Architectural Patterns and Design Principles
- Modular Design: The separation between agent logic and computer abstractions allows for independent development/testing of each Computer environment.
- Interface Abstraction: The “Computer” interface allows adding new implementations without changing core agent logic.
- Extensibility: The design supports plug-and-play “Computer” environments (as shown by the variety in the “computers” directory).
- CLI-Driven Configuration: The core configuration and operation are driven by command-line inputs and environmental settings (e.g., via .env, Dockerfile).

##### Technologies, Frameworks, and Libraries
- Python as the core language.
- Playwright (in “local_playwright.py”) for controlling local browsers.
- Docker support provided by the “Dockerfile” and the “docker.py” implementation.
- External Computer services such as Browserbase and Scrapybara, which are integrated via API keys (referenced in the .env file).
- OpenAI API: The responses and function calling integrations form a critical dependency for the agent’s behavior.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend Components
    CLI["CLI / Entry Point"]:::infra
    Agent["Agent Module"]:::infra
    OpenAI["OpenAI API"]:::external

    %% Computer Abstraction Layer Subgraph
    subgraph "Computer Abstraction Layer"
        ComputerInterface["Computer Interface"]:::infra
        LocalPlaywright["LocalPlaywright (Playwright)"]:::external
        Docker["Docker Environment"]:::external
        Browserbase["Browserbase Service"]:::external
        Scrapybara["Scrapybara Service"]:::external
    end

    %% Examples Subgraph
    subgraph "Examples & Usage Scenarios"
        Examples["Usage Examples"]:::example
    end

    %% Main Flow
    CLI -->|"initiates"| Agent
    Agent -->|"calls OpenAI"| OpenAI
    Agent -->|"invokes"| ComputerInterface

    %% Computer Implementations delegation
    ComputerInterface -->|"delegates_action"| LocalPlaywright
    ComputerInterface -->|"delegates_action"| Docker
    ComputerInterface -->|"delegates_action"| Browserbase
    ComputerInterface -->|"delegates_action"| Scrapybara

    %% Feedback from implementations back to Agent
    LocalPlaywright -->|"feedback"| Agent
    Docker -->|"feedback"| Agent
    Browserbase -->|"feedback"| Agent
    Scrapybara -->|"feedback"| Agent

    %% Examples guiding usage
    Examples -->|"demonstrates_usage"| CLI

    %% Click Events for Component Mapping
    click CLI "https://github.com/pas-mllr/openai-cua-sample-app/blob/main/cli.py"
    click Agent "https://github.com/pas-mllr/openai-cua-sample-app/blob/main/agent/agent.py"
    click ComputerInterface "https://github.com/pas-mllr/openai-cua-sample-app/blob/main/computers/computer.py"
    click LocalPlaywright "https://github.com/pas-mllr/openai-cua-sample-app/blob/main/computers/local_playwright.py"
    click Docker "https://github.com/pas-mllr/openai-cua-sample-app/blob/main/computers/docker.py"
    click Browserbase "https://github.com/pas-mllr/openai-cua-sample-app/blob/main/computers/browserbase.py"
    click Scrapybara "https://github.com/pas-mllr/openai-cua-sample-app/blob/main/computers/scrapybara.py"
    click Examples "https://github.com/pas-mllr/openai-cua-sample-app/tree/main/examples/"

    %% Styles
    classDef infra fill:#E0BBE4,stroke:#5D2A42,stroke-width:2px;
    classDef external fill:#FFDFD3,stroke:#D1495B,stroke-width:2px;
    classDef example fill:#CDEAC0,stroke:#379683,stroke-width:2px;
```
