Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:HKUDS AI Trader Load Config

From Leeroopedia


Knowledge Sources
Domains Configuration, Software_Architecture
Last Updated 2026-02-09 14:00 GMT

Overview

Concrete tool for loading and parsing JSON configuration files for the trading agent system.

Description

The load_config function reads a JSON configuration file from disk and returns it as a Python dictionary. It defaults to configs/default_config.json if no path is provided. The function handles file-not-found and JSON parse errors by printing an error message and calling exit(1). It is the first function called in both the single-agent (main.py) and parallel (main_parrallel.py) entry points.

Usage

Call this function at application startup to load the agent configuration before creating agent instances. Both main.py and main_parrallel.py define their own load_config with identical behavior.

Code Reference

Source Location

  • Repository: AI-Trader
  • File: main.py
  • Lines: L76-106

Signature

def load_config(config_path=None):
    """
    Load configuration from JSON file.

    Args:
        config_path: Path to JSON config file (default: configs/default_config.json)

    Returns:
        dict: Parsed configuration dictionary

    Exits:
        Calls exit(1) on FileNotFoundError or JSONDecodeError
    """

Import

# Defined in main.py (not separately importable)
# Usage: called internally by main() function
from main import load_config  # or from main_parrallel import load_config

I/O Contract

Inputs

Name Type Required Description
config_path Optional[str] No Path to JSON config (default: configs/default_config.json)

Outputs

Name Type Description
config dict Parsed configuration with keys: agent_type, market, models, date_range, agent_config, log_config

Usage Examples

Load Default Config

config = load_config()
# Loads from configs/default_config.json

agent_type = config["agent_type"]  # e.g. "BaseAgent"
models = config["models"]  # List of model configurations
init_date = config["date_range"]["init_date"]

Load Custom Config

config = load_config("configs/astock_config.json")
# Loads A-share specific configuration

Related Pages

Requires Environment

Uses Heuristic

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment