Skip to content

feat(provider): make openai, anthropic, google, and amazon-bedrock optional#3176

Merged
dgageot merged 1 commit into
mainfrom
worktree-board-760d8e0180538940
Jun 19, 2026
Merged

feat(provider): make openai, anthropic, google, and amazon-bedrock optional#3176
dgageot merged 1 commit into
mainfrom
worktree-board-760d8e0180538940

Conversation

@dgageot

@dgageot dgageot commented Jun 19, 2026

Copy link
Copy Markdown
Member

Projects embedding docker-agent can now drop model providers they don't need, shrinking both the binary and transitive dependency graph. The largest win is dropping the AWS SDK (aws-sdk-go-v2) via the docker_agent_no_bedrock tag, which eliminates the entire Bedrock integration and its 61-package dependency tree.

The monolithic pkg/model/provider/factory.go was split into a shared dispatch core plus one self-registering file per optional provider, each gated by a build tag. Providers register into the dispatch map via init(), and a model whose provider was compiled out fails at construction time with a clear "not compiled into this build" error. All providers are included by default; pass a tag to opt out of unwanted ones.

Build flags (all included by default; use tags to exclude):

  • docker_agent_no_openai — drops github.com/openai/openai-go
  • docker_agent_no_anthropic — drops github.com/anthropics/anthropic-sdk-go
  • docker_agent_no_google — drops google.golang.org/genai and Vertex AI / cloud auth stack
  • docker_agent_no_bedrock — drops the github.com/aws/aws-sdk-go-v2 stack

Example: go build -tags 'docker_agent_no_bedrock docker_agent_no_openai' ...

Tags are prefixed with docker_agent_ because Go build tags are global to a build (not scoped per module), so a bare no_openai would collide with an embedding project's own tags. The rationale and full tag list are documented in the package doc via go doc / pkg.go.dev.

One caveat: anthropic and openai SDKs are also imported by the google provider's Vertex Model Garden support, so they only fully drop when combined with docker_agent_no_google. The openai-go and genai packages also appear elsewhere (dmr/oaistream, chatserver, pkg/a2a), so those won't leave the module graph entirely. The dmr provider and rule-based router remain always compiled in. Builds pass with every tag combination and without any tags; js/wasm still builds; lint is clean.

…oviders optional via build tags

Every model provider was wired in through a single chokepoint
(pkg/model/provider/factory.go), so the heavy provider SDKs only entered the
dependency graph through that one file. This makes it cheap to compile a
provider out for projects embedding docker-agent that don't need it.

Split the monolithic factory into a shared core plus one self-registering file
per optional provider, each gated by a negative build tag:

  - docker_agent_no_openai    drops github.com/openai/openai-go
  - docker_agent_no_anthropic drops github.com/anthropics/anthropic-sdk-go
  - docker_agent_no_google    drops google.golang.org/genai and the Vertex AI
                              / cloud auth stack
  - docker_agent_no_bedrock   drops the github.com/aws/aws-sdk-go-v2 stack
                              (the largest provider-specific dependency tree)

All providers are included by default; the dmr provider and rule-based router
are always compiled in. Requesting a model whose provider was compiled out
fails at construction time with a clear 'not compiled into this build' error.

Build tags are global to a build (not scoped per module), so the tags are
prefixed with docker_agent_ to avoid colliding with an embedding project's own
tags. The rationale and the full tag list are documented in the package doc so
downstream consumers can discover them via go doc / pkg.go.dev.

Tests that build a real OpenAI client to exercise generic clone/custom-provider
logic are tagged !docker_agent_no_openai; the provider-agnostic logic tests
stay in the default build.
@dgageot dgageot requested a review from a team as a code owner June 19, 2026 15:31

@docker-agent docker-agent left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

The provider opt-out refactoring is well-structured. The split from a monolithic factory.go into per-provider self-registering files (factory_openai.go, factory_anthropic.go, factory_google.go, factory_bedrock.go) is clean and correct. Build tag syntax (//go:build !docker_agent_no_<provider>) is syntactically valid. The providerFactories map is initialized before init() runs, and the registerProviderFactory panic-on-duplicate acts as an intentional safety net against misconfigured builds. All four providers are included by default; the docker_agent_ prefix on tags avoids collision with embedding projects.

No high or medium severity bugs were found in the changed code.

Minor hygiene notes (no action required):

  • A few test files (custom_provider_test.go, etc.) lack build-tag guards matching their factory dependencies. This is harmless today since none of those tests call New() with a provider-specific path, but adding guards would make the intent explicit.
  • schema_test.go always imports SDK sub-packages regardless of build tags, so test binaries won't fully tree-shake even when provider tags are set — this is expected given those sub-packages appear elsewhere in the module.

@dgageot dgageot merged commit e419194 into main Jun 19, 2026
12 checks passed
@dgageot dgageot deleted the worktree-board-760d8e0180538940 branch June 19, 2026 15:39
pull Bot pushed a commit to TheTechOddBug/cagent that referenced this pull request Jun 20, 2026
…ddedchat, RAG opt-in, optional providers

- PR docker#3171 (pkg/embeddedchat): Add 'Headless Embedded Chat' section to
  docs/guides/go-sdk/index.md documenting the Config, Session, Event
  types and the Send/Confirm/Restart/Close API with worked examples.
- PR docker#3174 (RAG opt-in): Add 'RAG Toolset (cgo-free builds)' section
  explaining that pkg/rag must be blank-imported to register the toolset,
  allowing embedders to omit it and avoid the cgo dependency.
- PR docker#3176 (optional providers): Add 'Optional Provider Build Tags'
  section listing docker_agent_no_{openai,anthropic,google,bedrock} tags
  with the major dependency each removes and the Anthropic+Google note.
- Add pkg/embeddedchat row to the Core Packages table.

Sources:
  docker#3171
  docker#3174
  docker#3176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants