# cmirlop/agenttrading architecture

> Architecture diagram of the GitHub repository cmirlop/agenttrading, 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/cmirlop/agenttrading
- Repository: https://github.com/cmirlop/agenttrading

## Overview

AgentTrading is a Forex trading-agent system with live/dry-run analysis and historical research workflows. The clearest sampled live path is the dry-run pipeline: it checks broker/session and candidate eligibility, loads market state, builds a trade plan, and validates an order without enabling Python trading. Historical replay and backtesting are distinct product branches. The README gives no further capability details; unsampled modules are included where the source index identifies major components, but their internal behavior and some connections remain unverified.

Main entry points: [`src/orchestration/orchestrator.py`](https://github.com/cmirlop/agenttrading/blob/main/src/orchestration/orchestrator.py) (Agent Orchestrator), [`run_dry_pipeline.py`](https://github.com/cmirlop/agenttrading/blob/main/run_dry_pipeline.py) (Dry-run Pipeline), [`run_multiagent_historical_replay.py`](https://github.com/cmirlop/agenttrading/blob/main/run_multiagent_historical_replay.py) (Multi-agent Replay), [`run_stateful_backtest.py`](https://github.com/cmirlop/agenttrading/blob/main/run_stateful_backtest.py) (Stateful Backtest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_live["Live Trading"]
  node_dryrun["Dry-run Pipeline"]
  node_session["Session Gate<br/>[session_gate.py]"]
  node_candidate["Candidate Gate<br/>[candidate_gate.py]"]
  node_planner["Trade Planner<br/>[trade_planner.py]"]
  node_validator["Risk Validator<br/>[risk_validator.py]"]
end

subgraph group_agents["Agent Analysis"]
  node_orchestrator["Agent Orchestrator<br/>[orchestrator.py]"]
  node_context["Decision Context"]
  node_bus["Agent Bus<br/>[agent_bus.py]"]
  node_regime["Regime Agent<br/>[regime_agent.py]"]
  node_strategy["Strategy Agent<br/>[strategy_agent.py]"]
  node_critic["Critic Agent<br/>[critic_agent.py]"]
  node_decision["Decision Agent<br/>[decision_agent.py]"]
  node_llm["Structured LLM Client<br/>[llm_client.py]"]
end

subgraph group_history["Historical Research"]
  node_historyplanner["Historical Trade Planner"]
  node_execution["Historical Execution"]
  node_risk["Historical Risk<br/>[historical_risk.py]"]
  node_replay["Multi-agent Replay"]
  node_backtest["Stateful Backtest"]
  node_scan["Candidate Scan"]
end

subgraph group_market["Market Data"]
  node_snapshot["Market Snapshot<br/>[market_snapshot.py]"]
  node_marketstate["Historical Market State"]
  node_technical["Technical Evaluator"]
  node_levels["Support Resistance"]
  node_levelaction["Level Price Action"]
  node_calendar["Calendar Gate<br/>[calendar_gate.py]"]
end

subgraph group_policy["Configuration"]
  node_agentconfig["Agent Configuration<br/>[agent_config.py]"]
  node_backtestconfig["Backtest Configuration<br/>[backtest_config.py]"]
  node_marketconfig["Market Configuration<br/>[market_config.py]"]
  node_operational["Operational Configuration"]
  node_riskconfig["Risk Configuration<br/>[risk_config.py]"]
  node_plannerconfig["Planner Configuration"]
end

node_operator(("Operator"))
node_mt5{{"MetaTrader 5"}}

node_operator -->|"starts"| node_dryrun
node_dryrun -->|"checks account"| node_mt5
node_dryrun -->|"builds session"| node_session
node_dryrun -->|"checks candidate"| node_candidate
node_dryrun -->|"builds plan"| node_planner
node_dryrun -->|"validates order"| node_validator
node_dryrun -->|"checks order"| node_mt5
node_orchestrator -->|"creates context"| node_context
node_orchestrator -->|"publishes messages"| node_bus
node_orchestrator -->|"builds snapshot"| node_snapshot
node_orchestrator -->|"dispatches analysis"| node_regime
node_orchestrator -->|"dispatches analysis"| node_strategy
node_orchestrator -->|"invokes on approval"| node_critic
node_orchestrator -->|"requests decision"| node_decision
node_regime -->|"requests assessment"| node_llm
node_replay -->|"loads state"| node_marketstate
node_replay -->|"plans trades"| node_historyplanner
node_replay -->|"simulates execution"| node_execution
node_replay -->|"evaluates risk"| node_risk
node_replay -.->|"runs agents"| node_orchestrator
node_backtest -->|"loads state"| node_marketstate
node_backtest -->|"plans trades"| node_historyplanner
node_backtest -->|"simulates execution"| node_execution
node_backtest -->|"evaluates risk"| node_risk
node_scan -->|"loads state"| node_marketstate
node_scan -->|"builds snapshot"| node_snapshot
node_scan -->|"evaluates technicals"| node_technical
node_scan -->|"checks session"| node_session
node_session -->|"reads settings"| node_operational
node_llm -->|"reads model settings"| node_agentconfig
node_marketstate -->|"reads market settings"| node_marketconfig
node_historyplanner -->|"reads plan settings"| node_plannerconfig
node_risk -->|"reads risk settings"| node_riskconfig
node_backtest -.->|"uses evaluation settings"| node_backtestconfig
node_orchestrator -.-> node_levels
node_orchestrator -.-> node_levelaction
node_dryrun -->|"reads calendar state"| node_calendar

click node_dryrun "https://github.com/cmirlop/agenttrading/blob/main/run_dry_pipeline.py"
click node_session "https://github.com/cmirlop/agenttrading/blob/main/src/session_gate.py"
click node_candidate "https://github.com/cmirlop/agenttrading/blob/main/src/candidate_gate.py"
click node_planner "https://github.com/cmirlop/agenttrading/blob/main/src/trade_planner.py"
click node_validator "https://github.com/cmirlop/agenttrading/blob/main/src/risk_validator.py"
click node_orchestrator "https://github.com/cmirlop/agenttrading/blob/main/src/orchestration/orchestrator.py"
click node_context "https://github.com/cmirlop/agenttrading/blob/main/src/orchestration/decision_context.py"
click node_bus "https://github.com/cmirlop/agenttrading/blob/main/src/orchestration/agent_bus.py"
click node_regime "https://github.com/cmirlop/agenttrading/blob/main/src/agents/regime_agent.py"
click node_strategy "https://github.com/cmirlop/agenttrading/blob/main/src/agents/strategy_agent.py"
click node_critic "https://github.com/cmirlop/agenttrading/blob/main/src/agents/critic_agent.py"
click node_decision "https://github.com/cmirlop/agenttrading/blob/main/src/agents/decision_agent.py"
click node_llm "https://github.com/cmirlop/agenttrading/blob/main/src/agents/llm_client.py"
click node_snapshot "https://github.com/cmirlop/agenttrading/blob/main/src/market_snapshot.py"
click node_marketstate "https://github.com/cmirlop/agenttrading/blob/main/src/historical_state.py"
click node_technical "https://github.com/cmirlop/agenttrading/blob/main/src/technical_evaluator.py"
click node_levels "https://github.com/cmirlop/agenttrading/blob/main/src/support_resistance.py"
click node_levelaction "https://github.com/cmirlop/agenttrading/blob/main/src/level_price_action.py"
click node_calendar "https://github.com/cmirlop/agenttrading/blob/main/src/calendar_gate.py"
click node_historyplanner "https://github.com/cmirlop/agenttrading/blob/main/src/historical_trade_planner.py"
click node_execution "https://github.com/cmirlop/agenttrading/blob/main/src/historical_execution.py"
click node_risk "https://github.com/cmirlop/agenttrading/blob/main/src/historical_risk.py"
click node_replay "https://github.com/cmirlop/agenttrading/blob/main/run_multiagent_historical_replay.py"
click node_backtest "https://github.com/cmirlop/agenttrading/blob/main/run_stateful_backtest.py"
click node_scan "https://github.com/cmirlop/agenttrading/blob/main/scan_backtest_candidates.py"
click node_agentconfig "https://github.com/cmirlop/agenttrading/blob/main/config/agent_config.py"
click node_backtestconfig "https://github.com/cmirlop/agenttrading/blob/main/config/backtest_config.py"
click node_marketconfig "https://github.com/cmirlop/agenttrading/blob/main/config/market_config.py"
click node_operational "https://github.com/cmirlop/agenttrading/blob/main/config/operational_config.py"
click node_riskconfig "https://github.com/cmirlop/agenttrading/blob/main/config/risk_config.py"
click node_plannerconfig "https://github.com/cmirlop/agenttrading/blob/main/config/trade_planner_config.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_dryrun,node_session,node_candidate,node_planner,node_validator toneBlue
class node_orchestrator,node_context,node_bus,node_regime,node_strategy,node_critic,node_decision,node_llm toneAmber
class node_historyplanner,node_execution,node_risk,node_replay,node_backtest,node_scan toneMint
class node_snapshot,node_marketstate,node_technical,node_levels,node_levelaction,node_calendar toneRose
class node_agentconfig,node_backtestconfig,node_marketconfig,node_operational,node_riskconfig,node_plannerconfig,node_operator,node_mt5 toneIndigo
```

## Components

### Live Trading

- [Dry-run Pipeline](https://github.com/cmirlop/agenttrading/blob/main/run_dry_pipeline.py): `run_dry_pipeline.py`
- [Session Gate](https://github.com/cmirlop/agenttrading/blob/main/src/session_gate.py): `src/session_gate.py`
- [Candidate Gate](https://github.com/cmirlop/agenttrading/blob/main/src/candidate_gate.py): `src/candidate_gate.py`
- [Trade Planner](https://github.com/cmirlop/agenttrading/blob/main/src/trade_planner.py): `src/trade_planner.py`
- [Risk Validator](https://github.com/cmirlop/agenttrading/blob/main/src/risk_validator.py): `src/risk_validator.py`

### Agent Analysis

- [Agent Orchestrator](https://github.com/cmirlop/agenttrading/blob/main/src/orchestration/orchestrator.py): `src/orchestration/orchestrator.py`
- [Decision Context](https://github.com/cmirlop/agenttrading/blob/main/src/orchestration/decision_context.py): `src/orchestration/decision_context.py`
- [Agent Bus](https://github.com/cmirlop/agenttrading/blob/main/src/orchestration/agent_bus.py): `src/orchestration/agent_bus.py`
- [Regime Agent](https://github.com/cmirlop/agenttrading/blob/main/src/agents/regime_agent.py): `src/agents/regime_agent.py`
- [Strategy Agent](https://github.com/cmirlop/agenttrading/blob/main/src/agents/strategy_agent.py): `src/agents/strategy_agent.py`
- [Critic Agent](https://github.com/cmirlop/agenttrading/blob/main/src/agents/critic_agent.py): `src/agents/critic_agent.py`
- [Decision Agent](https://github.com/cmirlop/agenttrading/blob/main/src/agents/decision_agent.py): `src/agents/decision_agent.py`
- [Structured LLM Client](https://github.com/cmirlop/agenttrading/blob/main/src/agents/llm_client.py): `src/agents/llm_client.py`

### Historical Research

- [Historical Trade Planner](https://github.com/cmirlop/agenttrading/blob/main/src/historical_trade_planner.py): `src/historical_trade_planner.py`
- [Historical Execution](https://github.com/cmirlop/agenttrading/blob/main/src/historical_execution.py): `src/historical_execution.py`
- [Historical Risk](https://github.com/cmirlop/agenttrading/blob/main/src/historical_risk.py): `src/historical_risk.py`
- [Multi-agent Replay](https://github.com/cmirlop/agenttrading/blob/main/run_multiagent_historical_replay.py): `run_multiagent_historical_replay.py`
- [Stateful Backtest](https://github.com/cmirlop/agenttrading/blob/main/run_stateful_backtest.py): `run_stateful_backtest.py`
- [Candidate Scan](https://github.com/cmirlop/agenttrading/blob/main/scan_backtest_candidates.py): `scan_backtest_candidates.py`

### Market Data

- [Market Snapshot](https://github.com/cmirlop/agenttrading/blob/main/src/market_snapshot.py): `src/market_snapshot.py`
- [Historical Market State](https://github.com/cmirlop/agenttrading/blob/main/src/historical_state.py): `src/historical_state.py`
- [Technical Evaluator](https://github.com/cmirlop/agenttrading/blob/main/src/technical_evaluator.py): `src/technical_evaluator.py`
- [Support Resistance](https://github.com/cmirlop/agenttrading/blob/main/src/support_resistance.py): `src/support_resistance.py`
- [Level Price Action](https://github.com/cmirlop/agenttrading/blob/main/src/level_price_action.py): `src/level_price_action.py`
- [Calendar Gate](https://github.com/cmirlop/agenttrading/blob/main/src/calendar_gate.py): `src/calendar_gate.py`

### Configuration

- [Agent Configuration](https://github.com/cmirlop/agenttrading/blob/main/config/agent_config.py): `config/agent_config.py`
- [Backtest Configuration](https://github.com/cmirlop/agenttrading/blob/main/config/backtest_config.py): `config/backtest_config.py`
- [Market Configuration](https://github.com/cmirlop/agenttrading/blob/main/config/market_config.py): `config/market_config.py`
- [Operational Configuration](https://github.com/cmirlop/agenttrading/blob/main/config/operational_config.py): `config/operational_config.py`
- [Risk Configuration](https://github.com/cmirlop/agenttrading/blob/main/config/risk_config.py): `config/risk_config.py`
- [Planner Configuration](https://github.com/cmirlop/agenttrading/blob/main/config/trade_planner_config.py): `config/trade_planner_config.py`

### Other components

- **Operator**
- **MetaTrader 5**

## Connections

- Operator → Dry-run Pipeline: starts
- Dry-run Pipeline → MetaTrader 5: checks account (evidence: `run_dry_pipeline.py`)
- Dry-run Pipeline → Session Gate: builds session (evidence: `run_dry_pipeline.py`)
- Dry-run Pipeline → Candidate Gate: checks candidate (evidence: `run_dry_pipeline.py`)
- Dry-run Pipeline → Trade Planner: builds plan (evidence: `run_dry_pipeline.py`)
- Dry-run Pipeline → Risk Validator: validates order (evidence: `run_dry_pipeline.py`)
- Dry-run Pipeline → MetaTrader 5: checks order (evidence: `run_dry_pipeline.py`)
- Agent Orchestrator → Decision Context: creates context (evidence: `src/orchestration/orchestrator.py`)
- Agent Orchestrator → Agent Bus: publishes messages (evidence: `src/orchestration/orchestrator.py`)
- Agent Orchestrator → Market Snapshot: builds snapshot (evidence: `src/orchestration/orchestrator.py`)
- Agent Orchestrator → Regime Agent: dispatches analysis (evidence: `src/orchestration/orchestrator.py`)
- Agent Orchestrator → Strategy Agent: dispatches analysis (evidence: `src/orchestration/orchestrator.py`)
- Agent Orchestrator → Critic Agent: invokes on approval (evidence: `src/orchestration/orchestrator.py`)
- Agent Orchestrator → Decision Agent: requests decision (evidence: `src/orchestration/orchestrator.py`)
- Regime Agent → Structured LLM Client: requests assessment (evidence: `src/agents/regime_agent.py`)
- Multi-agent Replay → Historical Market State: loads state (evidence: `run_multiagent_historical_replay.py`)
- Multi-agent Replay → Historical Trade Planner: plans trades (evidence: `run_multiagent_historical_replay.py`)
- Multi-agent Replay → Historical Execution: simulates execution (evidence: `run_multiagent_historical_replay.py`)
- Multi-agent Replay → Historical Risk: evaluates risk (evidence: `run_multiagent_historical_replay.py`)
- Multi-agent Replay → Agent Orchestrator: runs agents
- Stateful Backtest → Historical Market State: loads state (evidence: `run_stateful_backtest.py`)
- Stateful Backtest → Historical Trade Planner: plans trades (evidence: `run_stateful_backtest.py`)
- Stateful Backtest → Historical Execution: simulates execution (evidence: `run_stateful_backtest.py`)
- Stateful Backtest → Historical Risk: evaluates risk (evidence: `run_stateful_backtest.py`)
- Candidate Scan → Historical Market State: loads state (evidence: `scan_backtest_candidates.py`)
- Candidate Scan → Market Snapshot: builds snapshot (evidence: `scan_backtest_candidates.py`)
- Candidate Scan → Technical Evaluator: evaluates technicals (evidence: `scan_backtest_candidates.py`)
- Candidate Scan → Session Gate: checks session (evidence: `scan_backtest_candidates.py`)
- Session Gate → Operational Configuration: reads settings (evidence: `src/session_gate.py`)
- Structured LLM Client → Agent Configuration: reads model settings (evidence: `src/agents/llm_client.py`)
- Historical Market State → Market Configuration: reads market settings (evidence: `src/historical_state.py`)
- Historical Trade Planner → Planner Configuration: reads plan settings (evidence: `src/historical_trade_planner.py`)
- Historical Risk → Risk Configuration: reads risk settings (evidence: `src/historical_risk.py`)
- Stateful Backtest → Backtest Configuration: uses evaluation settings (evidence: `run_stateful_backtest.py`)
- Agent Orchestrator → Support Resistance
- Agent Orchestrator → Level Price Action
- Dry-run Pipeline → Calendar Gate: reads calendar state (evidence: `run_dry_pipeline.py`)
