# gnosis/prediction-market-agent architecture

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

- Interactive diagram: https://gitdiagram.com/gnosis/prediction-market-agent
- Repository: https://github.com/gnosis/prediction-market-agent

## Overview

##### Main Components

a) Agent Layer:
- Multiple specialized agents (arbitrage, blockchain, coinflip, known outcome, etc.)
- Goal management system
- Agent communication system

b) Infrastructure Layer:
- Database systems (SQL, Pinecone for vector storage)
- External APIs integration
- Tools and Utilities

c) Market Integration Layer:
- Manifold Markets
- Presagio
- Polymarket
- Metaculus

##### Key Architectural Elements

**[User Interface Layer]**

- Streamlit Apps
- Command Line Interface

**[Agent Orchestration Layer]**

- Agent Manager
- Goal Manager
- Agent Communication

**[Core Agents]**

- Microchain Agent
- Prophet Agent
- Social Media Agent
- Other Specialized Agents

**[Tools & Services Layer]**

- Web Scraping
- Web Search
- LLM Integration
- Blockchain Tools

**[Data Persistence Layer]**

- SQL Database
- Pinecone Vector DB
- Long-term Memory

**[External Integration Layer]**

- Prediction Markets
- Social Media Platforms
- Blockchain Networks

##### Important Relationships to Highlight

- Blue: Data flow
- Green: API calls
- Red: Critical paths
- Purple: Event triggers

##### Technical Details

- Python 3.10+ environment
- Poetry dependency management
- Environment configuration requirements
- Docker containerization
- GitHub Actions CI/CD pipeline

##### Implementation Notes

- Use standardized UML notation where applicable
- Version information
- Document key configuration requirements
- Scalability points

##### Specific Components to Detail

a) Agent Framework:
**[Agent Base Class]**

- DeployableTraderAgent
- Specialized Agents
- CoinFlip Agent
- Known Outcome Agent
- Microchain Agent

- Agent Support Systems
- Goal Manager
- Memory Handler
- Communication System

b) Database Architecture:
**[Database Layer]**

- SQL Tables
- Evaluated Goals
- Long Term Memory
- Prompts

- Vector Storage
- Pinecone

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#e1f5fe,stroke:#01579b
    classDef agent fill:#e8f5e9,stroke:#2e7d32
    classDef infra fill:#fff3e0,stroke:#ff6f00
    classDef market fill:#f3e5f5,stroke:#7b1fa2
    classDef db fill:#fbe9e7,stroke:#d84315
    classDef tools fill:#f1f8e9,stroke:#33691e

    %% User Interface Layer
    subgraph UI["User Interface Layer"]
        StreamlitApps["Streamlit Apps"]
        CLI["Command Line Interface"]
    end

    %% Agent Orchestration Layer
    subgraph Orchestration["Agent Orchestration Layer"]
        AgentManager["Agent Manager"]
        GoalManager["Goal Manager"]
        AgentComm["Agent Communication"]
    end

    %% Core Agents Layer
    subgraph CoreAgents["Core Agents Layer"]
        MicrochainAgent["Microchain Agent"]
        ProphetAgent["Prophet Agent"]
        SocialMediaAgent["Social Media Agent"]
        MetaculusAgent["Metaculus Agent"]
        OmenAgent["Omen Agent"]
    end

    %% Tools & Services Layer
    subgraph Tools["Tools & Services Layer"]
        WebScraping["Web Scraping"]
        WebSearch["Web Search"]
        LLMIntegration["LLM Integration"]
        BlockchainTools["Blockchain Tools"]
    end

    %% Data Persistence Layer
    subgraph Data["Data Persistence Layer"]
        SQLDatabase["SQL Database"]
        PineconeDB["Pinecone Vector DB"]
        LongTermMemory["Long-term Memory"]
    end

    %% External Integration Layer
    subgraph External["External Integration Layer"]
        PredictionMarkets["Prediction Markets"]
        SocialPlatforms["Social Media Platforms"]
        BlockchainNetworks["Blockchain Networks"]
    end

    %% Relationships
    UI --> Orchestration
    Orchestration --> CoreAgents
    CoreAgents --> Tools
    Tools --> Data
    CoreAgents --> External
    Tools --> External

    %% Click Events
    click StreamlitApps "https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/tools/streamlit_utils.py"
    click CLI "https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/run_agent.py"
    click GoalManager "https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/agents/goal_manager.py"
    click AgentComm "https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/db/agent_communication.py"
    click MicrochainAgent "https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/agents/microchain_agent/"
    click ProphetAgent "https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/agents/prophet_agent/"
    click SocialMediaAgent "https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/agents/social_media_agent/"
    click MetaculusAgent "https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/agents/metaculus_agent/"
    click OmenAgent "https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/agents/omen_cleaner_agent/"
    click WebScraping "https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/tools/web_scrape/"
    click WebSearch "https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/tools/web_search/"
    click LLMIntegration "https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/tools/ollama_utils.py"
    click BlockchainTools "https://github.com/gnosis/prediction-market-agent/tree/main/prediction_market_agent/agents/microchain_agent/blockchain/"
    click SQLDatabase "https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/db/sql_handler.py"
    click PineconeDB "https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/db/pinecone_handler.py"
    click LongTermMemory "https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/db/long_term_memory_table_handler.py"

    %% Style Applications
    class StreamlitApps,CLI ui
    class AgentManager,GoalManager,AgentComm agent
    class MicrochainAgent,ProphetAgent,SocialMediaAgent,MetaculusAgent,OmenAgent agent
    class WebScraping,WebSearch,LLMIntegration,BlockchainTools tools
    class SQLDatabase,PineconeDB,LongTermMemory db
    class PredictionMarkets,SocialPlatforms,BlockchainNetworks market
```
