Skip to content

feat: add per-model bypass_models_gateway option - #3338

Merged
dgageot merged 2 commits into
docker:mainfrom
dgageot:worktree-board-8c54d94d165d6beb
Jun 30, 2026
Merged

dgageot merged 2 commits into
docker:mainfrom
dgageot:worktree-board-8c54d94d165d6beb

Conversation

@dgageot

@dgageot dgageot commented Jun 30, 2026

Copy link
Copy Markdown
Member

When most models in a deployment route through a central gateway (--models-gateway / CAGENT_MODELS_GATEWAY), there are cases where one specific model must connect directly to its provider — for example, a private fine-tune hosted on OpenAI that cannot be accessed through the gateway, or a model whose provider credentials differ from those the gateway holds. Until now, the gateway setting was all-or-nothing per agent invocation.

This adds a bypass_models_gateway boolean field to the per-model config in the agent YAML. Setting it to true on a model makes that model skip the gateway entirely and connect directly to its provider, using that provider's own credentials (OPENAI_API_KEY, ANTHROPIC_API_KEY, token_key, etc.). The rest of the agent's models continue routing through the gateway as before. Bypass is propagated transparently through router models: a bypass-flagged routing model passes the flag to all of its routed targets, so neither the config author nor the runtime needs to repeat the flag on every leaf. The combination of bypass_models_gateway: true with first_available is rejected at validation time because it has no coherent semantics.

The security implication of this field is noted in the type definition: on an untrusted config, a malicious base_url combined with this flag could be used to exfiltrate provider credentials to an attacker-controlled endpoint. Users should only enable this on configs they control.

dgageot added 2 commits June 30, 2026 19:05
Allows individual models to opt out of the configured models gateway and
connect directly to their provider using their own credentials.
…rthand marshal, reject with first_available

Assisted-By: docker-agent
@dgageot
dgageot requested a review from a team as a code owner June 30, 2026 17:42

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

The bypass_models_gateway implementation is correct and well-structured. The drafter attempted analysis of the diff and I performed direct code analysis to verify four areas of concern — all were dismissed.

Areas reviewed:

  • pkg/model/provider/factory.go — The functional-options pattern correctly appends WithGateway("") after the existing opts so the last writer wins; the gateway-bypass logic fires only when a gateway is actually configured; the routing model propagation and leaf model paths are both handled consistently.
  • pkg/config/gather.go — The bypassOnly flag is propagated correctly through the gatherEnvVarsForModel call chain. Named routing targets with their own BypassModelsGateway flag are handled. Non-recursion into sub-routers is safe because resolveRoutedModel explicitly rejects models-with-routing-rules as routing targets at validation time.
  • pkg/config/latest/validate.go — The validateFirstAvailable rejection of bypass_models_gateway is correctly placed; first_available candidates are plain strings so they cannot carry the flag on the parent config entry.
  • pkg/config/latest/types.go — The isShorthandOnly() guard correctly includes !f.BypassModelsGateway so a model with bypass set serializes as a full config object rather than a shorthand string.

No bugs were found in the changed code.

@dgageot
dgageot merged commit 11b008a into docker:main Jun 30, 2026
9 of 10 checks passed
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
docker-agent 1.93.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>This release adds OpenRouter as a built-in provider, introduces per-model gateway bypass support, and allows a dedicated model for session compaction, alongside several internal refactoring improvements.

## What's New
- Adds OpenRouter as a first-class built-in provider; when `OPENROUTER_API_KEY` is set, the provider is auto-detected and its base URL resolved automatically
- Adds a `compaction_model` field to allow a dedicated model for session summary generation, separate from the primary agent model
- Adds a `bypass_models_gateway` boolean field on a per-model basis, allowing specific models to connect directly to their provider instead of routing through the configured models gateway

## Technical Changes
- Replaces mutex usage with atomic types (`atomic.Bool`, `atomic.Pointer`) for single mutable fields in several structs
- Replaces package-level global variables with explicit parameters or struct fields to enable parallel-safe testing across several packages (`toolinstall`, `runtime`, `mcp`, `notification`, `tui`, `cmd/root`)
- Adds a concurrency group to the PR review trigger CI workflow to prevent duplicate reviews for the same PR
---

## What's Changed
* docs: update CHANGELOG.md for v1.92.0 by @docker-read-write[bot] in docker/docker-agent#3331
* refactor: replace single-variable mutexes with atomic types by @dgageot in docker/docker-agent#3330
* ci: add concurrency group to pr-review-trigger to prevent duplicate reviews by @derekmisler in docker/docker-agent#3334
* refactor: replace test-overridden globals with parallel-safe injection by @dgageot in docker/docker-agent#3332
* feat(compaction): allow a dedicated model for session summary generation by @Sayt-0 in docker/docker-agent#3335
* feat: add OpenRouter provider by @dgageot in docker/docker-agent#3337
* feat: add per-model bypass_models_gateway option by @dgageot in docker/docker-agent#3338


**Full Changelog**: docker/docker-agent@v1.92.0...v1.93.0
</pre>
  <p>View the full release notes at <a href="https://github.com/docker/docker-agent/releases/tag/v1.93.0">https://github.com/docker/docker-agent/releases/tag/v1.93.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!13152
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