internal/ai/harness defines the generic Skill interface (Name, Version, Render, Schema, Validate, PostProcess) and Run, which renders the prompt, calls Provider.Generate with the skill's schema and the household temperature, strictly decodes and validates the reply, and on failure sends exactly one repair turn quoting the problems. A second failure returns a *BadOutputError matching llm.ErrBadOutput with both problem lists. Provider errors other than ErrBadOutput pass through unchanged. Maestro task 38e7bf98-f1d1-4301-b73b-7ec4b51e8b68. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package harness
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
|
|
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/ai/llm"
|
|
)
|
|
|
|
// echoSkill is the trivial test skill: it asks the model to repeat a word.
|
|
type echoSkill struct{}
|
|
|
|
type echoInput struct{ Word string }
|
|
|
|
type echoOutput struct {
|
|
Echo string `json:"echo"`
|
|
}
|
|
|
|
var _ Skill[echoInput, echoOutput] = echoSkill{}
|
|
|
|
func (echoSkill) Name() string { return "echo" }
|
|
|
|
func (echoSkill) Version() int { return 1 }
|
|
|
|
func (echoSkill) Render(in echoInput) (Prompt, error) {
|
|
if in.Word == "" {
|
|
return Prompt{}, errors.New("no word to echo")
|
|
}
|
|
return Prompt{System: "You repeat words.", User: "Repeat: " + in.Word}, nil
|
|
}
|
|
|
|
func (echoSkill) Schema() llm.JSONSchema {
|
|
return llm.JSONSchema{Name: "echo", Schema: json.RawMessage(
|
|
`{"type":"object","properties":{"echo":{"type":"string"}},"required":["echo"],"additionalProperties":false}`)}
|
|
}
|
|
|
|
func (echoSkill) Validate(out echoOutput) []string {
|
|
if out.Echo == "" {
|
|
return []string{"echo must not be empty"}
|
|
}
|
|
if out.Echo != strings.ToLower(out.Echo) {
|
|
return []string{"echo must be lower case"}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (echoSkill) PostProcess(out echoOutput) (echoOutput, error) {
|
|
out.Echo = strings.TrimSpace(out.Echo)
|
|
return out, nil
|
|
}
|