10 "github.com/stretchr/testify/require"
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)
22 // The old agent name is built from parts, so the source does not spell
24 require.NotContains(t, strings.ToLower(text), "u"+"nii")
27 func TestPromptLeavesOutAbsentFeatures(t *testing.T) {
28 text := prompt("Ada", "")
29 for _, absent := range []string{"image", "computer", "device", "instructions at the end"} {
30 require.NotContains(t, text, absent)
34 func TestPromptHasTheLinesOnSubagents(t *testing.T) {
35 text := prompt("Ada", "")
36 require.Contains(t, text, "Do the user's tasks yourself, with your tools.\nUse subagents only when the user asks for them.\n")
37 require.Contains(t, text, `Messages the user sends while you work reach you between tool calls.
38 Subagents run in the background; each one's report reaches you as a message
39 starting "[Name]", between your tool calls or as a new turn. Never wait for one
40 (no sleep, no polling): go on, or end your turn and tell the user what is
45 func TestSubagentPromptNamesTheAgentAndEndsWithTheInstructions(t *testing.T) {
46 text := promptSubagent("Ada", "\nI am Lena.\n")
47 require.True(t, strings.HasPrefix(text, "You are a subagent of Ada, an AI agent"))
48 require.Contains(t, text, "Ada gave you a task. Do it yourself, with your tools,\nfollowing the user's instructions at the end of this prompt: they say who the\nuser is, how their files are organized and how they want work done.\n")
49 require.Contains(t, text, "zoom(\"Name\") gives an agent's\nwhole chat.")
50 require.True(t, strings.HasSuffix(text, "\n\n# The user's instructions\n\nI am Lena."))
51 require.NotContains(t, text, promptName)
53 for _, absent := range []string{"image", "computer", "device", "Compaction"} {
54 require.NotContains(t, text, absent)
57 text = promptSubagent("Ada", " \n")
58 require.Contains(t, text, "Ada gave you a task. Do it yourself, with your tools.\n")
59 require.NotContains(t, text, "instructions")
62 func TestPromptEndsWithTheInstructions(t *testing.T) {
63 text := prompt("Ada", "\nI am Lena. Keep replies short.\n\n")
64 require.Contains(t, text, `Do the user's tasks yourself, with your tools, following the user's instructions
65 at the end of this prompt: who they are, how their files are organized and how
66 they want work done.`)
67 require.True(t, strings.HasSuffix(text, "\n\n# The user's instructions\n\nI am Lena. Keep replies short."))
70 func TestPromptWithoutInstructionsHasNoClause(t *testing.T) {
71 for _, instructions := range []string{"", " \n\t"} {
72 text := prompt("Ada", instructions)
73 require.Contains(t, text, "Do the user's tasks yourself, with your tools.\n")
74 require.NotContains(t, text, "instructions")
78 func TestAgentToolsAreStrictAndStable(t *testing.T) {
79 tools := promptTools()
80 require.Equal(t, []string{"zoom", "date", "shell", "read", "write", "edit", "spawn", "tell"}, promptToolNames(tools))
81 require.Equal(t, []string{"zoom", "date", "shell", "read", "write", "edit"}, promptToolNames(promptSubagentTools()))
83 for _, tool := range tools {
84 schema := tool.Parameters.(map[string]any)
85 properties := schema["properties"].(map[string]any)
86 require.True(t, tool.Strict, tool.Name)
87 require.Equal(t, false, schema["additionalProperties"], tool.Name)
88 require.Equal(t, slices.Sorted(maps.Keys(properties)), schema["required"], tool.Name)
91 first, err := json.Marshal(tools)
92 require.NoError(t, err)
95 again, err := json.Marshal(promptTools())
96 require.NoError(t, err)
97 require.Equal(t, first, again)
101 // promptToolNames returns the names of tools.
102 func promptToolNames(tools []ModelTool) []string {
103 names := make([]string, len(tools))
104 for n, tool := range tools {