State each model stage's permitted tools in its prompt

A planner had no machine-readable view of the tool set later stages would
have, so it could emit acceptance checks that required tools (shell) the
implementer was not permitted, causing a blocked run.

modelPrompt now emits exactly one authoritative line naming the stage's
permitted tools, derived from the definition via the new effectiveTools
helper. effectiveTools reuses ToolNames: a present tools block, including
an explicit empty one, is returned as parsed; an absent block yields the
legacy mutating read/glob/grep/edit/shell bundle so it is never
misrepresented as empty or read-only. The bundle is declared once as
legacyTools and reused by tools.go, agent.go, pi.go and permissions.go.

The redundant client-side strings.Replace of the tools line is removed
from AgentClient.Generate and PiClient.Generate; the agent-only guidance
sentence is preserved by appending it in agent.go, and Pi appends a short
mapping line derived from piTools. Edit-scope and permitted-shell text,
routing, review, budgets and retries are unchanged.

Adds internal/stage/model_prompt_test.go covering explicit, absent and
explicit-empty blocks plus derivation edge cases, and a guard that the
agent prompt still carries the tools, edit-scope and shell-command text.
This commit is contained in:
2026-10-16 23:34:39 +01:00
parent 0937327e8c
commit c41bf4f5b0
6 changed files with 212 additions and 10 deletions
+8 -2
View File
@@ -76,7 +76,7 @@ func (c *PiClient) RepairFormat(ctx context.Context, config ModelConfig, text st
func piTools(tools []string) ([]string, error) {
if tools == nil {
tools = []string{"read", "glob", "grep", "edit", "shell"}
tools = legacyTools
}
names := []string{}
for _, tool := range tools {
@@ -283,7 +283,13 @@ func (c *PiClient) Generate(ctx context.Context, config ModelConfig, prompt stri
}
owned = true
}
prompt = strings.Replace(prompt, "This call has no tools.", "This call has only these stage tools: "+strings.Join(tools, ", ")+".", 1)
// The authoritative permitted-tools line is emitted once by modelPrompt. Pi
// realizes those canonical tool names through its own audited builtins, so
// append that derived mapping here rather than hardcoding Pi names. An
// explicit empty block stays text-only and gets no extra line.
if len(tools) > 0 {
prompt += "\nThis Pi harness exposes these builtin tools: " + strings.Join(tools, ", ") + "."
}
c.WorkStarted = true
if _, err = c.rpc(ctx, "prompt", map[string]any{"message": prompt}); err != nil {
return "", err