# alejandroll10/llm_trading_sim architecture

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

- Interactive diagram: https://gitdiagram.com/alejandroll10/llm_trading_sim
- Repository: https://github.com/alejandroll10/llm_trading_sim

## Overview

This is an agent-based financial-market simulation for studying LLM trading behavior and market dynamics. Its main workflow configures a scenario, gives heterogeneous agents market information and trading decisions, matches submitted orders into trades, and records results for analysis and visualization. The README also documents multi-stock and stress scenarios, robustness sweeps, prompt variants, estimators, and plots. Several runtime modules are represented from the source index and README rather than inspected excerpts, so uncertain connections are omitted or marked dashed.

Main entry points: [`src/agents/base_agent.py`](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/base_agent.py) (Agent state and behavior), [`src/base_sim.py`](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/base_sim.py) (Simulation runtime), [`src/market/engine/match_engine.py`](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/engine/match_engine.py) (Order matching), [`src/agents/agent_manager/agent_repository.py`](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/agent_manager/agent_repository.py) (Agent repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experiments["Experiments"]
  node_scenario["Scenario configuration<br/>[base.py]"]
  node_scenario_catalog["Scenario designs"]
  node_simulation["Simulation runtime<br/>[base_sim.py]"]
end

subgraph group_agents["Trading agents"]
  node_agent_types["Agent decision schema<br/>[agent_types.py]"]
  node_agent_api["Structured trade decisions<br/>[agents_api.py]"]
  node_agent["Agent state and behavior<br/>[base_agent.py]"]
  node_agent_repository["Agent repository"]
  node_deterministic_agents["Rule-based strategies"]
  node_llm_agent["LLM trading agent<br/>[llm_agent.py]"]
  node_prompt_schema["Prompt and output features<br/>[schema_features.py]"]
  node_llm_service["LLM requests<br/>[llm_services.py]"]
end

subgraph group_information["Market information"]
  node_information_service["Information distribution"]
  node_information_types["Signals and capabilities"]
end

subgraph group_market["Market execution"]
  node_orders["Orders and commitments<br/>[order.py]"]
  node_matching["Order matching<br/>[match_engine.py]"]
  node_trade["Executed trades<br/>[trade.py]"]
  node_market_state["Market state"]
end

subgraph group_results["Results and analysis"]
  node_logging["Simulation logging<br/>[logging_service.py]"]
  node_log_models["Log records<br/>[logging_models.py]"]
  node_estimators["Research estimators"]
  node_visualization["Result plots<br/>[plot_generator.py]"]
end

node_researcher(("Researcher"))
node_llm_provider["LLM provider"]

node_researcher -->|"selects scenario"| node_scenario_catalog
node_scenario_catalog -.->|"configures"| node_scenario
node_scenario -.->|"sets parameters"| node_simulation
node_simulation -.->|"runs agents"| node_agent
node_simulation -.->|"updates information"| node_information_service
node_simulation -.->|"submits orders"| node_matching
node_agent -->|"uses decisions"| node_agent_api
node_agent_api -->|"defines types"| node_agent_types
node_deterministic_agents -.->|"extends behavior"| node_agent
node_llm_agent -->|"extends behavior"| node_agent
node_llm_agent -->|"requests completion"| node_llm_service
node_llm_agent -->|"uses features"| node_prompt_schema
node_llm_service -->|"sends request"| node_llm_provider
node_scenario -->|"configures endpoint"| node_llm_service
node_information_service -->|"builds signals"| node_information_types
node_information_service -.->|"distributes signals"| node_agent
node_agent_repository -->|"stores agents"| node_agent
node_matching -->|"processes orders"| node_orders
node_matching -->|"processes trades"| node_trade
node_agent_repository -->|"reads order data"| node_orders
node_agent_repository -->|"records trade"| node_trade
node_simulation -.->|"updates market"| node_market_state
node_matching -->|"logs market state"| node_logging
node_agent -->|"logs agent state"| node_logging
node_logging -->|"creates records"| node_log_models
node_researcher -->|"runs estimates"| node_estimators
node_estimators -.->|"produces figures"| node_visualization
node_researcher -->|"views results"| node_visualization

click node_scenario "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/scenarios/base.py"
click node_scenario_catalog "https://github.com/alejandroll10/llm_trading_sim/tree/main/src/scenarios"
click node_simulation "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/base_sim.py"
click node_agent_types "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/agent_types.py"
click node_agent_api "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/agents_api.py"
click node_agent "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/base_agent.py"
click node_agent_repository "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/agent_manager/agent_repository.py"
click node_deterministic_agents "https://github.com/alejandroll10/llm_trading_sim/tree/main/src/agents/deterministic"
click node_llm_agent "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/LLMs/llm_agent.py"
click node_prompt_schema "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/LLMs/services/schema_features.py"
click node_llm_service "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/LLMs/services/llm_services.py"
click node_information_service "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/information/base_information_services.py"
click node_information_types "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/information/information_types.py"
click node_orders "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/orders/order.py"
click node_matching "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/engine/match_engine.py"
click node_trade "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/trade.py"
click node_market_state "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/state/market_state_manager.py"
click node_logging "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/services/logging_service.py"
click node_log_models "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/services/logging_models.py"
click node_estimators "https://github.com/alejandroll10/llm_trading_sim/tree/main/src/analysis"
click node_visualization "https://github.com/alejandroll10/llm_trading_sim/blob/main/src/visualization/plot_generator.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_scenario,node_scenario_catalog,node_simulation toneBlue
class node_agent_types,node_agent_api,node_agent,node_agent_repository,node_deterministic_agents,node_llm_agent,node_prompt_schema,node_llm_service toneAmber
class node_information_service,node_information_types toneMint
class node_orders,node_matching,node_trade,node_market_state toneRose
class node_logging,node_log_models,node_estimators,node_visualization,node_researcher,node_llm_provider toneIndigo
```

## Components

### Experiments

- [Scenario configuration](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/scenarios/base.py): `src/scenarios/base.py`
- [Scenario designs](https://github.com/alejandroll10/llm_trading_sim/tree/main/src/scenarios): `src/scenarios`
- [Simulation runtime](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/base_sim.py): `src/base_sim.py`

### Trading agents

- [Agent decision schema](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/agent_types.py): `src/agents/agent_types.py`
- [Structured trade decisions](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/agents_api.py): `src/agents/agents_api.py`
- [Agent state and behavior](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/base_agent.py): `src/agents/base_agent.py`
- [Agent repository](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/agent_manager/agent_repository.py): `src/agents/agent_manager/agent_repository.py`
- [Rule-based strategies](https://github.com/alejandroll10/llm_trading_sim/tree/main/src/agents/deterministic): `src/agents/deterministic`
- [LLM trading agent](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/LLMs/llm_agent.py): `src/agents/LLMs/llm_agent.py`
- [Prompt and output features](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/LLMs/services/schema_features.py): `src/agents/LLMs/services/schema_features.py`
- [LLM requests](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/agents/LLMs/services/llm_services.py): `src/agents/LLMs/services/llm_services.py`

### Market information

- [Information distribution](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/information/base_information_services.py): `src/market/information/base_information_services.py`
- [Signals and capabilities](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/information/information_types.py): `src/market/information/information_types.py`

### Market execution

- [Orders and commitments](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/orders/order.py): `src/market/orders/order.py`
- [Order matching](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/engine/match_engine.py): `src/market/engine/match_engine.py`
- [Executed trades](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/trade.py): `src/market/trade.py`
- [Market state](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/market/state/market_state_manager.py): `src/market/state/market_state_manager.py`

### Results and analysis

- [Simulation logging](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/services/logging_service.py): `src/services/logging_service.py`
- [Log records](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/services/logging_models.py): `src/services/logging_models.py`
- [Research estimators](https://github.com/alejandroll10/llm_trading_sim/tree/main/src/analysis): `src/analysis`
- [Result plots](https://github.com/alejandroll10/llm_trading_sim/blob/main/src/visualization/plot_generator.py): `src/visualization/plot_generator.py`

### Other components

- **Researcher**
- **LLM provider**

## Connections

- Researcher → Scenario designs: selects scenario (evidence: `README.md`)
- Scenario designs → Scenario configuration: configures (evidence: `src/scenarios/multi_stock.py`)
- Scenario configuration → Simulation runtime: sets parameters
- Simulation runtime → Agent state and behavior: runs agents
- Simulation runtime → Information distribution: updates information
- Simulation runtime → Order matching: submits orders
- Agent state and behavior → Structured trade decisions: uses decisions (evidence: `src/agents/base_agent.py`)
- Structured trade decisions → Agent decision schema: defines types (evidence: `src/agents/agents_api.py`)
- Rule-based strategies → Agent state and behavior: extends behavior
- LLM trading agent → Agent state and behavior: extends behavior (evidence: `src/agents/LLMs/llm_agent.py`)
- LLM trading agent → LLM requests: requests completion (evidence: `src/agents/LLMs/llm_agent.py`)
- LLM trading agent → Prompt and output features: uses features (evidence: `src/agents/LLMs/llm_agent.py`)
- LLM requests → LLM provider: sends request (evidence: `src/agents/LLMs/services/llm_services.py`)
- Scenario configuration → LLM requests: configures endpoint (evidence: `src/agents/LLMs/services/llm_services.py`)
- Information distribution → Signals and capabilities: builds signals (evidence: `src/market/information/base_information_services.py`)
- Information distribution → Agent state and behavior: distributes signals
- Agent repository → Agent state and behavior: stores agents (evidence: `src/agents/agent_manager/agent_repository.py`)
- Order matching → Orders and commitments: processes orders (evidence: `src/market/engine/match_engine.py`)
- Order matching → Executed trades: processes trades (evidence: `src/market/engine/match_engine.py`)
- Agent repository → Orders and commitments: reads order data (evidence: `src/agents/agent_manager/agent_repository.py`)
- Agent repository → Executed trades: records trade (evidence: `src/agents/agent_manager/agent_repository.py`)
- Simulation runtime → Market state: updates market
- Order matching → Simulation logging: logs market state (evidence: `src/market/engine/match_engine.py`)
- Agent state and behavior → Simulation logging: logs agent state (evidence: `src/agents/base_agent.py`)
- Simulation logging → Log records: creates records (evidence: `src/services/logging_service.py`)
- Researcher → Research estimators: runs estimates (evidence: `README.md`)
- Research estimators → Result plots: produces figures
- Researcher → Result plots: views results (evidence: `README.md`)
