TauricResearch/TradingAgents · error · ImportError

AWS Bedrock support requires the optional 'langchain-aws' de

Error message

AWS Bedrock support requires the optional 'langchain-aws' dependency. Install it with: pip install "tradingagents[bedrock]"

What it means

ImportError raised by the Bedrock client factory (tradingagents/llm_clients/bedrock_client.py) when langchain_aws cannot be imported. AWS Bedrock support ships as an optional dependency; the lazy import keeps boto3/langchain-aws out of the base install, and the error names the exact extra to install.

Source

Thrown at tradingagents/llm_clients/bedrock_client.py:26

_DEFAULT_REGION = "us-west-2"
_BEDROCK_CLASS = None


def _bedrock_class():
    """Lazily import langchain-aws (the optional ``[bedrock]`` extra) and return a
    ChatBedrockConverse subclass with normalized content output.

    Imported on demand so the optional dependency (and boto3) isn't required by
    the rest of the package; cached after the first call.
    """
    global _BEDROCK_CLASS
    if _BEDROCK_CLASS is not None:
        return _BEDROCK_CLASS

    try:
        from langchain_aws import ChatBedrockConverse
    except ImportError as exc:
        raise ImportError(
            "AWS Bedrock support requires the optional 'langchain-aws' dependency. "
            'Install it with: pip install "tradingagents[bedrock]"'
        ) from exc

    class NormalizedChatBedrockConverse(ChatBedrockConverse):
        """ChatBedrockConverse with normalized (string) content output."""

        def invoke(self, input, config=None, **kwargs):
            return normalize_content(super().invoke(input, config, **kwargs))

    _BEDROCK_CLASS = NormalizedChatBedrockConverse
    return _BEDROCK_CLASS


class BedrockClient(BaseLLMClient):
    """Client for Amazon Bedrock via the Converse API (langchain-aws).

    Authentication is either a Bedrock API key (bearer token) via

View on GitHub (pinned to a33fd4c0f1)

Solutions

  1. Install the extra: pip install "tradingagents[bedrock]" (or pip install langchain-aws).
  2. Rebuild your Docker image / lockfile so langchain-aws and boto3 are pinned.
  3. If Bedrock is not intended, switch the provider config to an installed one (openai/azure/openai-compatible).

Example fix

# before
pip install tradingagents
TradingAgentsGraph(config with provider='bedrock')  # ImportError

# after
pip install "tradingagents[bedrock]"
TradingAgentsGraph(config with provider='bedrock')
Defensive patterns

Strategy: validation

Validate before calling

def bedrock_available() -> bool:
    try:
        import langchain_aws  # noqa: F401
        return True
    except ImportError:
        return False

if provider == 'bedrock' and not bedrock_available():
    raise SystemExit('install first: pip install "tradingagents[bedrock]"')

Try / catch

try:
    client = BedrockClient(model, base_url)
except ImportError as e:
    raise SystemExit(f'missing optional dependency: {e}')  # fail deployment with install hint

Prevention

When it happens

Trigger: Configuring the LLM provider as 'bedrock' (which routes through factory.py to BedrockClient) without having installed the optional extra. The `from langchain_aws import ChatBedrockConverse` inside _get_bedrock_class raises ImportError, which is re-raised with install instructions.

Common situations: Deploying to environments where only the base package was installed; lockfiles that dropped langchain-aws after a refactor; assuming boto3 alone is sufficient.


AI-assisted analysis of TauricResearch/TradingAgents@a33fd4c0f1 (2026-08-14). Data as JSON: /api/errors/b10ccf356273346f. Report an issue: GitHub.