systemprompt.go RawHistoryFolder
1package agent
2
3import (
4 "fmt"
5 "strings"
6 "time"
7)
8
9// ToolSummary is a name+one-line description. Kept for backwards
10// compatibility with callers that still pass tool summaries in; the
11// built-in system prompt no longer lists tools by name, since the
12// tool schemas themselves already reach the model.
13type ToolSummary struct {
14 Name string
15 Description string
16}
17
18// SystemPromptOpts configures BuildSystemPrompt.
19type SystemPromptOpts struct {
20 CWD string
21 Tools []ToolSummary
22 Custom string // if set, replaces the default identity/guidelines sections
23 Append []string // extra text appended at the end
24 Now time.Time
25}
26
27// BuildSystemPrompt constructs the system prompt.
28//
29// Design note: the prompt is intentionally tiny. Every byte here
30// is re-sent on every request (cached after the first, but still
31// counts toward cache-write on turn 1 and live context throughout).
32// We avoid:
33//
34// - Listing the tool names and descriptions (the provider sends
35// the tool schemas separately; duplicating them costs tokens
36// for zero benefit, the model already sees the tools).
37// - Repeating generic coding-assistant advice the frontier models
38// already internalise ("always read before editing", "prefer
39// minimal diffs", "don't apologize"). These were free tokens
40// on older models; they are pure overhead now.
41//
42// Anything the user explicitly needs can still be added via
43// --system-prompt, --append-system-prompt, or $ZOT_HOME/SYSTEM.md.
44func BuildSystemPrompt(o SystemPromptOpts) string {
45 if o.Now.IsZero() {
46 o.Now = time.Now()
47 }
48 date := o.Now.Format("2006-01-02")
49 cwd := o.CWD
50 if cwd == "" {
51 cwd = "."
52 }
53
54 var sb strings.Builder
55
56 if o.Custom != "" {
57 sb.WriteString(o.Custom)
58 } else {
59 sb.WriteString(defaultIdentity)
60 }
61
62 for _, a := range o.Append {
63 if strings.TrimSpace(a) == "" {
64 continue
65 }
66 sb.WriteString("\n\n")
67 sb.WriteString(a)
68 }
69
70 fmt.Fprintf(&sb, "\n\nCurrent date: %s\nCurrent working directory: %s\n", date, cwd)
71 return sb.String()
72}
73
74const defaultIdentity = `You are zot, a lightweight terminal coding agent. Be concise, act on the user's request directly, and reply with a short summary when done.`