# thunlp/chateval architecture

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

- Interactive diagram: https://gitdiagram.com/thunlp/chateval
- Repository: https://github.com/thunlp/chateval

## Overview

##### Main Components
- Frontend & User Interaction: The UI is primarily provided via the Gradio web server (found in FastChat/serve, e.g., gradio_web_server_multi) where users select models and initiate chats.
- Controller & Orchestration: The FastChat controller (fastchat/serve/controller) coordinates multiple model workers. This component acts as the hub for incoming requests and dispatches model inference requests.
- Evaluation Agents and Debate Engine: The “agentverse” directory contains a set of agents, environments, memory modules, and tasks that orchestrate the multi-agent debate for evaluating LLM responses. This includes configuration files (YAML) and scripts (llm_eval.py) to run evaluations.
- Data Handling and Pre/Post–Processing: Both FastChat and agentverse include data modules (e.g., FastChat/fastchat/data and agentverse/tasks/.../data) to prepare, clean, and transform input as well as to format the output from the debates.
- Supporting and Deployment Artifacts: Docker files (under FastChat/docker), test suites, scripts, and documentation provide guidance and automate the deployment (containerization, testing, and training).

##### Relationships & Interactions
- The User initiates a session through the Gradio web interface.
- The FastChat controller accepts the user’s request and signals one or multiple model workers to produce LLM outputs.
- The generated responses are then fed into the evaluation system – agentverse’s multi-agent debate workflow – where different types of agent evaluators (as set in “agentverse/agents”) debate and assign scores.
- Data flows between components: the initial prompt, model responses, their transmission to the evaluation module, and final output (JSON with evaluations) are handled through APIs and command-line scripts (e.g., llm_eval.py).
- Configuration files (such as agentverse/tasks/llm_eval/config.yaml) govern the behavior and interactions of the evaluation agents, detailing memory usage, prompt templates, and scoring strategies.

##### Architectural Patterns & Design Principles
- Modularity: The project clearly separates chat-serving (FastChat) from evaluation logic (agentverse), ensuring clean module boundaries.
- Microservice-style Components: With components like the controller, model workers, and the Gradio web server each running individual processes (and even via Docker), there is a loose coupling between services.
- Extensibility: By using configuration files (YAML) and modular agents/environments, adding or modifying new evaluators or model types is straightforward.
- API-Driven Communication: The use of HTTP endpoints (seen in the scripts for starting the controller and workers) represents a service-based architecture supporting horizontal scaling.

##### Relevant Technologies, Frameworks, and Libraries
- FastChat’s internal components (Python modules in fastchat/serve, fastchat/model, etc.) for model serving and chat orchestration.
- Agentverse’s agent management, environment simulation, and memory manipulation logic.
- Gradio for the web demo interface.
- Docker for containerization and deployment (as defined in FastChat/docker).
- OpenAI’s API (indicated in the README) for models that invoke API calls.
- Auxiliary build and testing tools including scripts (bash files) and configuration management (pyproject.toml, setup.py, requirements.txt).

##### Summary
- Explicitly delineate the role of “agentverse” as the autonomous, multi-agent debate and evaluation subsystem.
- Project’s emphasis on modularity and extensibility by cleanly compartmentalizing each major block.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User[/"User"/]:::user

    subgraph "Frontend & Serving Subsystem"
        FE["Gradio Web UI"]:::frontend
        CTRL["Controller"]:::controller
        MW1["Model Worker (Single)"]:::worker
        MW2["Model Worker (Multi)"]:::worker
        FD["Data Handling (FastChat)"]:::data
        SD["Deployment (Docker)"]:::deploy
        TS["Test Suites"]:::deploy
    end

    subgraph "Evaluation Subsystem (Agentverse)"
        EA["Evaluation Agent"]:::evaluation
        EE["Debate Engine"]:::evaluation
        ED["Data Handling (Agentverse)"]:::data
        CFG["Configuration (YAML)"]:::config
        EO["Final Evaluation Output"]:::evaluation
    end

    %% Serving Subsystem Flow
    User -->|"initiates"| FE
    FE -->|"sendsRequest"| CTRL
    CTRL -->|"dispatchInference"| MW1
    CTRL -->|"dispatchInference"| MW2
    MW1 -->|"returnResponse"| CTRL
    MW2 -->|"returnResponse"| CTRL
    CTRL -->|"aggregateResponses"| FD

    %% Data Transfer to Evaluation Subsystem
    FD -->|"sendsData"| EA
    EA -->|"triggersDebate"| EE
    EE -->|"producesResult"| EO
    ED -->|"supports"| EA
    CFG -->|"configures"| EA

    %% Auxiliary Links for Deployment & Tests
    FE --- SD
    CTRL --- SD
    FE --- TS
    CTRL --- TS

    %% Click Events (Paths)
    click FE "https://github.com/thunlp/chateval/blob/main/FastChat/fastchat/serve/gradio_web_server_multi.py"
    click CTRL "https://github.com/thunlp/chateval/blob/main/FastChat/fastchat/serve/controller.py"
    click MW1 "https://github.com/thunlp/chateval/blob/main/FastChat/fastchat/serve/model_worker.py"
    click MW2 "https://github.com/thunlp/chateval/blob/main/FastChat/fastchat/serve/multi_model_worker.py"
    click FD "https://github.com/thunlp/chateval/tree/main/FastChat/fastchat/data"
    click EA "https://github.com/thunlp/chateval/blob/main/agentverse/agents/llm_eval_agent.py"
    click EE "https://github.com/thunlp/chateval/blob/main/agentverse/environments/llm_eval.py"
    click ED "https://github.com/thunlp/chateval/tree/main/agentverse/tasks/llm_eval/data"
    click SD "https://github.com/thunlp/chateval/tree/main/FastChat/docker"
    click TS "https://github.com/thunlp/chateval/tree/main/FastChat/tests"

    %% Styling Classes
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef controller fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef worker fill:#FFE4B5,stroke:#000,stroke-width:2px;
    classDef data fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef evaluation fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef config fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef deploy fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef user fill:#87CEFA,stroke:#000,stroke-width:2px;
```
