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.

Environment:HKUDS AI Trader Python LangChain Runtime

From Leeroopedia


Knowledge Sources
Domains Infrastructure, LLM_Agents
Last Updated 2026-02-09 14:00 GMT

Overview

Python 3.10+ runtime environment with LangChain 1.0.2, langchain-openai 1.0.1, FastMCP 2.12.5, and scientific computing libraries (numpy, pandas, matplotlib) for LLM-powered trading agent execution.

Description

This environment provides the core Python runtime and dependency stack for the AI-Trader system. It includes the LangChain agent framework for orchestrating LLM-based trading decisions, the FastMCP library for Model Context Protocol tool servers, and data processing libraries for market data handling and performance visualization. The system uses an OpenAI-compatible API interface, supporting multiple LLM providers (OpenAI, Anthropic, DeepSeek, Qwen, Google) through configurable base URLs.

Usage

Use this environment for all AI-Trader operations including data fetching, agent trading sessions, metrics calculation, and performance visualization. This is the mandatory base environment for every workflow in the system.

System Requirements

Category Requirement Notes
OS Linux / macOS / Windows (WSL2) Tested on Linux; fcntl-based file locking requires POSIX
Hardware CPU-only No GPU required; LLM inference is remote via API
Python Python 3.10+ Required for type hint syntax (tuple[str, str])
Disk 500MB+ For price data JSON files and agent logs
Network Internet access Required for LLM API calls and market data fetching

Dependencies

System Packages

  • No special system packages required beyond Python

Python Packages (from requirements.txt)

  • langchain == 1.0.2
  • langchain-openai == 1.0.1
  • langchain-mcp-adapters >= 0.1.0
  • fastmcp == 2.12.5
  • tushare (for A-stock data only)
  • efinance (for A-stock data only)

Implicit Dependencies (imported but not in requirements.txt)

  • python-dotenv (imported as dotenv in every module)
  • numpy (used in calculate_metrics.py, plot_metrics.py)
  • pandas (used in get_daily_price_tushare.py, calculate_metrics.py)
  • matplotlib (used in plot_metrics.py)
  • seaborn (used in plot_metrics.py)
  • requests (used in data fetching scripts)
  • pyyaml (used in frontend config loading)

Credentials

See Environment:HKUDS_AI_Trader_API_Credentials for all required API keys and environment variables.

Quick Install

# Install core dependencies
pip install langchain==1.0.2 langchain-openai==1.0.1 langchain-mcp-adapters>=0.1.0 fastmcp==2.12.5

# Install implicit dependencies
pip install python-dotenv numpy pandas matplotlib seaborn requests pyyaml

# For A-stock market support (optional)
pip install tushare efinance

Code Evidence

Import chain from agent/base_agent/base_agent.py:6-21:

from dotenv import load_dotenv
from langchain.agents import create_agent
from langchain_core.globals import set_verbose, set_debug
from langchain_core.messages import AIMessage
from langchain_core.utils.function_calling import convert_to_openai_tool
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_openai import ChatOpenAI

Best-effort LangChain version compatibility from agent/base_agent/base_agent.py:24-33:

try:  # langchain <=0.1 style
    from langchain.callbacks.stdout import StdOutCallbackHandler as _ConsoleHandler
except Exception:  # langchain 0.2+/core split variants
    try:
        from langchain.callbacks import StdOutCallbackHandler as _ConsoleHandler
    except Exception:
        try:
            from langchain_core.callbacks.stdout import StdOutCallbackHandler as _ConsoleHandler
        except Exception:
            _ConsoleHandler = None  # Fallback if handler not available

FastMCP tool server from agent_tools/tool_trade.py:5:

from fastmcp import FastMCP
mcp = FastMCP("TradeTools")

Common Errors

Error Message Cause Solution
ModuleNotFoundError: No module named 'langchain' LangChain not installed pip install langchain==1.0.2
ModuleNotFoundError: No module named 'dotenv' python-dotenv missing pip install python-dotenv
ImportError: cannot import name 'create_agent' from 'langchain.agents' Wrong LangChain version Ensure langchain==1.0.2 specifically
ModuleNotFoundError: No module named 'tushare' Missing A-stock dependency pip install tushare (only needed for A-share market)

Compatibility Notes

  • POSIX Required: File locking uses fcntl module which is POSIX-only. Windows users must use WSL2.
  • LangChain Version Sensitivity: The codebase includes fallback imports for different LangChain versions, but is pinned to 1.0.2. Other versions may cause import failures.
  • Python 3.10+ Required: The codebase uses tuple[str, str] type syntax which requires Python 3.10+.

Related Pages

Page Connections

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