Skip to content

fix: make goth and ex_aws_auth optional dependencies#799

Merged
mikehostetler merged 2 commits into
agentjido:mainfrom
davydog187:fix/optional-goth-exaws
Jul 6, 2026
Merged

fix: make goth and ex_aws_auth optional dependencies#799
mikehostetler merged 2 commits into
agentjido:mainfrom
davydog187:fix/optional-goth-exaws

Conversation

@davydog187

Copy link
Copy Markdown
Contributor

Summary

Closes #798.

goth and ex_aws_auth were required dependencies, but they're only used by two providers:

  • google_vertex — Goth, for Google Cloud OAuth (ADC / refresh tokens / workload identity / metadata server)
  • amazon_bedrock — ex_aws_auth, for AWS Signature V4 signing (IAM credentials, STS, bidi streaming)

Every user inherited both regardless of which provider they used. This marks them optional: true so they're only pulled in when explicitly added.

The non-obvious part

optional: true alone is not sufficient. Provider modules are compiled into :req_llm and discovered at runtime (ReqLLM.Providers.discover_providers/0), so the Bedrock/Vertex modules must still compile when a downstream user omits the optional dep. They referenced %AWSAuth.Credentials{} and %Goth.Token{} as compile-time struct literals/patterns, which raise a CompileError (__struct__/1 is undefined) when the dep is absent.

These are rewritten to plain-map form — %{__struct__: Mod, ...} for pattern matches and struct(Mod, ...) for construction — so they no longer force the module at compile time. Remote function calls (AWSAuth.sign_authorization_header, Goth.Token.fetch, etc.) compile fine without the dep and only need runtime guarding.

Changes

  • mix.exs — both deps marked optional: true.
  • Converted all compile-time struct references across amazon_bedrock.ex, amazon_bedrock/sts.ex, bedrock/bidi_stream.ex, google_vertex/auth.ex.
  • Added ensure-loaded guards that raise a clear "add this dependency" error:
    • ensure_ex_aws_auth!/0 at Bedrock credential-resolution time (the pre-existing guard fired too late — after AWSAuth.Credentials.from_map/from_env was already called).
    • Code.ensure_loaded(Goth.Token) on the Vertex ADC/metadata path.
  • Updated stale error-message version text (~> 1.3~> 1.4).
  • README: added an "Optional Provider Dependencies" section.

Verification

  • mix compile + Bedrock/Vertex test suites: 180 tests, 0 failures. mix format --check-formatted and mix credo clean on changed files.
  • Dep-less downstream check: a throwaway consumer project depending on this branch without goth/ex_aws_auth compiles cleanly (only xref warnings, no CompileError), neither dep is fetched, both providers still appear in ReqLLM.Providers.list/0, and exercising an IAM/ADC path raises the friendly dependency error rather than a raw UndefinedFunctionError.

Known gap

The bidirectional-streaming path (bidi_stream.ex, Nova Sonic) constructs credentials without an upfront guard, so it would raise a raw UndefinedFunctionError rather than the friendly message if ex_aws_auth is missing. Left as-is since it's a niche path — happy to add a guard for symmetry if preferred.

@mikehostetler mikehostetler added needs_work Changes requested before merge ready_to_merge and removed needs_work Changes requested before merge labels Jul 6, 2026
davydog187 and others added 2 commits July 6, 2026 11:09
Goth and ex_aws_auth were required deps but are only used by the
google_vertex (Goth OAuth) and amazon_bedrock (AWS SigV4) providers.
Mark them optional so users of other providers don't inherit them.

Because providers are compiled into :req_llm and discovered at runtime,
the Bedrock/Vertex modules must still compile when the optional deps are
absent. Rewrite the compile-time struct references (%AWSAuth.Credentials{},
%Goth.Token{}) to plain-map form so they no longer force the modules at
compile time. Add ensure-loaded guards that raise a clear 'add this
dependency' error when an IAM/ADC path is used without the dep.

Closes agentjido#798
@mikehostetler mikehostetler force-pushed the fix/optional-goth-exaws branch from fea7737 to f953679 Compare July 6, 2026 16:12
@mikehostetler mikehostetler added needs_work Changes requested before merge ready_to_merge and removed ready_to_merge needs_work Changes requested before merge labels Jul 6, 2026
@mikehostetler mikehostetler merged commit 3289c10 into agentjido:main Jul 6, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Goth and AWS being pulled in as dependencies

2 participants