# gta0804/mass architecture

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

- Interactive diagram: https://gitdiagram.com/gta0804/mass
- Repository: https://github.com/gta0804/mass

## Overview

MASS simulates heterogeneous investor agents to produce portfolio signals from market, fundamental, news, and macro inputs. The main workflow loads the stock universe and labels, configures and runs agents over dates, aggregates their decisions as disagreement signals, and evaluates the resulting signals; agent-distribution optimization is an additional training capability. The excerpts establish the entry point, trainer initialization and agent dispatch, and core aggregation/optimization behavior. Some agent-internal calls and data wiring are supported only by the source index or README, so uncertain links are omitted.

Main entry points: [`stock_disagreement/agent/basic_agent.py`](https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/basic_agent.py) (Investor agents), [`stock_disagreement/exp/trainer.py`](https://github.com/gta0804/mass/blob/main/stock_disagreement/exp/trainer.py) (Simulation trainer), [`stock_disagreement/main.py`](https://github.com/gta0804/mass/blob/main/stock_disagreement/main.py) (Run configuration), [`stock_disagreement/utils/llm.py`](https://github.com/gta0804/mass/blob/main/stock_disagreement/utils/llm.py) (LLM client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Simulation workflow"]
  node_entry["Run configuration<br/>[main.py]"]
  node_trainer["Simulation trainer<br/>[trainer.py]"]
  node_marketdata[("Market datasets")]
end

subgraph group_agents["Investor agents"]
  node_population["Investor agents<br/>[basic_agent.py]"]
  node_modalities["Data modalities<br/>[basic_agent.py]"]
  node_macro["Macro context<br/>[basic_agent.py]"]
  node_selector["Stock selectors<br/>[stock_selector.py]"]
  node_history["Decision history"]
end

subgraph group_signals["Signal and optimization"]
  node_aggregation["Disagreement analyzer"]
  node_optimizer["Distribution optimizer"]
  node_results["Portfolio signals<br/>[trainer.py]"]
  node_evaluation["Signal evaluation<br/>[main.py]"]
end

subgraph group_interfaces["Prompts and model"]
  node_prompt["Investment prompts<br/>[prompt_template.py]"]
  node_llmclient["LLM client<br/>[llm.py]"]
end

node_user(("Researcher"))
node_llmservice{{"OpenAI API"}}

node_user -->|"runs"| node_entry
node_entry -->|"loads inputs"| node_marketdata
node_entry -->|"configures"| node_trainer
node_trainer -->|"loads datasets"| node_marketdata
node_trainer -->|"initializes agents"| node_population
node_trainer -->|"dispatches investment"| node_population
node_population -->|"selects inputs"| node_modalities
node_population -->|"formats context"| node_macro
node_population -->|"uses selection strategies"| node_selector
node_population -->|"records decisions"| node_history
node_population -->|"uses templates"| node_prompt
node_population -->|"generates responses"| node_llmclient
node_llmclient -->|"sends chat requests"| node_llmservice
node_trainer -->|"uses analyzer"| node_aggregation
node_trainer -->|"configures optimizer"| node_optimizer
node_trainer -.->|"produces signals"| node_results
node_entry -->|"evaluates results"| node_evaluation
node_entry -->|"saves outputs"| node_results

click node_entry "https://github.com/gta0804/mass/blob/main/stock_disagreement/main.py"
click node_trainer "https://github.com/gta0804/mass/blob/main/stock_disagreement/exp/trainer.py"
click node_marketdata "https://github.com/gta0804/mass/tree/main/stock_disagreement/dataset"
click node_population "https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/basic_agent.py"
click node_modalities "https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/basic_agent.py"
click node_macro "https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/basic_agent.py"
click node_selector "https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/stock_selector.py"
click node_history "https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/investing_history.py"
click node_prompt "https://github.com/gta0804/mass/blob/main/stock_disagreement/prompts/prompt_template.py"
click node_llmclient "https://github.com/gta0804/mass/blob/main/stock_disagreement/utils/llm.py"
click node_aggregation "https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/investment_analyzer.py"
click node_optimizer "https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/agent_distribution.py"
click node_results "https://github.com/gta0804/mass/blob/main/stock_disagreement/exp/trainer.py"
click node_evaluation "https://github.com/gta0804/mass/blob/main/stock_disagreement/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_trainer,node_marketdata toneBlue
class node_population,node_modalities,node_macro,node_selector,node_history toneAmber
class node_aggregation,node_optimizer,node_results,node_evaluation,node_llmservice toneMint
class node_prompt,node_llmclient toneRose
class node_user toneIndigo
```

## Components

### Simulation workflow

- [Run configuration](https://github.com/gta0804/mass/blob/main/stock_disagreement/main.py): `stock_disagreement/main.py`
- [Simulation trainer](https://github.com/gta0804/mass/blob/main/stock_disagreement/exp/trainer.py): `stock_disagreement/exp/trainer.py`
- [Market datasets](https://github.com/gta0804/mass/tree/main/stock_disagreement/dataset): `stock_disagreement/dataset`

### Investor agents

- [Investor agents](https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/basic_agent.py): `stock_disagreement/agent/basic_agent.py`
- [Data modalities](https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/basic_agent.py): `stock_disagreement/agent/basic_agent.py`
- [Macro context](https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/basic_agent.py): `stock_disagreement/agent/basic_agent.py`
- [Stock selectors](https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/stock_selector.py): `stock_disagreement/agent/stock_selector.py`
- [Decision history](https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/investing_history.py): `stock_disagreement/agent/investing_history.py`

### Signal and optimization

- [Disagreement analyzer](https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/investment_analyzer.py): `stock_disagreement/agent/investment_analyzer.py`
- [Distribution optimizer](https://github.com/gta0804/mass/blob/main/stock_disagreement/agent/agent_distribution.py): `stock_disagreement/agent/agent_distribution.py`
- [Portfolio signals](https://github.com/gta0804/mass/blob/main/stock_disagreement/exp/trainer.py): `stock_disagreement/exp/trainer.py`
- [Signal evaluation](https://github.com/gta0804/mass/blob/main/stock_disagreement/main.py): `stock_disagreement/main.py`

### Prompts and model

- [Investment prompts](https://github.com/gta0804/mass/blob/main/stock_disagreement/prompts/prompt_template.py): `stock_disagreement/prompts/prompt_template.py`
- [LLM client](https://github.com/gta0804/mass/blob/main/stock_disagreement/utils/llm.py): `stock_disagreement/utils/llm.py`

### Other components

- **Researcher**
- **OpenAI API**

## Connections

- Researcher → Run configuration: runs (evidence: `README.md`)
- Run configuration → Market datasets: loads inputs (evidence: `stock_disagreement/main.py`)
- Run configuration → Simulation trainer: configures (evidence: `stock_disagreement/main.py`)
- Simulation trainer → Market datasets: loads datasets (evidence: `stock_disagreement/exp/trainer.py`)
- Simulation trainer → Investor agents: initializes agents (evidence: `stock_disagreement/exp/trainer.py`)
- Simulation trainer → Investor agents: dispatches investment (evidence: `stock_disagreement/exp/trainer.py`)
- Investor agents → Data modalities: selects inputs (evidence: `stock_disagreement/agent/basic_agent.py`)
- Investor agents → Macro context: formats context (evidence: `stock_disagreement/agent/basic_agent.py`)
- Investor agents → Stock selectors: uses selection strategies (evidence: `stock_disagreement/agent/basic_agent.py`)
- Investor agents → Decision history: records decisions (evidence: `stock_disagreement/agent/basic_agent.py`)
- Investor agents → Investment prompts: uses templates (evidence: `stock_disagreement/agent/basic_agent.py`)
- Investor agents → LLM client: generates responses (evidence: `stock_disagreement/agent/basic_agent.py`)
- LLM client → OpenAI API: sends chat requests (evidence: `stock_disagreement/utils/llm.py`)
- Simulation trainer → Disagreement analyzer: uses analyzer (evidence: `stock_disagreement/exp/trainer.py`)
- Simulation trainer → Distribution optimizer: configures optimizer (evidence: `stock_disagreement/exp/trainer.py`)
- Simulation trainer → Portfolio signals: produces signals (evidence: `stock_disagreement/exp/trainer.py`)
- Run configuration → Signal evaluation: evaluates results (evidence: `stock_disagreement/main.py`)
- Run configuration → Portfolio signals: saves outputs (evidence: `stock_disagreement/main.py`)
