]> git.giacomolli.uk - onechat/blob - prompt_test.go
Hold the agent prompt and tools in one place
[onechat] / prompt_test.go
1 package main
2
3 import (
4 "encoding/json"
5 "maps"
6 "slices"
7 "testing"
8
9 "github.com/stretchr/testify/require"
10 )
11
12 func TestPromptNamesTheAgent(t *testing.T) {
13 text := prompt("Ada")
14 require.Contains(t, text, "You are Ada, an AI agent")
15 require.Contains(t, text, "- reply: Ada's replies")
16 require.Contains(t, text, "Goal: let Ada work later")
17 require.Contains(t, text, `- work: an agent's report, starting "[Name]"`)
18 require.NotContains(t, text, promptName)
19 require.NotContains(t, text, "Unii")
20 require.NotContains(t, text, "unii")
21 }
22
23 func TestPromptLeavesOutAbsentFeatures(t *testing.T) {
24 text := prompt("Ada")
25 for _, absent := range []string{"image", "ubagent", "computer", "device", `zoom("Name")`, "instructions at the end"} {
26 require.NotContains(t, text, absent)
27 }
28 }
29
30 func TestAgentToolsAreStrictAndStable(t *testing.T) {
31 tools := agentTools()
32 require.Equal(t, []string{"zoom", "date"}, []string{tools[0].Name, tools[1].Name})
33
34 for _, tool := range tools {
35 schema := tool.Parameters.(map[string]any)
36 properties := schema["properties"].(map[string]any)
37 require.True(t, tool.Strict, tool.Name)
38 require.Equal(t, false, schema["additionalProperties"], tool.Name)
39 require.Equal(t, slices.Sorted(maps.Keys(properties)), schema["required"], tool.Name)
40 }
41
42 first, err := json.Marshal(tools)
43 require.NoError(t, err)
44
45 for range 10 {
46 again, err := json.Marshal(agentTools())
47 require.NoError(t, err)
48 require.Equal(t, first, again)
49 }
50 }