feat(runtime): resolveAgentBackend — one shared backend-name → AgentExecutionBackend resolver#451
Merged
Merged
Conversation
…xecutionBackend resolver
The AgentExecutionBackend sibling of resolveSandboxClient. Every in-process
eval product hand-rolled the same {router,tcloud,cli-bridge} →
createOpenAICompatibleBackend branch (gtm, legal, insurance, creative); this
is the single generic resolver they share.
- router/tcloud/cli-bridge → createOpenAICompatibleBackend({ apiKey, baseUrl,
model, kind: label ?? kind }). All three speak OpenAI-compatible chat
completions; cli-bridge REQUIRES model in the body, which this factory sends
(a transport that drops it is why products never used a bespoke bridge path).
- sandbox → the caller's own sandboxBackend() seam. The product sandbox variant
carries system prompt / workspace / in-box executor that do not belong in the
substrate; fail loud when the seam is absent.
Pure backend selection. Product concerns (credit hard-cuts, fetch-capture,
D1 wiring) stay as product-side wrappers; the openai-compat passthrough
(tools/toolChoice/responseFormat/fetchImpl/retry) is forwarded verbatim.
Additive, non-breaking. Bumps 0.82.0 → 0.83.0.
tangletools
approved these changes
Jul 3, 2026
tangletools
left a comment
Contributor
There was a problem hiding this comment.
✅ Auto-approved drewstone PR — d8b3e7d4
This PR was opened by the trusted drewstone account.
The full PR reviewer audit still runs separately and will publish findings if it detects issues.
tangletools · auto-approval · reason: drewstone_author · 2026-07-03T03:45:29Z
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
resolveAgentBackend(opts): AgentExecutionBackend— theAgentExecutionBackendsibling of the shippedresolveSandboxClient. It turns a--backend {router,tcloud,cli-bridge,sandbox}choice into the backendrunChatThroughRuntime/runAgentTaskStreamruns on.Why
Five in-process eval products hand-roll the same
backend-name → createOpenAICompatibleBackendbranch, and the copies drift. Studied gtm (eval/kernel.ts buildAgentBackend), insurance (tests/eval/canonical.ts makeBackend), creative (eval/canonical-runner.ts buildBackend), legal (chat.ts defaultTCloudBackend): all three OpenAI-compat kinds are byte-identical apart from thekindlabel. This is the single generic resolver they will share (product migration is a later wave — no product repo touched here).Union decisions
createOpenAICompatibleBackend({ apiKey, baseUrl, model, kind: label ?? kind }). All three speak OpenAI-compatiblePOST {baseUrl}/chat/completions; router is the tcloud endpoint, cli-bridge fronts a harness CLI at its own/v1. cli-bridge requiresmodelin the body — which this factory sends — so it routes here, never a transport that drops it.sandboxBackend()seam. The product sandbox variant carries system prompt / workspace id / in-box D1 executor that do not belong in the substrate. Fail loud when the seam is absent (no silent fallback), matchingresolveSandboxClient'ssandboxcontract.tools,toolChoice,responseFormat,fetchImpl,retry) is forwarded verbatim so a product keeps its tool advertising / capture-fetch without re-opening the branch.createCliBridgeBackend
The brief flagged a broken
createCliBridgeBackendto fix/deprecate — it does not exist in agent-runtime (no export, no source; the only cli-bridge transport isbridgeExecutorinsupervise/runtime.ts, used byresolveSandboxClientfor theSandboxClientseam, a different path). Nothing to fix. cli-bridge correctly routes throughcreateOpenAICompatibleBackend.Tests / gate
src/resolve-agent-backend.test.ts— 8 cases: each kind builds the rightcreateOpenAICompatibleBackendconfig; label override; passthrough forwarding + omission (keeps tool-free request shape); sandbox seam honored + fail-loud.Additive, non-breaking.
0.82.0 → 0.83.0(minor).