# openbmb/proagent architecture

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

- Interactive diagram: https://gitdiagram.com/openbmb/proagent
- Repository: https://github.com/openbmb/proagent

## Overview

##### Main Components
- Core Agent Engine: Represented by the “ProAgent/agent” directory. This includes the main LLM integration (for example, “gpt4_function.py”) and utility functions for handling agent operations.
- Workflow and Decision Handlers: Found in “ProAgent/handler”. This includes modules like “ReACT.py” and “react_prompt.py”, which implement the decision framework (e.g., the ReACT pattern) that allows the agent to construct and refine workflows.
- Workflow Parsing & Compilation: The “ProAgent/n8n_parser” directory contains the compiler (compiler.py), node definitions, intrinsic functions, and utility scripts necessary to convert human instructions or workflow descriptions into n8n-compatible workflows.
- Testing and Simulation: The “ProAgent/n8n_tester” folder provides a simulated environment for workflows. It contains mock data, examples (mock_input, mock_pairs), and helper scripts to run pseudo nodes.
- Frontend & Presentation Layer: The “ProAgent/frontend” directory includes modules (like “highlight_code.py”) to support the frontend component, possibly for debugging or code presentation.
- Routing and Utilities: The “ProAgent/router” and other utility modules (like “utils.py” at the project root and inside agent/handler) support internal communications, record-keeping (e.g., “running_recorder.py”), and general helper functions.
- Configuration & Logging: “ProAgent/config.py” and “ProAgent/loggers” modules define the runtime configurations (development, refine, production) and logging mechanisms.
- External Interactions: The project expects integration with the n8n environment (see n8n installation and credential export/import commands in the README).
- Case Studies and Records: The “apa_case” folder includes test cases and logs that illustrate real-world usage as reported in the associated paper.

##### Relationships and Data Flows
- Data Flow from User Input to Workflow Execution: Start at the main entry point (main.py) which reads the configurations (from ProAgent/config.py). The agent (ProAgent/agent) then processes input, interacts with various handlers (ProAgent/handler) to decide or refine workflows.
- Workflow Construction: The n8n_parser component takes the decisions from the agent and converts them into n8n workflow configurations. This process may involve collaborative decision-making if human intervention is required (noted in the README as proactive inquiries).
- Testing and Simulation: The system then routes these workflows to the n8n_tester to simulate or debug flows before actual deployment.
- Logging & Record Keeping: Once a workflow is executed, the system logs activity both using the “loggers” and “running_recorder” modules.

##### Architectural Patterns & Principles
- Modular Design: The logical separation into agent, handler, parser, tester, router, and frontend modules suggests an architecture where each component is responsible for a distinct part of the process (adhering to the single-responsibility principle).
- Workflow/Decision Automation Pattern: The use of ReACT and agentic decision-making as well as compiler-based translation to external workflow definitions underlines a pipeline architecture.
- Extensibility: With multiple directories (n8n_tester for testing, various configuration files, and extensive sub-modules for different responsibilities), the design showcases extensibility to support additional functionalities or integrations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global Nodes
    User["User/External Input"]:::user
    MainApp["Main Application (main.py)"]
    
    %% Core Processing Subgraph
    subgraph "Core Processing"
        %% Agent Core Subgraph
        subgraph "Agent Core"
            agentLLM["LLM Integration"]:::agent
            agentUtils["Agent Utils"]:::agent
            agentLLM --- agentUtils
        end

        %% Workflow/Decision Handlers Subgraph
        subgraph "Workflow/Decision Handlers"
            handlerReACT["ReACT Module"]:::handler
            handlerPrompt["Prompt Manager"]:::handler
            handlerRPA["RPA Code Example"]:::handler
            handlerReACT --- handlerPrompt --- handlerRPA
        end

        %% Workflow Parser & Compiler Subgraph
        subgraph "Workflow Parser & Compiler"
            parserCompiler["Compiler"]:::parser
            parserNodeEditor["Node Editor"]:::parser
            parserCompiler --- parserNodeEditor
        end

        %% Router & Utilities Subgraph
        subgraph "Router & Utilities"
            routing["Routing Module"]:::routing
            generalUtils["General Utils"]:::routing
            runningRecorder["Running Recorder"]:::routing
            routing --- generalUtils --- runningRecorder
        end

        %% Config & Logging Subgraph
        subgraph "Config & Logging"
            config["Configuration Manager"]:::config
            logger["Logging System"]:::config
            config --- logger
        end

        %% Frontend Support Subgraph
        subgraph "Frontend Support"
            frontend["Code Highlighting"]:::frontend
        end

        %% Testing/Simulation Subgraph
        subgraph "Testing/Simulation"
            testerRunCode["Run Code Tester"]:::tester
            testerRunNode["Run Node Tester"]:::tester
            testerMock["Mock Data"]:::tester
            testerRunCode --- testerRunNode --- testerMock
        end
    end

    %% External and Additional Components
    n8nInterface["n8n Service Interface"]:::external
    caseStudies["Case Studies & Records"]:::external

    %% Connections
    User -->|"initiates"| MainApp
    MainApp -->|"loads_config"| config
    MainApp -->|"invokes_agent"| agentLLM
    agentLLM -->|"internal_routing"| routing
    agentLLM -->|"sends_decision"| handlerReACT
    handlerRPA -->|"generates_workflow"| parserCompiler
    parserCompiler -->|"submit_workflow"| n8nInterface
    parserCompiler -->|"simulate_workflow"| testerRunCode
    testerMock -->|"log_results"| logger
    agentLLM -->|"display_debug"| frontend
    logger -->|"archive"| caseStudies

    %% Class Definitions
    classDef agent fill:#ffcccc,stroke:#cc0000,stroke-width:2px,color:#000;
    classDef handler fill:#ccffcc,stroke:#009900,stroke-width:2px,color:#000;
    classDef parser fill:#ccccff,stroke:#0000cc,stroke-width:2px,color:#000;
    classDef tester fill:#fff0b3,stroke:#ff9900,stroke-width:2px,color:#000;
    classDef frontend fill:#e6e6fa,stroke:#8a2be2,stroke-width:2px,color:#000;
    classDef routing fill:#dcdcdc,stroke:#696969,stroke-width:2px,color:#000;
    classDef config fill:#ffe6e6,stroke:#ff6666,stroke-width:2px,color:#000;
    classDef external fill:#e0ffff,stroke:#008b8b,stroke-width:2px,color:#000;
    classDef user fill:#f0e68c,stroke:#daa520,stroke-width:2px,color:#000;

    %% Click Events
    click agentLLM "https://github.com/openbmb/proagent/blob/main/ProAgent/agent/gpt4_function.py"
    click agentUtils "https://github.com/openbmb/proagent/blob/main/ProAgent/agent/utils.py"
    click handlerReACT "https://github.com/openbmb/proagent/blob/main/ProAgent/handler/ReACT.py"
    click handlerPrompt "https://github.com/openbmb/proagent/blob/main/ProAgent/handler/react_prompt.py"
    click handlerRPA "https://github.com/openbmb/proagent/blob/main/ProAgent/handler/rpa_code_example.py"
    click parserCompiler "https://github.com/openbmb/proagent/blob/main/ProAgent/n8n_parser/compiler.py"
    click parserNodeEditor "https://github.com/openbmb/proagent/blob/main/ProAgent/n8n_parser/node_editor.py"
    click testerRunCode "https://github.com/openbmb/proagent/blob/main/ProAgent/n8n_tester/run_code.py"
    click testerRunNode "https://github.com/openbmb/proagent/blob/main/ProAgent/n8n_tester/run_node.py"
    click testerMock "https://github.com/openbmb/proagent/tree/main/ProAgent/n8n_tester"
    click frontend "https://github.com/openbmb/proagent/blob/main/ProAgent/frontend/highlight_code.py"
    click routing "https://github.com/openbmb/proagent/blob/main/ProAgent/router/utils.py"
    click generalUtils "https://github.com/openbmb/proagent/blob/main/ProAgent/utils.py"
    click runningRecorder "https://github.com/openbmb/proagent/blob/main/running_recorder.py"
    click config "https://github.com/openbmb/proagent/blob/main/ProAgent/config.py"
    click logger "https://github.com/openbmb/proagent/blob/main/ProAgent/loggers/logs.py"
    click caseStudies "https://github.com/openbmb/proagent/tree/main/apa_case"
```
