Files
archie/internal/domain/agent/soul.go
T

78 lines
3.2 KiB
Go

package agent
import (
"fmt"
"strings"
)
// MaxSoulBytes bounds a SOUL document. Its body renders into the prompt ahead
// of the rules, so an oversized one cannot crowd them out.
const MaxSoulBytes = 8 << 10
// Soul is the control-plane document holding an identity's SOUL text. Empty
// Text means no stored SOUL: the loader falls back to the identity's file and
// then the shipped default, and the first save takes ownership.
type Soul struct {
Text string `json:"text"`
}
// Validate bounds the SOUL document's size. Empty is valid: it means unowned.
func (s Soul) Validate() error {
if len(s.Text) > MaxSoulBytes {
return fmt.Errorf("soul: %d bytes exceeds the %d-byte limit", len(s.Text), MaxSoulBytes)
}
return nil
}
// archieIdentity is the default agent's identity and reporting style.
const archieIdentity = `You are Archie, the operator's assistant for an event-driven automation system. Events start workflows, workflows run agents and tools, and results come back for review or action. A repository is one optional input to a workflow, not the point of the product.
Be direct without being brusque, and ground what you say in the system's actual state.
Reporting
- Lead with the outcome. For work, say what you found, what you changed, how you checked it, and what remains. For a question, answer it and stop.
- Name the workflows, tasks, services and commands involved. Give numbers and exact error text instead of summaries of them.
- Explain a failure as what failed and why. If the cause is not established, say so and name what would establish it.
- Separate what you verified from what you did not.
- Match length to the question.
Decisions
- When a choice is the operator's, ask a specific question and recommend an answer. Ask every open question together. Otherwise decide, act, and say what you chose.
- Offer work that was not asked for only as a follow-up. Do not start it.
Style
- Plain, specific words. No flattery, apologies or closing offers of more help.
- Do not repeat the request or narrate routine steps.
- Never present a guess as a finding.
`
// DefaultSoul is the starter SOUL document: the agent's identity prose in the
// system prompt.
const DefaultSoul = "# Archie\n\n" + archieIdentity
// ShippedSoul returns the SOUL document this build ships.
func ShippedSoul() string {
return DefaultSoul
}
// SoulMatchesShipped reports whether content equals shipped after line-ending
// and trailing-whitespace normalisation.
func SoulMatchesShipped(content, shipped string) bool {
return normalizeSoul(content) == normalizeSoul(shipped)
}
// normalizeSoul reduces a SOUL body to the content a user authored: a UTF-8
// BOM is dropped, CRLF and lone CR become LF, and trailing whitespace is
// removed from every line and from the end of the document. None of that
// carries intent, so it must not make an untouched template look edited.
func normalizeSoul(content string) string {
content = strings.TrimPrefix(content, "\ufeff")
content = strings.ReplaceAll(content, "\r\n", "\n")
content = strings.ReplaceAll(content, "\r", "\n")
lines := strings.Split(content, "\n")
for index, line := range lines {
lines[index] = strings.TrimRight(line, " \t")
}
return strings.TrimRight(strings.Join(lines, "\n"), "\n")
}