HKUDS/Vibe-Trading · error · RuntimeError

LANGCHAIN_MODEL_NAME is not set

Error message

LANGCHAIN_MODEL_NAME is not set

What it means

build_llm requires a model name, and neither the model_name argument nor the LANGCHAIN_MODEL_NAME environment variable provided one (empty/whitespace after strip). This is a configuration guard before any client is constructed.

Source

Thrown at agent/src/providers/llm.py:1411


def build_llm(*, model_name: Optional[str] = None, callbacks: Any = None) -> Any:
    """Construct the configured LangChain chat model.

    Args:
        model_name: Model name; defaults to LANGCHAIN_MODEL_NAME.
        callbacks: Optional LangChain callbacks.

    Returns:
        Provider-specific LangChain chat model.

    Raises:
        RuntimeError: If langchain-openai is missing or LANGCHAIN_MODEL_NAME is unset.
    """
    _sync_provider_env()
    name = model_name or get_env_config().llm.langchain_model_name.strip()
    if not name:
        raise RuntimeError("LANGCHAIN_MODEL_NAME is not set")
    temperature = get_env_config().llm.langchain_temperature
    provider = get_env_config().llm.langchain_provider.lower()
    caps = get_provider_capabilities(provider, name)
    if provider in {"openai-codex", "openai_codex"}:
        from src.providers.openai_codex import OpenAICodexLLM

        effort = get_env_config().llm.langchain_reasoning_effort.strip().lower()
        return OpenAICodexLLM(
            model=name,
            temperature=temperature,
            timeout=get_env_config().llm.timeout_seconds,
            reasoning_effort=effort or None,
        )

    if provider in {"copilot", "github-copilot"}:
        from src.providers.copilot_auth import CopilotSDKLLM

        return CopilotSDKLLM(

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Set LANGCHAIN_MODEL_NAME in your environment or .env (e.g. export LANGCHAIN_MODEL_NAME=claude-sonnet-4)
  2. Pass model_name explicitly to build_llm(model_name=...)
  3. Check the env file is actually loaded: python -c "from src.env_config import get_env_config; print(repr(get_env_config().llm.langchain_model_name))"

Example fix

# before
llm = build_llm()  # LANGCHAIN_MODEL_NAME unset

# after
export LANGCHAIN_MODEL_NAME=gpt-4o
llm = build_llm()
Defensive patterns

Strategy: validation

Validate before calling

name = model_name or os.environ.get('LANGCHAIN_MODEL_NAME', '').strip()
if not name:
    raise SystemExit('LANGCHAIN_MODEL_NAME is required')

Prevention

When it happens

Trigger: Calling build_llm() with no model_name and LANGCHAIN_MODEL_NAME unset, empty, or whitespace; .env file not loaded in the current shell; CI environment missing the variable.

Common situations: New machine/container without the .env file copied; variable renamed or commented out; tests running in an environment that scrubs env vars.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/d3130e5bd4b77bdc. Report an issue: GitHub.