The chat agent's entire system prompt was the four-sentence static string in gateway.DefaultPersonas(). It carried no tool inventory, no environment block and no instruction precedence, so the model invented its own capabilities: asked to set something up it announced it "only has the memory editing tool", then offered to walk through installing software it has no tool to install. Renders a template modelled on tau's agent.md.tpl + tau.agent.md: instruction precedence, core rules, communication rules, a <tools> block and an <env> block. The persona stays the style layer on top; the rules and the tool inventory live in the template so switching persona cannot remove them. The tool list is derived from the same core.ToolSet handed to the model, so the prompt cannot drift from what the agent can actually call, and an empty toolset renders an explicit "no tools are available" rather than silence the model fills in for itself. Tool metadata is third-party data from MCP servers, so it is markup-escaped (<, >, & only — not xml.EscapeText, which mangles prose into 
/') and whitespace-flattened, so a description cannot forge a closing tag or a second "- tool: ..." list entry.
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
aicore "github.com/samcharles93/ai-sdk/core"
|
|
)
|
|
|
|
func TestToolSummaries(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
set aicore.ToolSet
|
|
want []string // expected "name: description" pairs, in order
|
|
}{
|
|
{
|
|
name: "nil set yields no summaries",
|
|
set: nil,
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "empty set yields no summaries",
|
|
set: aicore.ToolSet{},
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "summaries are sorted by name for a stable prompt",
|
|
set: aicore.ToolSet{
|
|
"skill_activate": aicore.NewTool("skill_activate", "Load a skill", nil, nil),
|
|
"memory_edit": aicore.NewTool("memory_edit", "Edit memory", nil, nil),
|
|
},
|
|
// ToolSet is a map: without sorting the prompt text would
|
|
// differ between turns and defeat provider prompt caching.
|
|
want: []string{"memory_edit: Edit memory", "skill_activate: Load a skill"},
|
|
},
|
|
{
|
|
name: "nil entries are skipped rather than panicking",
|
|
set: aicore.ToolSet{"broken": nil},
|
|
want: nil,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := toolSummaries(tc.set)
|
|
if len(got) != len(tc.want) {
|
|
t.Fatalf("toolSummaries() returned %d summaries, want %d: %+v", len(got), len(tc.want), got)
|
|
}
|
|
for i, want := range tc.want {
|
|
joined := got[i].Name + ": " + got[i].Description
|
|
if joined != want {
|
|
t.Errorf("summary %d = %q, want %q", i, joined, want)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|