Files
archie/internal/platform/prompts/prompts.go
T
sam eadb88d3bf feat(governance): serve the organisation's instructions to every agent (#2023)
The organisation's standing instructions are stored per organisation and
join the system prompt of chat turns and workflow agent steps. The Org
configuration group is served: schedules, alert webhook, playbooks,
models, connections and credential bindings open the page that already
owns the concept.
2026-11-22 11:24:25 +11:00

93 lines
2.5 KiB
Go

// Package prompts holds every instruction the binary sends to a model, one
// file each, so a prompt is reviewed as text rather than read out of code.
package prompts
import (
_ "embed"
"strings"
"text/template"
"time"
)
//go:embed agent.md
var agent string
//go:embed follow_through.md
var followThrough string
//go:embed record_cause.md
var recordCause string
//go:embed model-probe.md
var modelProbe string
// FollowThrough is added to an agent's prompt when it described an action it
// didn't call.
func FollowThrough() string { return followThrough }
// Agent is how every agent step of a workflow works. The workflow's
// instructions and the step's mission follow it.
func Agent() string { return agent }
// RecordCause is the system prompt of the turn that files an investigation's
// cause in Archie's memory.
func RecordCause() string { return recordCause }
// ModelProbe is the one question a saved model is tested with, so the operator
// learns the endpoint, model and key work before relying on them.
func ModelProbe() string { return modelProbe }
//go:embed chat_system.tmpl
var chatSystem string
//go:embed soul.md
var soul string
//go:embed product_guide.md
var productGuide string
//go:embed session_title.md
var sessionTitle string
var chatTemplate = template.Must(template.New("chat").Funcs(template.FuncMap{"xml": EscapeXML}).Parse(chatSystem))
// EscapeXML replaces the bytes that would be read as markup inside a
// trust="data" block.
var EscapeXML = strings.NewReplacer("&", "&amp;", "<", "&lt;", ">", "&gt;").Replace
// ChatTool is one tool as the chat prompt lists it.
type ChatTool struct {
Name string
Description string
}
// ChatContext is what a chat turn's system prompt is filled from.
type ChatContext struct {
Tools []ChatTool
Channel string
Page string
Model string
SessionID string
Memory string
// Instructions are the organisation's standing instructions.
Instructions string
Now time.Time
}
// ChatSystem is the chat agent's system prompt: its soul, the core rules, the
// product guide, its tools, what it remembers and where it is asked from.
func ChatSystem(c ChatContext) string {
data := struct {
ChatContext
Soul, Date, ProductGuide string
}{c, soul, c.Now.Format("2006-01-02"), productGuide}
var b strings.Builder
if err := chatTemplate.Execute(&b, data); err != nil {
panic("prompts: render chat system: " + err.Error())
}
return strings.TrimSpace(b.String())
}
// SessionTitle instructs the model to title a conversation.
func SessionTitle() string { return sessionTitle }