Skip to content

Commit c108b01

Browse files
committed
batches: drop ModelProviderRoutes from codingagent Agent contract
Sourcegraph now owns the wire-path/upstream-path mapping per agent type; src-cli only needs to construct its base URL as <modelProviderURL>/<agent-type> and let the agent CLI append its protocol's wire path (codex CLI is hardcoded to POST <base>/responses since wire_api=responses is now the only supported value, so the explicit -c model_providers.sourcegraph.wire_api line is also dropped).
1 parent 6a48767 commit c108b01

3 files changed

Lines changed: 22 additions & 76 deletions

File tree

lib/batches/codex/codex.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package codex implements the codex coding agent run-command rewrite.
1+
// Package codex implements the codex coding agent.
22
package codex
33

44
import (
@@ -10,23 +10,16 @@ import (
1010
"github.com/sourcegraph/sourcegraph/lib/batches/codingagent/types"
1111
)
1212

13-
const model = "gpt-5.4"
14-
15-
// pinnedVersion is the codex CLI release we test against. Bump in lockstep
16-
// with the model_providers.* config keys below; codex CLI is pre-v1.
17-
const pinnedVersion = "0.134.0"
18-
19-
var routes = []types.ModelProviderRoute{
20-
{WirePath: "/responses", UpstreamPath: "/v1/completions/openai-responses"},
21-
}
13+
const (
14+
model = "gpt-5.4"
15+
pinnedVersion = "0.134.0"
16+
)
2217

2318
type Agent struct{}
2419

25-
func (Agent) Type() batcheslib.CodingAgentType { return batcheslib.CodingAgentTypeCodex }
26-
func (Agent) ModelProviderRoutes() []types.ModelProviderRoute { return routes }
27-
func (Agent) ImageRequirements() []string { return []string{"curl", "tar"} }
20+
func (Agent) Type() batcheslib.CodingAgentType { return batcheslib.CodingAgentTypeCodex }
21+
func (Agent) ImageRequirements() []string { return []string{"curl", "tar"} }
2822

29-
// InstallScript installs codex at pinnedVersion into types.InstallDir.
3023
func (Agent) InstallScript() string {
3124
return fmt.Sprintf(`_install_dir=%s
3225
_version=%s
@@ -69,7 +62,6 @@ func (Agent) RunCommand(prompt, modelProviderURL string) string {
6962
"-c", fmt.Sprintf(`model_providers.sourcegraph.base_url=%q`, modelProviderURL),
7063
"-c", fmt.Sprintf(`model_providers.sourcegraph.env_key=%q`, types.ModelProviderTokenEnvVar),
7164
"-c", fmt.Sprintf(`model_providers.sourcegraph.env_http_headers={%q=%q}`, types.JobIDHeaderName, types.JobIDEnvVar),
72-
"-c", `model_providers.sourcegraph.wire_api="responses"`,
7365
prompt,
7466
)
7567
}

lib/batches/codingagent/codingagent.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Package codingagent rewrites v3 batch spec coding-agent steps into the
2-
// shell commands that drive them. Register new agents in the agents list.
1+
// Package codingagent rewrites v3 batch spec coding-agent steps into shell
2+
// commands. Register new agents in the agents list.
33
package codingagent
44

55
import (
@@ -16,13 +16,9 @@ import (
1616
"github.com/sourcegraph/sourcegraph/lib/errors"
1717
)
1818

19-
// ErrUnknownType is returned when a codingAgent step references a type that
20-
// has no registered Agent.
2119
var ErrUnknownType = errors.New("unknown codingAgent type")
2220

23-
// RenderRunCommand returns the shell-quoted command that runs agentStep. The
24-
// prompt is rendered before quoting; reversing would let templated values
25-
// break out of the shell quoting.
21+
// RenderRunCommand returns the shell command that runs agentStep.
2622
func RenderRunCommand(agentStep *batcheslib.CodingAgentStep, modelProviderURL string, stepCtx *template.StepContext) (string, error) {
2723
a, ok := agents[agentStep.Type]
2824
if !ok {
@@ -43,9 +39,6 @@ func RenderRunCommand(agentStep *batcheslib.CodingAgentStep, modelProviderURL st
4339
return b.String(), nil
4440
}
4541

46-
// failIfMissing returns a shell snippet that, when prepended to the step
47-
// script, writes a message to stderr and exits the container with status 1
48-
// if binary isn't on PATH.
4942
func failIfMissing(agentType batcheslib.CodingAgentType, binary string) string {
5043
msg := fmt.Sprintf(
5144
"codingAgent %q requires %q on PATH in the run container",
@@ -69,20 +62,3 @@ var agents = func() map[batcheslib.CodingAgentType]types.Agent {
6962
}
7063
return out
7164
}()
72-
73-
// RegisteredModelProviderRoutes returns the model-provider proxy routes
74-
// contributed by every registered Agent, each WirePath prefixed with
75-
// its agent type.
76-
func RegisteredModelProviderRoutes() []types.ModelProviderRoute {
77-
var out []types.ModelProviderRoute
78-
for _, a := range agents {
79-
prefix := "/" + string(a.Type())
80-
for _, route := range a.ModelProviderRoutes() {
81-
out = append(out, types.ModelProviderRoute{
82-
WirePath: prefix + route.WirePath,
83-
UpstreamPath: route.UpstreamPath,
84-
})
85-
}
86-
}
87-
return out
88-
}
Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,26 @@
1-
// Package types holds the contract shared between the codingagent registry
2-
// and individual coding-agent implementations, in a leaf package to avoid an
3-
// import cycle with the registry.
1+
// Package types holds the codingagent contract shared with individual
2+
// coding-agent implementations; split out to avoid an import cycle.
43
package types
54

65
import (
76
batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
87
)
98

10-
const ModelProviderTokenEnvVar = "SRC_BATCHES_MODEL_PROVIDER_TOKEN"
11-
12-
// JobIDEnvVar binds ModelProviderTokenEnvVar to its job; sent as JobIDHeaderName.
13-
const JobIDEnvVar = "SRC_BATCHES_JOB_ID"
14-
15-
const JobIDHeaderName = "X-Sourcegraph-Job-ID"
16-
17-
// InstallDir is where each Agent installs its pinned binary; invoked by
18-
// absolute path so we ignore any copy shipped by the image.
19-
const InstallDir = "/tmp/sg-codingagent/bin"
9+
const (
10+
ModelProviderTokenEnvVar = "SRC_BATCHES_MODEL_PROVIDER_TOKEN"
11+
JobIDEnvVar = "SRC_BATCHES_JOB_ID"
12+
JobIDHeaderName = "X-Sourcegraph-Job-ID"
13+
InstallDir = "/tmp/sg-codingagent/bin"
14+
)
2015

2116
type Agent interface {
2217
Type() batcheslib.CodingAgentType
23-
// RunCommand receives the already-templated prompt and MUST shell-quote it.
18+
// RunCommand returns the shell command for the agent. The rendered
19+
// prompt MUST be shell-quoted.
2420
RunCommand(renderedPrompt, modelProviderURL string) string
25-
// ModelProviderRoutes returns routes whose WirePath is relative to the
26-
// agent type; the registry prefixes "/<agent-type>" before exposing them.
27-
ModelProviderRoutes() []ModelProviderRoute
2821
// ImageRequirements lists binaries that must be on PATH in the run
29-
// container (e.g. "curl" so InstallScript can fetch the agent). The
30-
// registry emits a `command -v` check for each before InstallScript.
22+
// container before InstallScript runs.
3123
ImageRequirements() []string
32-
// InstallScript returns shell that installs the agent at a pinned
33-
// version into a Sourcegraph-owned scratch dir and prepends it to PATH.
24+
// InstallScript installs the agent at a pinned version into InstallDir.
3425
InstallScript() string
3526
}
36-
37-
// ModelProviderRoute is one wire→upstream mapping served by the Sourcegraph
38-
// model-provider proxy (mounted under /.executors/model-provider/batches).
39-
type ModelProviderRoute struct {
40-
// WirePath is the proxy subpath the agent CLI POSTs to, relative to the
41-
// agent type (e.g. "/responses"). The registry prefixes "/<agent-type>"
42-
// before registering it on the router (e.g. "/codex/responses").
43-
WirePath string
44-
// UpstreamPath is the path on the Sourcegraph Model Provider upstream
45-
// (e.g. Cody Gateway) that serves WirePath, such as
46-
// "/v1/completions/openai-responses".
47-
UpstreamPath string
48-
}

0 commit comments

Comments
 (0)