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.
37 lines
955 B
Go
37 lines
955 B
Go
package main
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
|
|
aicore "github.com/samcharles93/ai-sdk/core"
|
|
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
)
|
|
|
|
// toolSummaries converts the toolset handed to the model into the capability
|
|
// metadata advertised in its system prompt, so the two can never disagree.
|
|
//
|
|
// core.ToolSet is a map, so the result is sorted by name: an unstable tool
|
|
// order would change the system prompt on every turn and defeat provider-side
|
|
// prompt caching.
|
|
func toolSummaries(set aicore.ToolSet) []gateway.ToolSummary {
|
|
summaries := make([]gateway.ToolSummary, 0, len(set))
|
|
for name, tool := range set {
|
|
if tool == nil {
|
|
continue
|
|
}
|
|
summaries = append(summaries, gateway.ToolSummary{
|
|
Name: name,
|
|
Description: tool.Description,
|
|
})
|
|
}
|
|
if len(summaries) == 0 {
|
|
return nil
|
|
}
|
|
slices.SortFunc(summaries, func(a, b gateway.ToolSummary) int {
|
|
return strings.Compare(a.Name, b.Name)
|
|
})
|
|
return summaries
|
|
}
|