Skip to content

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

Closed

Description

@JAORMX

Summary

The engine assembles the system prompt with prompt.Build, which always emits a layered prompt and falls back to coding-agent defaults for any field a host leaves empty. A host that embeds the engine for a non-coding agent has no way to fully supply its own system prompt: the built-in role ("you are a headless agentic coding harness"), the coding tone ("cite code as file_path:line_number… never git add -A"), and the layered structure ride on every LLM call regardless of host intent.

Asking for a small, backward-compatible seam so a host can plug in its own system-prompt assembly (and/or tune which built-in layers apply), with prompt.Build staying the default.

Where this came from

Atrium is replacing its hand-rolled agent loop with the imported engine, pinned at engine/v0.0.1 (Atrium ADR-0068). Its first agent is Craig, a weekly-update assistant that talks to Slack — not a coding agent. During the cutover the parity check caught that every model turn now carries the engine's defaultRole/defaultTone, which tell the model it edits a workspace and cites code by line number. That is a behaviour change the host can't opt out of, and the re-platform's whole premise is behaviour parity.

The mechanism (engine/v0.0.1)

agent/loop.go buildRequest builds the system prompt unconditionally from Deps.PromptConfig:

// agent/loop.go ~1490, ~1526
cfg := e.deps.PromptConfig
// … cfg.Tools / cfg.Env populated …
return port.LLMRequest{
    System:   prompt.Build(cfg),   // <- no host override path
    Messages: sess.Conversation.Messages,
    Tools:    cfg.Tools,
    Model:    e.deps.Model,
}

prompt.Build (prompt/builder.go) forces a built-in default whenever a field is empty, and the structure is fixed:

func Build(cfg Config) Layered {
    role := cfg.Role;   if role == ""   { role = defaultRole }
    tone := cfg.Tone;   if tone == ""   { tone = defaultTone }
    safety := cfg.Safety; if safety == "" { safety = defaultSafety }

    // Safety first, then Role, then Tone, then tool-discipline hints,
    // then the tool inventory ("Available tools: …"). Env -> volatile suffix.
}
  • defaultRole = "You are mecatl, a headless agentic coding harness. You operate an agent loop: you call tools to inspect and modify a workspace…"
  • defaultTone = "…Cite code as file_path:line_number… Before changing a file, read it… never git add -A."
  • defaultSafety = the immutable injection-resistance rules.
  • toolInventory(cfg.Tools) is always appended (a Available tools: block, or (none)).
  • EnvBlock(cfg.Env) is always the volatile suffix.

So Config{Role,Tone,Safety,Tools,Env} → Layered{StablePrefix,VolatileSuffix}.

What a host can and can't do today

  • Can: override Role/Tone/Safety by setting them non-empty (empty → mecatl default). So the coding identity can be replaced field-by-field.
  • Can't: supply a single, fully host-owned system prompt. Even with all three fields set, the host still gets mecatl's fixed ordering (Safety → Role → Tone → hints → tool inventory) plus the always-present Available tools: block and <env> suffix. There is no way to bypass the layering or to omit a layer a host doesn't want. Byte-parity with a host that previously sent one assembled system message is impossible.

Note: agent/cascade.go already builds prompt.Layered{StablePrefix: summarizerSystemPrompt} directly for the summarizer turn, so a raw, non-layered prefix is already a shape the engine emits internally — there's precedent for letting that be host-supplied.

Proposed direction (maintainer's call on the exact shape)

A minimal, backward-compatible seam. Two complementary ideas:

  1. Pluggable builder (the main ask). A host-supplied builder that replaces prompt.Build when present. e.g. a func type in the prompt package:

    // prompt/builder.go
    // Builder assembles the system prompt from Config. Build is the default Builder.
    type Builder func(Config) Layered

    and an optional field on agent.Deps:

    // PromptBuilder, when non-nil, assembles the system prompt instead of the
    // built-in prompt.Build. When nil, prompt.Build is used.
    PromptBuilder prompt.Builder

    buildRequest then does build := e.deps.PromptBuilder; if build == nil { build = prompt.Build }; System: build(cfg). prompt.Build already satisfies Builder, so the default is literally the current behaviour. A host (Atrium) supplies a builder that returns its own assembled prompt as the StablePrefix (and can still use cfg.Tools/cfg.Env if it wants the inventory/env). nil → byte-identical to today.

  2. Tunable layers (optional, smaller). If a full builder is more than you want to expose, narrower knobs would still unblock the host: e.g. Config.OmitToolInventory bool, and treating a sentinel (or a separate Config.RawPrefix string) as "use this verbatim, skip the layering." Less flexible than (1) but enough for the parity case.

Either way the key property is: a host can produce a system prompt that contains none of the mecatl coding defaults and none of the layers it didn't ask for.

Backward-compat / contract notes

  • Additive only: a new optional Deps field / a new prompt type. nil/default path is byte-identical to v0.0.1, so existing consumers are unaffected.
  • This touches two COMPATIBILITY-committed core packages (agent, prompt), so it needs task api:update to regenerate engine/api/agent.txt + engine/api/prompt.txt, and a CHANGELOG entry classified Added = minor per engine/COMPATIBILITY.md / ADR-0037.
  • Suggested release: a fresh engine/vX.Y.Z tag once merged, so the host can re-pin off main.

Suggested acceptance criteria

  • A host can construct an engine whose every model turn carries a fully host-supplied system prompt with no defaultRole/defaultTone/defaultSafety text and no Available tools: block unless the host included it.
  • Deps with the new field left nil produces a byte-identical LLMRequest.System to v0.0.1 (a pinning test).
  • prompt.Build remains exported and is the documented default builder.
  • engine/api/*.txt regenerated; CHANGELOG classifies the change as Added (minor).

Downstream

Atrium will re-pin to the released tag and route its assembled prompt through the new seam, completing the agent-loop-engine-import cutover (Atrium ADR-0068) at true parity. Until then Atrium is blocked on a clean parity path for the system prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions