]> git.giacomolli.uk - onechat/blob - prompt_test.go
Store the subagents and read them with zoom
[onechat] / prompt_test.go
1 package main
2
3 import (
4 "encoding/json"
5 "maps"
6 "slices"
7 "strings"
8 "testing"
9
10 "github.com/stretchr/testify/require"
11 )
12
13 func TestPromptNamesTheAgent(t *testing.T) {
14 text := prompt("Ada", "")
15 require.Contains(t, text, "You are Ada, an AI agent")
16 require.Contains(t, text, "- reply: Ada's replies")
17 require.Contains(t, text, "Goal: let Ada work later")
18 require.Contains(t, text, `- work: an agent's report, starting "[Name]"`)
19 require.Contains(t, text, "- zoom(id, 1) gives message id whole\n- zoom(\"Name\") gives an agent's whole chat\n")
20 require.NotContains(t, text, promptName)
21
22 // The old agent name is built from parts, so the source does not spell
23 // it.
24 require.NotContains(t, strings.ToLower(text), "u"+"nii")
25 }
26
27 func TestPromptLeavesOutAbsentFeatures(t *testing.T) {
28 text := prompt("Ada", "")
29 for _, absent := range []string{"image", "ubagent", "computer", "device", "instructions at the end"} {
30 require.NotContains(t, text, absent)
31 }
32 }
33
34 func TestPromptEndsWithTheInstructions(t *testing.T) {
35 text := prompt("Ada", "\nI am Lena. Keep replies short.\n\n")
36 require.Contains(t, text, `Do the user's tasks yourself, with your tools, following the user's instructions
37 at the end of this prompt: who they are, how their files are organized and how
38 they want work done.`)
39 require.True(t, strings.HasSuffix(text, "\n\n# The user's instructions\n\nI am Lena. Keep replies short."))
40 }
41
42 func TestPromptWithoutInstructionsHasNoClause(t *testing.T) {
43 for _, instructions := range []string{"", " \n\t"} {
44 text := prompt("Ada", instructions)
45 require.Contains(t, text, "Do the user's tasks yourself, with your tools.\n")
46 require.NotContains(t, text, "instructions")
47 }
48 }
49
50 func TestAgentToolsAreStrictAndStable(t *testing.T) {
51 tools := promptTools()
52 names := make([]string, len(tools))
53 for n, tool := range tools {
54 names[n] = tool.Name
55 }
56
57 require.Equal(t, []string{"zoom", "date", "shell", "read", "write", "edit"}, names)
58
59 for _, tool := range tools {
60 schema := tool.Parameters.(map[string]any)
61 properties := schema["properties"].(map[string]any)
62 require.True(t, tool.Strict, tool.Name)
63 require.Equal(t, false, schema["additionalProperties"], tool.Name)
64 require.Equal(t, slices.Sorted(maps.Keys(properties)), schema["required"], tool.Name)
65 }
66
67 first, err := json.Marshal(tools)
68 require.NoError(t, err)
69
70 for range 10 {
71 again, err := json.Marshal(promptTools())
72 require.NoError(t, err)
73 require.Equal(t, first, again)
74 }
75 }