Skip to content

feat(provider): ship LLM provider adapters as opt-in Go modules (#362) - #378

Merged
JAORMX merged 4 commits into
mainfrom
feat/362-provider-module
Aug 4, 2026
Merged

JAORMX merged 4 commits into
mainfrom
feat/362-provider-module

Conversation

@JAORMX

@JAORMX JAORMX commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

What

Ships the real LLM provider adapters (OpenAI + Anthropic) out of the box as opt-in Go submodules under provider/, so engine importers get a working port.LLMProvider by import instead of re-deriving wire-format logic.

Closes #362.

Why

engine/ ships port.LLMProvider and mockllm, but the real adapters lived in the root module's internal/adapter/ — unimportable. Anyone embedding the engine had to write their own, re-deriving details that have exactly one correct answer and fail silently when wrong. The sharpest example is Anthropic prompt-cache breakpoint placement: place them wrong and every turn of a long tool-calling loop reprocesses the accumulated transcript at full input price — quadratic cost growth on precisely the sessions this engine exists to run. Nothing fails; you find out from a bill.

#269 carved the adapters out of the engine module so heavy SDK deps aren't forced on every engine importer. That was right — but it argued against the engine module, not against shipping them. mecatl is already multi-module; a third makes the dependency opt-in by import. Nobody who doesn't want the SDK pays for it.

How — a provider/ subtree of opt-in submodules

Module Contents Deps (require)
provider/anthropic native Anthropic Messages adapter engine + anthropic-sdk-go
provider/openai OpenAI Responses adapter engine + openai-go/v3 + provider/ssefilter
provider/openaichat OpenAI Chat Completions adapter engine + openai-go/v3 + provider/ssefilter
provider/ssefilter shared SSE keepalive filter openai-go/v3/option only
  • Opt-in by import: each module has its own go.mod; a consumer go gets exactly one provider and inherits only that SDK + the engine's tiny closure. The engine module is untouched (ADR 0036's tiny-closure promise holds).
  • Single-source fence intact: the adapters are byte-identical moves (git mv) — no logic change, no second copy to drift.
  • Consumers keep real policy — credentials, custom auth, thinking on/off, model choice — via the existing Options pattern; wire-format correctness now comes from the library.
  • llmresilience / providercatalog / openrouter / openaicompat stay root-side — a harness decorator and stdlib-only leaves, not wire-format providers.
  • Tag grammar provider/<name>/vX.Y.Z (same as engine/v*); the v* release trigger does not fire on these.

The one design decision — version pinning + the private-repo standalone wall

Each provider go.mod requires the engine at the published v0.8.0 (no replace — a committed replace breaks downstream go get), resolved to the local tree via go.work for dev.

Consequence: the GOWORK=off standalone hygiene gate (provider-standalone CI job + test:provider-standalone) can only cover provider/ssefilter — the sole self-contained provider (no mecatl-module dependency). anthropic/openai/openaichat each require another mecatl module, and mecatl is a private/INTERNAL repo, so a GOWORK=off build must fetch that dep from the origin — proxy.golang.org can't serve a private module and the job checks out with persist-credentials: false, so the fetch 401s. They're covered by the workspace (GOWORK=on) build/test; their standalone proof is deferred until the repo is public or git credentials + GOPRIVATE are wired. Recorded in ADR 0093 and tracked in #379.

Verification

  • provider-standalone (GOWORK=off) — ssefilter ✓ (anthropic/openai/openaichat deferred per above)
  • task lint — 0 issues across all 6 modules; task test — root + engine + all 4 providers + both standalone gates
  • task api:check, go test ./docs/lint/, task docs, task site:build, go run ./cmd/mecademo — all green

Panel review (spec / standards / software-architect / devops): architecture verdict "sound, ship it". Findings fixed in this PR: 4 stale internal/adapter/... Go-comment backpaths; the multi-line cd subshell bug across the provider CI jobs; the private-repo standalone fetch wall.

Docs

New ADR 0093 (docs/adr/0093-provider-modules.md). The ~30 internal/adapter/... citations across the frozen ADRs + living docs are repointed to provider/<name>/ (the docs/lint anti-drift gate). AGENTS.md, docs/architecture*.md, and user-docs/ (embed-engine, extension-points) updated; llms.txt regenerated.

Follow-ups (not in this PR)

  • Cut provider/ssefilter tag to unblock the openai/openaichat standalone gate #379 — widen the provider-standalone gate to all four modules (needs repo-public OR git-credentials+GOPRIVATE, plus the first provider/ssefilter tag).
  • Renumber the operator's 0092-no-project-trust-pin ADR (on feat/359) to 0091 — the existing 0090 collision means 0092 was taken; this ADR is 0093. Flagged, not touched here.

The engine module ships port.LLMProvider and mockllm, but the real adapters
lived in the root module's internal/adapter/, unimportable — so an engine
embedder had to re-derive wire-format logic that has exactly one correct answer
(Anthropic prompt-cache breakpoint placement, message ordering, stream
assembly, usage accounting). Getting it wrong is silent and costly: misplaced
cache breakpoints turn every turn of a long tool-calling loop into a
full-transcript reprocess at full input price.

forced on every engine importer — but that argued against the *engine module*,
not against shipping them. Ship them as a provider/ subtree of opt-in Go
submodules, so the dependency is opt-in by import (Jeremy's mechanism):

- provider/anthropic   — native Anthropic Messages adapter (zero couplings)
- provider/openai      — OpenAI Responses adapter
- provider/openaichat  — OpenAI Chat Completions adapter
- provider/ssefilter   — the shared SSE keepalive filter (openai + openaichat)

Each carries its own go.mod (require engine + its SDK; openai/openaichat also
require provider/ssefilter), so a consumer go gets exactly one provider and
inherits only that SDK + the engine's tiny closure. llmresilience /
providercatalog / openrouter / openaicompat stay root-side (a harness decorator
and stdlib-only leaves, not wire-format providers). The engine module is
untouched.

Registration: go.work use, root go.mod require+replace, Taskfile second passes,
ci.yml per-module jobs + a provider-standalone GOWORK=off gate (scoped to
ssefilter + anthropic — openai/openaichat defer until provider/ssefilter is
tagged), perf.yml cache keys, dependabot, depguard rules, release.yml
tag-grammar doc (provider/<name>/v*). New ADR 0093 records the decision. The
~30 internal/adapter/... doc citations across the frozen ADRs + living docs are
repointed to provider/<name>/ (docs/lint gate), and AGENTS.md / user-docs are
updated.

Co-Authored-By: Juan Antonio Osorio <[email protected]>
@JAORMX
JAORMX force-pushed the feat/362-provider-module branch from 205fa56 to dea2099 Compare August 4, 2026 22:03
JAORMX and others added 3 commits August 5, 2026 01:08
The provider-standalone job's run blocks did 'cd provider/ssefilter && ...'
then 'cd provider/anthropic && ...' on separate lines of the SAME shell — the
first cd persisted, so the second resolved to provider/ssefilter/provider/
anthropic and failed. Wrap each in a subshell. Same gate logic; scoped to
ssefilter + anthropic until provider/ssefilter is tagged (ADR 0093).

Co-Authored-By: Juan Antonio Osorio <[email protected]>
…lms.txt

The build/test/lint/vet/vuln provider jobs each ran several 'cd provider/X && ...'
lines in ONE shell — the first cd persisted, so every later line resolved under
provider/ssefilter/provider/... and failed. Subshell each (the same fix as the
standalone gate). Also regenerate llms.txt now that the scratch PLAN-362.md is
gone (159 docs / 0 orphans).

Co-Authored-By: Juan Antonio Osorio <[email protected]>
…po fetch wall

anthropic/openai/openaichat each require another mecatl module (engine, and
provider/ssefilter for the openai-go family). mecatl is a private/INTERNAL repo,
so a GOWORK=off build must fetch that dep from the origin — proxy.golang.org
can't serve a private module, and the job checks out with
persist-credentials: false, so the fetch 401s (git ls-remote exit 128). The
earlier 'deferred until ssefilter is tagged' framing was wrong: even anthropic
(engine is a published v0.8.0 tag) cannot fetch it privately. Scope the
provider-standalone gate to ssefilter (the only self-contained provider) and
defer the rest until the repo is public or git credentials + GOPRIVATE are
wired; correct ADR 0093 to record the real reason.

Co-Authored-By: Juan Antonio Osorio <[email protected]>
@JAORMX
JAORMX merged commit 9455fbb into main Aug 4, 2026
16 checks passed
@JAORMX
JAORMX deleted the feat/362-provider-module branch August 4, 2026 22:35
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.

Ship the provider adapters out of the box (opt-in module)

1 participant