Skip to content

feat(prompt): host-pluggable system-prompt builder seam - #128

Merged
JAORMX merged 2 commits into
mainfrom
fix/issue-127-host-pluggable-system-prompt
Jun 20, 2026
Merged

JAORMX merged 2 commits into
mainfrom
fix/issue-127-host-pluggable-system-prompt

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #127.

Adds a small, backward-compatible seam so a host embedding the engine for a non-coding agent can fully own the system prompt (role, tone, safety, tool inventory) with no coding-agent defaults and no Available tools: block, while prompt.Build stays the default.

The Atrium cutover (replacing its hand-rolled agent loop with the imported engine, pinned at engine/v0.0.1) caught that every model turn carries the engine's defaultRole/defaultTone ("you are a headless agentic coding harness… cite code as file_path:line_number… never git add -A"), which a non-coding host (Craig, the Slack weekly-update assistant) cannot opt out of. This seam provides the clean parity path.

The change

  • engine/prompt: new exported Builder func type (func(Config) Layered). prompt.Build is the documented default implementation and literally satisfies it (same signature).
  • engine/agent: new optional Deps.PromptBuilder prompt.Builder field. buildRequest resolves build := e.deps.PromptBuilder; if build == nil { build = prompt.Build } then System: build(cfg) — nil → byte-identical to engine/v0.0.1 (the same prompt.Build over the same cfg, populated in the same order).
  • Isolation: only the MAIN loop's buildRequest routes through Deps.PromptBuilder. The compaction summarizer (engine/agent/cascade.go) builds its own prompt.Layered{StablePrefix: summarizerSystemPrompt} directly and is explicitly unaffected — the summarizer's structured-output contract is host-independent.
  • Composition: internal/app is unchanged. nil is the default and propagates to the loop, so every shipped mecated/mecatui/mecademo build is byte-identical to v0.0.1. The seam is purely for external embedders (host-embedding concern, not an operator flag — per the issue).

Why the builder-only shape (no tunable knobs)

The issue floated two options: (1) a pluggable builder, (2) narrower knobs (Config.OmitToolInventory bool, Config.RawPrefix string). This lands only the builder. Justification:

  • The builder alone satisfies the acceptance criterion ("host can produce a prompt with NONE of the defaults and NONE of the layers it didn't ask for") — a host returns prompt.Layered{StablePrefix: hostRole} and ignores cfg.Tools.
  • The knobs are strictly less general (can only suppress known defaults, can't replace the role/tone/safety with arbitrary host content) and would be premature abstraction (one site of use).
  • A host that wants partial reuse calls prompt.Build(cfg) inside its builder and overlays its role — the seam is not all-or-nothing (tested).

Tests

Unit + loop-level e2e (offline, mockllm + memfs — the repo convention):

  • TestBuildSatisfiesBuilder — compile-time + runtime assignability pin (var _ prompt.Builder = prompt.Build).
  • TestBuildRequestNilPromptBuilderIsByteIdenticalToDefault — the v0.0.1 pinning test: nil PromptBuilder produces an LLMRequest.System byte-identical to prompt.Build over the reconstructed turn-0 Config.
  • TestBuildRequestHostPromptBuilderOwnsSystemPrompt — the headline acceptance test: a host builder produces a fully host-owned prompt with none of defaultRole/defaultTone/defaultSafety/Available tools:/the registered tool name, with tools present.
  • TestPromptBuilderHostCanStillUseInventoryAndEnv — flexibility: a host can opt back into the tool inventory + env block by calling prompt.Build from inside its builder.
  • TestPromptBuilderDoesNotRouteThroughCompactionSummarizer — isolation: drives a real CascadeCompactor through the loop with a host builder installed, captures every provider request, and asserts the summarizer request carries summarizerSystemPrompt (not the host marker); fails loudly if compaction never reaches tier-4.
  • TestPromptBuilderAppliesEveryTurn — multi-turn: the host builder is consulted on EACH turn (text→tool-call→text), not just the first.
  • TestPromptBuilderEmptyLayeredIsHonoredNotBackfilled — edge: a host builder returning an empty Layered is honored (no panic, no silent back-fill of defaults).

API / stability contract

  • engine/api/agent.txt + engine/api/prompt.txt regenerated (task api:update); api:check passes.
  • engine/CHANGELOG.md: Added (minor) per engine/COMPATIBILITY.md / ADR-0037 — a new func type and a new struct field, both additive; no existing identifier changed or removed.
  • No new ADR (additive backward-compatible seam; ADR 0024 describes the layered default, which remains the default — the seam adds an opt-out).

Verification

  • task lint — 0 issues (golangci-lint v2 + go vet, both modules).
  • task test — green (full suite + engine-standalone GOWORK=off hygiene proof).
  • task api:check — passes.
  • task docs — llms.txt regenerated, 0 broken links/anchors/orphans.
  • go run ./cmd/mecademo — full offline session still prints (turn → tool.call → result).

Downstream

Atrium will re-pin to the released tag (a fresh engine/vX.Y.Z once merged) and route its assembled prompt through Deps.PromptBuilder, completing the agent-loop-engine-import cutover (Atrium ADR-0068) at true parity.

Add a backward-compatible seam so a host embedding the engine for a
non-coding agent can fully own the system prompt (role/tone/safety/tool
inventory) with no coding-agent defaults and no 'Available tools:' block.

- prompt: new Builder func type (func(Config) Layered); prompt.Build is
  the documented default and literally satisfies it.
- agent: new optional Deps.PromptBuilder field; nil -> prompt.Build,
  byte-identical to engine/v0.0.1.
- agent/loop.go buildRequest resolves the builder once per turn after the
  same cfg population (Tools + volatile Env), so the nil path is provably
  byte-identical. Only the MAIN loop routes through it; the compaction
  summarizer (cascade.go) builds its own prompt.Layered directly and is
  unaffected.

Tests: byte-identity pin (nil == v0.0.1), host-ownership (no defaults, no
tool inventory, tools present), flexibility (host can reuse prompt.Build
helpers), cascade-isolation (summarizer keeps its own prompt), multi-turn
(builder applies every turn), empty-Layered (honored, not back-filled),
and a compile-time assignability pin.

api: agent.txt + prompt.txt regenerated (Added). CHANGELOG: Added (minor)
per COMPATIBILITY.md / ADR-0037.
@JAORMX JAORMX added the e2e-live Run the live e2e suite on this PR label Jun 20, 2026
…ock)

The live e2e default-lane model anthropic/claude-3.5-haiku reached
end-of-life on AWS Bedrock and started 404-ing
("This model version has reached the end of its life"), failing the
provider-smoke canary and gating every later scenario.

Repoint the lane to anthropic/claude-haiku-4.5 — same family, same lane
rationale (tool-call-capable, Bedrock-routed, no OpenAI-family
content_filter on mecatl-shaped tool-bearing requests per finding F2),
catalogued, not EOL'd.

- harness.DefaultModel() default + doc comment (e2e/harness/target.go)
- haikuLane constant value + comment (e2e/restart_helpers_test.go) —
  the single source the 6 hard-pinned specs reference
- approve_after_kill lane comment (e2e/approve_after_kill_test.go)
- modelPricing cost-ledger: add haiku-4.5 ($1/$5 per 1M from catalog),
  keep the 3.5 entry for the historical cost ledger (e2e/suite_test.go)
- e2e/README.md default-lane references

Found by the live e2e run on PR #128 (unrelated to the PR's change —
the prompt-builder seam is offline-tested and the CI lint/test/api/docs
gates are green).
@JAORMX
JAORMX merged commit d3e299e into main Jun 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e-live Run the live e2e suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

engine: make the system prompt host-pluggable (a non-coding host can't suppress the built-in coding-agent prompt)

1 participant