hsliuping/TradingAgents-CN · error · AttributeError
name
Error message
name
What it means
Raised by the module-level __getattr__ in tradingagents/agents/__init__.py when code accesses an attribute that is not in the lazy-export _EXPORTS mapping. The package uses PEP 562 lazy imports, so unknown attribute lookups surface as AttributeError(name) rather than the usual module attribute error.
Source
Thrown at tradingagents/agents/__init__.py:53
"RiskDebateState",
"create_bear_researcher",
"create_bull_researcher",
"create_research_manager",
"create_fundamentals_analyst",
"create_market_analyst",
"create_neutral_debator",
"create_news_analyst",
"create_risky_debator",
"create_risk_manager",
"create_safe_debator",
"create_social_media_analyst",
"create_trader",
]
def __getattr__(name: str):
if name not in _EXPORTS:
raise AttributeError(name)
module_name, attr_name = _EXPORTS[name]
module = importlib.import_module(module_name)
value = getattr(module, attr_name)
globals()[name] = value
return value
def __dir__():
return sorted(set(globals().keys()) | set(_EXPORTS.keys()))
View on GitHub (pinned to 74783e8817)
Solutions
- Check the _EXPORTS dict in tradingagents/agents/__init__.py for valid names
- Fix the typo in the attribute/import name
- If the symbol should be public, add it to _EXPORTS with its (module, attr) pair
Example fix
// before from tradingagents.agents import create_analyst agent = tradingagents.agents.create_tradr(...) // after from tradingagents.agents import create_trader agent = create_trader(...)
Defensive patterns
Strategy: validation
Validate before calling
import tradingagents.agents as ta
assert 'create_trader' in dir(ta) or True
# authoritative check against the export map
from tradingagents.agents import _EXPORTS
if 'create_trader' not in _EXPORTS:
raise KeyError('create_trader is not exported; valid: %s' % sorted(_EXPORTS)) Type guard
def is_agent_export(name: str) -> bool:
from tradingagents.agents import _EXPORTS
return name in _EXPORTS Try / catch
try:
create_trader = getattr(tradingagents.agents, 'create_trader')
except AttributeError:
# surface valid options for debugging
raise Prevention
- Use an IDE so attribute names autocomplete against the lazy module
- When adding agents, register them in _EXPORTS in the same PR
- Pin export names in a smoke test that iterates _EXPORTS and getattr's each one
When it happens
Trigger: Calling e.g. tradingagents.agents.nonexistent or a typo like tradingagents.agents.create_tradr (not in _EXPORTS). Also `from tradingagents.agents import X` where X was never registered in the _EXPORTS dict.
Common situations: Typos in agent factory names, using an agent name that exists elsewhere in the codebase but was never added to _EXPORTS, or expecting old exports after a refactor to lazy loading.
Related errors
- MongoDB连接字符串未配置。请设置环境变量 MONGODB_CONNECTION_STRING\n例如: MONGO
- Redis连接配置未完整设置。请设置以下环境变量之一:\n1. REDIS_CONNECTION_STRING=redi
- pymongo is not installed. Please install it with: pip instal
- MongoDB连接字符串未配置。请通过以下方式之一进行配置:\n1. 设置环境变量 MONGODB_CONNECTION
- 不支持的数据源: {self.current_source}
AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28).
Data as JSON: /api/errors/e8aade4bf7f2deb8.
Report an issue: GitHub.