fix(subagent): list available agents in unknown-agent error (#1414)

The invalid-params error paths already listed available agents,
but the unknown-agent path in runSingleAgent just returned
'Unknown agent: claude' with no hint what exists.

Now: 'Unknown agent: "claude". Available agents: "worker".'

Model would guess names like "claude", "default", or skill names
like "brave-search". Now it self-corrects on the next call.

Tested with Opus 4.6: without fix, model gave up on subagent
and ran the tool calls itself instead. With fix, 1 wasted call.
This commit is contained in:
Daniel Nouri 2026-02-08 23:04:42 +01:00 committed by GitHub
parent 5b36cacaf3
commit dae2eb5bfa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -231,13 +231,14 @@ async function runSingleAgent(
const agent = agents.find((a) => a.name === agentName); const agent = agents.find((a) => a.name === agentName);
if (!agent) { if (!agent) {
const available = agents.map((a) => `"${a.name}"`).join(", ") || "none";
return { return {
agent: agentName, agent: agentName,
agentSource: "unknown", agentSource: "unknown",
task, task,
exitCode: 1, exitCode: 1,
messages: [], messages: [],
stderr: `Unknown agent: ${agentName}`, stderr: `Unknown agent: "${agentName}". Available agents: ${available}.`,
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0, turns: 0 }, usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0, turns: 0 },
step, step,
}; };