X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/581a88014e0acaf9e91de6d0a7037f9077bfe288..4a605fa39078354654ae648e489c117c7a445197:/prompt.go diff --git a/prompt.go b/prompt.go index e3c52c4..e48c5a6 100644 --- a/prompt.go +++ b/prompt.go @@ -5,15 +5,30 @@ import ( "strings" ) -// promptName stands for the name of the agent in promptText. -const promptName = "{name}" - -// promptText is the system prompt of the UniiChat design, nearly word for word, -// with the name of the agent in place of Unii and the kind reply in place of -// unii. It describes only what OneChat can do, so it leaves out the spec text -// on images, subagents, computers, background tasks, and the instructions of -// the user. It holds no date and no state, so turns and compactions share its -// prompt cache. +const ( + // promptName stands for the name of the agent in promptText. + promptName = "{name}" + + // taskSentence is the sentence of promptText that gets instructionsClause + // when the user has instructions. + taskSentence = "Do the user's tasks yourself, with your tools." + + // instructionsClause points to the instructions of the user at the end + // of the prompt. + instructionsClause = ", following the user's instructions\nat the end of this prompt: who they are, how their files are organized and how\nthey want work done" + + // instructionsHeading starts the instructions of the user after + // promptText. + instructionsHeading = "\n\n# The user's instructions\n\n" +) + +// promptText is the system prompt of the reference design, nearly word for +// word. The reference design names its own agent, so promptText has the name of +// the agent and the kind reply in its place. It describes only what OneChat can +// do, so it leaves out the spec text on images, subagents, computers, and +// background tasks. prompt adds the clause on the instructions of the user only +// when there are instructions. It holds no date and no state, so turns and +// compactions share its prompt cache. const promptText = `You are {name}, an AI agent that works for one user in a single chat that never ends. Each call to you is a turn or a compaction: the view below is followed by the user's new message, or by a task starting "Compaction:". @@ -92,11 +107,20 @@ exactly. Tag each item with its kind ("user: ...; echo: ..."), and credit quoted text to its real author. Never make anything look further along than it was. If told the line is too long, shorten it. Non-ASCII characters cost 2-4 bytes.` -// prompt returns the system prompt of the agent name. Turns and compactions -// send the same prompt and tools, so compactions read the prompt cache of the -// turns. -func prompt(name string) string { - return strings.ReplaceAll(promptText, promptName, name) +// prompt returns the system prompt of the agent name with the instructions of +// the user at its end. Without instructions it has neither them nor the clause +// that points to them. Turns and compactions send the same prompt and tools, so +// compactions read the prompt cache of the turns. +func prompt(name, instructions string) string { + text := strings.ReplaceAll(promptText, promptName, name) + instructions = strings.TrimSpace(instructions) + if instructions == "" { + return text + } + + text = strings.Replace(text, taskSentence, strings.TrimSuffix(taskSentence, ".")+instructionsClause+".", 1) + + return text + instructionsHeading + instructions } // agentTools returns the function tools of every call: zoom and date. A