Skip to content

fix(bedrock): route _require_boto3 through lazy_deps.ensure#24972

Closed
ChyuWei wants to merge 2 commits into
NousResearch:mainfrom
ChyuWei:fix/bedrock-lazy-install
Closed

fix(bedrock): route _require_boto3 through lazy_deps.ensure#24972
ChyuWei wants to merge 2 commits into
NousResearch:mainfrom
ChyuWei:fix/bedrock-lazy-install

Conversation

@ChyuWei

@ChyuWei ChyuWei commented May 13, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Restores the lazy-install path for boto3. The 2026-05-12 supply-chain-hardening pass (#24515) relocated boto3 from the [all] extra into LAZY_DEPS["provider.bedrock"], but agent/bedrock_adapter.py::_require_boto3 was not updated alongside the other adapters and still does a bare try: import boto3 / except ImportError: raise. Fresh installs therefore hit the manual-install error on the very first Bedrock call, even with security.allow_lazy_installs left at the default true.

This PR mirrors the pattern already used by agent/anthropic_adapter.py::_get_anthropic_sdk — call tools.lazy_deps.ensure("provider.bedrock", prompt=False) before the import, swallowing ImportError (the tools.lazy_deps module itself unavailable — e.g. minimal packaging) and generic Exception (FeatureUnavailable when the user has opted out of lazy installs or is offline). The existing manual-install ImportError survives as the final fallback when lazy install is unavailable or fails.

Related Issue

Fixes #24967

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • agent/bedrock_adapter.py_require_boto3() now calls tools.lazy_deps.ensure("provider.bedrock", prompt=False) before the import boto3 attempt, matching _get_anthropic_sdk in anthropic_adapter.py.
  • tests/agent/test_bedrock_adapter.py — new TestRequireBoto3LazyInstall class:

How to Test

  1. On a clean venv with no boto3 installed and security.allow_lazy_installs at the default true, configure the Bedrock provider and start a chat.
  2. The first user message should trigger tools.lazy_deps.ensure → pip-install boto3==1.42.89 → normal Converse call, not the manual-install ImportError.
  3. Focused regression (with and without boto3):
    # with boto3 present
    pytest tests/agent/test_bedrock_adapter.py::TestRequireBoto3LazyInstall -v
    # 2 passed
    
    # without boto3 (matches CI environment)
    uv pip uninstall boto3 botocore
    pytest tests/agent/test_bedrock_adapter.py::TestRequireBoto3LazyInstall -v
    # 2 passed
    
  4. Adjacent suites still green:
    pytest tests/agent/test_bedrock_adapter.py tests/tools/test_lazy_deps.py
    # 163 passed
    

Checklist

Code

Documentation & Housekeeping

  • I've updated relevant documentation — N/A (no user-facing doc changes)
  • I've updated cli-config.yaml.example — N/A (no config keys changed)
  • I've updated CONTRIBUTING.md or AGENTS.md — N/A (no architecture change)
  • I've considered cross-platform impact — N/A (pure-Python import path, same on Linux/macOS/Windows)
  • I've updated tool descriptions/schemas — N/A (no tool behavior change)

Screenshots / Logs

Before this PR, on a fresh install with security.allow_lazy_installs: true (default):

API call failed (attempt 1/3): ImportError
   Provider: bedrock  Model: arn:aws:bedrock:us-west-2:<REDACTED>:application-inference-profile/<REDACTED>
   Endpoint: https://bedrock-runtime.us-east-1.amazonaws.com
   Error: The 'boto3' package is required for the AWS Bedrock provider.
          Install it with: pip install boto3
          Or install Hermes with Bedrock support: pip install -e '.[bedrock]'

The retry loop exhausts without ever attempting a lazy install. Also reproduced earlier in the session from the model-discovery path:

WARNING agent.bedrock_adapter: Failed to create Bedrock client for model discovery:
The 'boto3' package is required for the AWS Bedrock provider. ...

Both paths go through _require_boto3, so the single-point fix in this PR resolves discovery and chat together.

ChyuWei added 2 commits May 13, 2026 18:43
The 2026-05-12 supply-chain-hardening pass moved boto3 out of [all]
and into LAZY_DEPS["provider.bedrock"], but _require_boto3 in
agent/bedrock_adapter.py still did a bare try/except ImportError and
told the user to run `pip install boto3` manually. Fresh installs
hitting a Bedrock chat therefore saw the manual-install message on
every first call even with lazy installs enabled.

Mirror the pattern already used by agent/anthropic_adapter.py's
_get_anthropic_sdk: call tools.lazy_deps.ensure("provider.bedrock",
prompt=False) before the import, tolerating ImportError (lazy_deps
module absent) and arbitrary exceptions (FeatureUnavailable when
lazy installs are opted out or offline). The existing manual-install
error survives as the final fallback.

Adds a regression test that patches tools.lazy_deps.ensure and asserts
_require_boto3 routes through it with the correct feature key, plus a
sibling test confirming the import path still succeeds when ensure()
itself raises.
…t it

The 2026-05-12 policy removed boto3 from [all], so CI's default
`pip install -e .[all,dev]` no longer pulls boto3 (see NousResearch#24601). The
regression tests added for _require_boto3 must therefore be runnable
without the real boto3 to actually guard the lazy-install path on
every CI run, not just on dev machines that happen to have it.

Stub boto3 via `patch.dict(sys.modules, {"boto3": <fake module>})`
in both tests. Verified locally that they pass in both states —
boto3 installed and fully uninstalled.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/bedrock AWS Bedrock (boto3, IAM) labels May 13, 2026
@ChyuWei

ChyuWei commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

Closing stale PR — will revisit if needed.

@ChyuWei ChyuWei closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/bedrock AWS Bedrock (boto3, IAM) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bedrock first-call fails with manual-install message — _require_boto3 never calls lazy_deps.ensure

2 participants