Unified Agent + reusable Go agent core.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Add system prompt template rendering for agent

Lyric 70cd93fa e10cc5e9

+57
+57
agent/prompt_template.go
··· 1 + package agent 2 + 3 + import ( 4 + _ "embed" 5 + "strings" 6 + 7 + "github.com/quailyquaily/mistermorph/internal/prompttmpl" 8 + "github.com/quailyquaily/mistermorph/tools" 9 + ) 10 + 11 + //go:embed prompts/system.tmpl 12 + var systemPromptTemplateSource string 13 + 14 + var systemPromptTemplate = prompttmpl.MustParse("agent_system_prompt", systemPromptTemplateSource, nil) 15 + 16 + type systemPromptTemplateBlock struct { 17 + Title string 18 + Content string 19 + } 20 + 21 + type systemPromptTemplateData struct { 22 + Identity string 23 + Blocks []systemPromptTemplateBlock 24 + ToolSummaries string 25 + HasPlanCreate bool 26 + Rules []string 27 + } 28 + 29 + func renderSystemPrompt(registry *tools.Registry, spec PromptSpec) (string, error) { 30 + data := systemPromptTemplateData{ 31 + Identity: spec.Identity, 32 + Blocks: make([]systemPromptTemplateBlock, 0, len(spec.Blocks)), 33 + Rules: make([]string, 0, len(spec.Rules)), 34 + } 35 + for _, blk := range spec.Blocks { 36 + title := strings.TrimSpace(blk.Title) 37 + if title == "" { 38 + title = "Context" 39 + } 40 + data.Blocks = append(data.Blocks, systemPromptTemplateBlock{ 41 + Title: title, 42 + Content: strings.TrimSpace(blk.Content), 43 + }) 44 + } 45 + for _, rule := range spec.Rules { 46 + rule = strings.TrimSpace(rule) 47 + if rule == "" { 48 + continue 49 + } 50 + data.Rules = append(data.Rules, rule) 51 + } 52 + if registry != nil { 53 + data.ToolSummaries = registry.FormatToolSummaries() 54 + _, data.HasPlanCreate = registry.Get("plan_create") 55 + } 56 + return prompttmpl.Render(systemPromptTemplate, data) 57 + }