systemprompt.go RawHistoryFolder
1package agent
2
3import (
4 "fmt"
5 "strings"
6 "time"
7)
8
9// ToolSummary is a name+one-line description, used when rendering the
10// "available tools" section of the system prompt.
11type ToolSummary struct {
12 Name string
13 Description string
14}
15
16// SystemPromptOpts configures BuildSystemPrompt.
17type SystemPromptOpts struct {
18 CWD string
19 Tools []ToolSummary
20 Custom string // if set, replaces the default identity/guidelines sections
21 Append []string // extra text appended at the end
22 Now time.Time
23}
24
25// BuildSystemPrompt constructs the system prompt.
26func BuildSystemPrompt(o SystemPromptOpts) string {
27 if o.Now.IsZero() {
28 o.Now = time.Now()
29 }
30 date := o.Now.Format("2006-01-02")
31 cwd := o.CWD
32 if cwd == "" {
33 cwd = "."
34 }
35
36 var sb strings.Builder
37
38 if o.Custom != "" {
39 sb.WriteString(o.Custom)
40 } else {
41 sb.WriteString(defaultIdentity)
42 sb.WriteString("\n\n")
43 sb.WriteString(renderToolsSection(o.Tools))
44 sb.WriteString("\n")
45 sb.WriteString(defaultGuidelines)
46 }
47
48 for _, a := range o.Append {
49 if strings.TrimSpace(a) == "" {
50 continue
51 }
52 sb.WriteString("\n\n")
53 sb.WriteString(a)
54 }
55
56 fmt.Fprintf(&sb, "\n\nCurrent date: %s\nCurrent working directory: %s\n", date, cwd)
57 return sb.String()
58}
59
60func renderToolsSection(tools []ToolSummary) string {
61 if len(tools) == 0 {
62 return "No tools are available in this session."
63 }
64 var sb strings.Builder
65 sb.WriteString("You have the following tools available:\n")
66 for _, t := range tools {
67 fmt.Fprintf(&sb, "- %s: %s\n", t.Name, t.Description)
68 }
69 return sb.String()
70}
71
72const defaultIdentity = `You are zot, a lightweight terminal coding assistant.
73You help a developer by reading files, writing files, editing files, and running shell commands.
74You are concise. You explain your plan briefly, then act. You do not apologize or hedge.`
75
76const defaultGuidelines = `Operating guidelines:
77- Prefer "edit" over "write" for existing files. Always read a file before editing it.
78- Before running "bash", explain what the command will do in one short sentence.
79- Avoid destructive commands (rm -rf, dropping tables, force-pushing, etc.) unless the user explicitly asks.
80- Keep shell commands non-interactive (pass -y / --yes where needed; pipe "yes" if required).
81- When unsure about a file's contents or structure, read it first rather than guess.
82- When you are done, reply with a short summary of what you changed and any commands the user should run.`