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
- Set LANGCHAIN_MODEL_NAME in your environment or .env (e.g. export LANGCHAIN_MODEL_NAME=claude-sonnet-4)
- Pass model_name explicitly to build_llm(model_name=...)
- 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
- Fail fast at app startup on missing critical env vars
- Use a settings schema (pydantic) that marks LANGCHAIN_MODEL_NAME required
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
- VIBE_TRADING_DEEPSEEK_ADAPTER=native requires langchain-deep
- unknown theme {theme!r}; expected one of {sorted(_VALID_THEM
- no MCP server configured for live broker {broker!r}
- {source} produces a non-ASCII HTTP header ({name!r}). Use an
- Anthropic provider requires langchain-anthropic. Install the
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/d3130e5bd4b77bdc.
Report an issue: GitHub.