Layered prompt rendering from embedded templates
Skill prompts are text/template files embedded from internal/ai/skills/prompts/, one per skill version (<skill>.v<version>.tmpl) defining "instructions" and "user". Templates are parsed at start with missingkey=error; a bad template stops the service. harness.Render builds the system prompt in fixed order (D-007): [1] the admin persona from ai_settings.system_prompt (Config.Persona), [2] the skill instructions, [3] the household context block, [4] the output contract quoting the JSON Schema. The contract is always the last layer whatever the persona says. The household context is a seam of titled sections until BuildContext lands; an empty one renders a defined block. Skill.Render is replaced by Skill.PromptInput. Golden tests pin the exact system prompt and user message for the echo test skill, with and without persona, and under a hostile persona that says "ignore the format below" or fakes a contract heading. checksums.txt records each template's SHA-256; a template change without a version bump fails TestTemplateChecksums naming the skill and version. Maestro task bceca7a8-bc30-48df-944d-84557a1f4154. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,9 +9,13 @@ import (
|
||||
)
|
||||
|
||||
// echoSkill is the trivial test skill: it asks the model to repeat a word.
|
||||
// Its prompt is prompts/echo.v1.tmpl.
|
||||
type echoSkill struct{}
|
||||
|
||||
type echoInput struct{ Word string }
|
||||
type echoInput struct {
|
||||
Word string
|
||||
Context []ContextSection
|
||||
}
|
||||
|
||||
type echoOutput struct {
|
||||
Echo string `json:"echo"`
|
||||
@@ -23,11 +27,11 @@ func (echoSkill) Name() string { return "echo" }
|
||||
|
||||
func (echoSkill) Version() int { return 1 }
|
||||
|
||||
func (echoSkill) Render(in echoInput) (Prompt, error) {
|
||||
func (echoSkill) PromptInput(in echoInput) (PromptInput, error) {
|
||||
if in.Word == "" {
|
||||
return Prompt{}, errors.New("no word to echo")
|
||||
return PromptInput{}, errors.New("no word to echo")
|
||||
}
|
||||
return Prompt{System: "You repeat words.", User: "Repeat: " + in.Word}, nil
|
||||
return PromptInput{Data: in, Context: in.Context}, nil
|
||||
}
|
||||
|
||||
func (echoSkill) Schema() llm.JSONSchema {
|
||||
|
||||
Reference in New Issue
Block a user