# agora-protocol/paper-demo architecture

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

- Interactive diagram: https://gitdiagram.com/agora-protocol/paper-demo
- Repository: https://github.com/agora-protocol/paper-demo

## Overview

##### Main Components

A. Agent Layer
- User Agents (/agents/user/)
- Server Agents (/agents/server/)
- Protocol DB Agents (/agents/protocol_db/)
- Common Agent Components (/agents/common/)

B. Model Layer (/models/)
- OpenAI Integration
- Multiple LLM Support (GPT-4, Llama 3 405b, Gemini 1.5 Pro)

C. Toolformers Layer
- Base Toolformer (/toolformers/base.py)
- Specialized Toolformers:
- Negotiator
- Programmer
- Protocol Checker
- Querier
- Responder

D. Database Layer
- MongoDB Integration
- SQL Integration

**Rectangle: Core Components**
**Hexagon: Agents**
**Rounded Rectangle: LLM Models**
**Diamond: Toolformers**

**Blue: Agent components**
**Green: Database systems**
**Purple: LLM models**
**Orange: Toolformers**
**Gray: Utility/Support components**

##### Key Relationships to Highlight

A. Communication Flow
1. Natural language communication (initial)
2. Protocol negotiation
3. Routine implementation
4. Optimized communication path

B. Integration Points
- How agents interact with:
- Different LLM models
- Database systems
- Specialized toolformers

##### Architectural Patterns to Emphasize

A. Protocol Negotiation System
- Transition from natural language to structured protocols
- Protocol storage and retrieval mechanisms

B. Multi-Model Architecture
- Demonstrate how different LLM models are unified through the toolformers layer
- Abstraction layer that enables model interoperability

##### Important Implementation Details

A. Memory Management
- Memory components from server/memory.py and user/memory.py
- How state is maintained across interactions

B. Configuration System
- Config management between different components
- How environment variables and config files are utilized

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Agents
        UA[User Agent]
        SA[Server Agent]
        PDA[Protocol DB Agent]
        CAC[Common Agent Components]
    end

    subgraph Memory
        SM[Server Memory]
        UM[User Memory]
        PM[Protocol Management]
    end

    subgraph Models
        OAI[OpenAI Integration]
        LLAMA[Llama Integration]
        GEM[Gemini Integration]
        CAMEL[CAMEL Integration]
    end

    subgraph Toolformers
        BT[Base Toolformer]
        NEG[Negotiator]
        PROG[Programmer]
        PC[Protocol Checker]
        QUE[Querier]
        RES[Responder]
    end

    subgraph Databases
        MONGO[(MongoDB)]
        SQL[(SQL Database)]
    end

    subgraph Config
        SC[Server Config]
        UC[User Config]
    end

    %% Relationships
    UA --> SA
    SA --> PDA
    UA & SA & PDA --> CAC

    UA --> UM
    SA --> SM
    UA --> PM

    UA & SA --> OAI & LLAMA & GEM & CAMEL

    UA & SA --> BT
    BT --> NEG & PROG & PC & QUE & RES

    UA & SA --> MONGO & SQL

    SA --> SC
    UA --> UC

    %% Click Events
    click UA "https://github.com/agora-protocol/paper-demo/blob/main/agents/user/main.py"
    click SA "https://github.com/agora-protocol/paper-demo/blob/main/agents/server/main.py"
    click PDA "https://github.com/agora-protocol/paper-demo/blob/main/agents/protocol_db/main.py"
    click CAC "https://github.com/agora-protocol/paper-demo/blob/main/agents/common/core.py"
    click OAI "https://github.com/agora-protocol/paper-demo/blob/main/models/openai_model.py"
    click BT "https://github.com/agora-protocol/paper-demo/blob/main/toolformers/base.py"
    click NEG "https://github.com/agora-protocol/paper-demo/blob/main/specialized_toolformers/negotiator.py"
    click PROG "https://github.com/agora-protocol/paper-demo/blob/main/specialized_toolformers/programmer.py"
    click PC "https://github.com/agora-protocol/paper-demo/blob/main/specialized_toolformers/protocol_checker.py"
    click QUE "https://github.com/agora-protocol/paper-demo/blob/main/specialized_toolformers/querier.py"
    click RES "https://github.com/agora-protocol/paper-demo/blob/main/specialized_toolformers/responder.py"
    click MONGO "https://github.com/agora-protocol/paper-demo/blob/main/databases/mongo.py"
    click SQL "https://github.com/agora-protocol/paper-demo/blob/main/databases/sql.py"
    click SM "https://github.com/agora-protocol/paper-demo/blob/main/agents/server/memory.py"
    click UM "https://github.com/agora-protocol/paper-demo/blob/main/agents/user/memory.py"
    click PM "https://github.com/agora-protocol/paper-demo/blob/main/agents/user/protocol_management.py"
    click LLAMA "https://github.com/agora-protocol/paper-demo/tree/main/toolformers/llama/"
    click GEM "https://github.com/agora-protocol/paper-demo/blob/main/toolformers/gemini.py"
    click CAMEL "https://github.com/agora-protocol/paper-demo/blob/main/toolformers/camel.py"
    click SC "https://github.com/agora-protocol/paper-demo/blob/main/agents/server/config.py"
    click UC "https://github.com/agora-protocol/paper-demo/blob/main/agents/user/config.py"

    %% Styling
    classDef agent fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef memory fill:#ffcdb2,stroke:#333,stroke-width:2px
    classDef model fill:#b5e48c,stroke:#333,stroke-width:2px
    classDef toolformer fill:#ffd6a5,stroke:#333,stroke-width:2px
    classDef database fill:#caffbf,stroke:#333,stroke-width:2px
    classDef config fill:#e5e5e5,stroke:#333,stroke-width:2px

    class UA,SA,PDA,CAC agent
    class SM,UM,PM memory
    class OAI,LLAMA,GEM,CAMEL model
    class BT,NEG,PROG,PC,QUE,RES toolformer
    class MONGO,SQL database
    class SC,UC config
```
