# polymarket/agents architecture

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

- Interactive diagram: https://gitdiagram.com/polymarket/agents
- Repository: https://github.com/polymarket/agents

## Overview

##### Main System Components

a) Interface Layer:
- CLI Interface (scripts/python/cli.py)
- Server Component (scripts/python/server.py)

b) Application Core:
- Trade Execution System (agents/application/trade.py)
- Agent Creator (agents/application/creator.py)
- Execution Engine (agents/application/executor.py)
- Prompt Management (agents/application/prompts.py)

c) Integration Layer:
- Polymarket Integration (agents/polymarket/)
- Data Connectors (agents/connectors/)
- Vector Database (Chroma)

##### Component Relationships

a) External Systems Integration:
- Connections to external APIs (News, Search, Polymarket CLOB)
- Integration with Chroma DB for vector storage
- Connection to OpenAI API for LLM operations

b) Internal Flow:
- CLI/Server → Application Core
- Application Core → Connectors
- Connectors → External Services
- Trade Execution → Polymarket API

##### Specific Design Elements

Use these visual elements:

- Blue rectangles: Core application components
- Green rectangles: External services
- Yellow rectangles: Data stores
- Purple rectangles: API interfaces

##### Key Architectural Patterns to Highlight

a) Modular Architecture:
- Separate connectors for different data sources
- Isolated trading logic
- Independent prompt management

b) RAG (Retrieval-Augmented Generation) Pipeline:
- Data flow from sources to vector DB
- LLM integration points
- Knowledge retrieval process

##### Implementation Details

- User Interface    |
- (CLI/Server Layer)    |

- ↓

- Application Core    |
- (Agent/Trading Logic)  |

- ↓

- Integration Layer     |
- (Connectors/APIs)      |

- ↓

- External Services    |
- (Polymarket/Data/LLM)  |

##### Technical Stack Indicators

- Python 3.9 runtime
- OpenAI API integration
- Chroma DB vector storage
- Polymarket CLOB client
- Docker containerization

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef interface fill:#6495ED,stroke:#333,stroke-width:2px
    classDef core fill:#4169E1,stroke:#333,stroke-width:2px
    classDef integration fill:#9370DB,stroke:#333,stroke-width:2px
    classDef external fill:#90EE90,stroke:#333,stroke-width:2px
    classDef storage fill:#FFD700,stroke:#333,stroke-width:2px
    classDef utils fill:#DEB887,stroke:#333,stroke-width:2px

    %% Interface Layer
    subgraph Interface
        CLI["CLI Interface"]
        Server["Server Component"]
    end

    %% Application Core
    subgraph AppCore
        Trade["Trade Execution"]
        Creator["Agent Creator"]
        Executor["Execution Engine"]
        Prompts["Prompt Management"]
        Cron["Scheduled Tasks"]
    end

    %% Integration Layer
    subgraph Integration
        PolyMarket["Polymarket Integration"]
        Gamma["Gamma Protocol"]
        NewsConn["News Connector"]
        SearchConn["Search Connector"]
        ChromaConn["Vector DB Connector"]
    end

    %% External Services
    subgraph External
        PolyAPI["Polymarket CLOB"]
        OpenAI["OpenAI API"]
        ChromaDB["Chroma DB"]
        NewsAPI["News Services"]
        SearchAPI["Search Services"]
    end

    %% Utility Layer
    subgraph Utils
        UtilFuncs["Utility Functions"]
        DataObj["Data Objects"]
    end

    %% Relationships
    CLI --> Trade
    Server --> Trade
    Trade --> Creator
    Creator --> Executor
    Executor --> Prompts
    Trade --> PolyMarket
    PolyMarket --> Gamma
    Gamma --> PolyAPI
    Creator --> ChromaConn
    ChromaConn --> ChromaDB
    Creator --> NewsConn
    NewsConn --> NewsAPI
    Creator --> SearchConn
    SearchConn --> SearchAPI
    Prompts --> OpenAI
    Cron --> Trade

    %% Click Events
    click CLI "https://github.com/Polymarket/agents/blob/main/scripts/python/cli.py"
    click Server "https://github.com/Polymarket/agents/blob/main/scripts/python/server.py"
    click Trade "https://github.com/Polymarket/agents/blob/main/agents/application/trade.py"
    click Creator "https://github.com/Polymarket/agents/blob/main/agents/application/creator.py"
    click Executor "https://github.com/Polymarket/agents/blob/main/agents/application/executor.py"
    click Prompts "https://github.com/Polymarket/agents/blob/main/agents/application/prompts.py"
    click PolyMarket "https://github.com/Polymarket/agents/blob/main/agents/polymarket/polymarket.py"
    click ChromaConn "https://github.com/Polymarket/agents/blob/main/agents/connectors/chroma.py"
    click NewsConn "https://github.com/Polymarket/agents/blob/main/agents/connectors/news.py"
    click SearchConn "https://github.com/Polymarket/agents/blob/main/agents/connectors/search.py"
    click Gamma "https://github.com/Polymarket/agents/blob/main/agents/polymarket/gamma.py"
    click UtilFuncs "https://github.com/Polymarket/agents/blob/main/agents/utils/utils.py"
    click DataObj "https://github.com/Polymarket/agents/blob/main/agents/utils/objects.py"
    click Cron "https://github.com/Polymarket/agents/blob/main/agents/application/cron.py"

    %% Legend
    subgraph Legend
        L1["Interface Components"]:::interface
        L2["Core Components"]:::core
        L3["Integration Layer"]:::integration
        L4["External Services"]:::external
        L5["Storage"]:::storage
        L6["Utilities"]:::utils
    end
```
