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.

Principle:HKUDS AI Trader Agent Class Resolution

From Leeroopedia


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

Overview

A dynamic dispatch pattern that resolves agent class names to their implementations at runtime using a registry and dynamic imports.

Description

Agent Class Resolution uses a registry-based factory pattern combined with Python's dynamic import system to resolve string-based agent type names (e.g., "BaseAgent", "BaseAgentCrypto") to their actual Python classes at runtime. This decouples the entry point from specific agent implementations, allowing the system to support multiple market-specific agent types without modifying the launcher code.

The pattern addresses the need to select different agent implementations based on configuration, where each market (US stocks, A-shares, crypto) and frequency (daily, hourly) has its own agent class with market-specific trading rules.

Usage

Use this principle when the application needs to instantiate different agent classes based on a string identifier from configuration. It is the bridge between the configuration system and the agent initialization step.

Theoretical Basis

# Pseudocode for registry-based class resolution
AGENT_REGISTRY = {
    "BaseAgent":       {"module": "agent.base_agent.base_agent",       "class": "BaseAgent"},
    "BaseAgentCrypto": {"module": "agent.base_agent_crypto.base_agent_crypto", "class": "BaseAgentCrypto"},
    ...
}

def resolve_agent_class(agent_type: str) -> type:
    entry = AGENT_REGISTRY[agent_type]
    module = importlib.import_module(entry["module"])
    return getattr(module, entry["class"])

Key properties:

  • Lazy loading: Agent modules are only imported when needed
  • Extensible: New agent types can be added to the registry without changing resolution logic
  • Fail-fast: Invalid agent types raise ValueError immediately

Related Pages

Implemented By

Page Connections

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