Summary
Delegating to external ACP agents like Fred fails with "agent not found" because their agent.md frontmatter is missing role: delegation-target, causing them to be excluded from the delegation lookup path.
Root Cause
Fred's ~/.agents/agents/286c6b41-.../agent.md has this frontmatter:
---
connection-type: acp
name: Fred
displayName: Fred
enabled: true
id: 286c6b41-28ed-4a57-9728-0bab9846ebe6
kind: agent
---
Missing field: role: delegation-target
How the lookup chain works:
handleDelegateToAgent() → calls agentProfileService.getByName(agentName) (line 587 of acp-router-tools.ts)
getByName() searches this.profilesData.profiles — finds Fred ✅
- BUT
handleListAvailableAgents() → calls getEnabledAgentTargets() → calls getAgentTargets() → calls getByRole("delegation-target") (line 652 of agent-profile-service.ts)
getByRole("delegation-target") filters profiles where p.role === "delegation-target" OR legacy fallback p.isAgentTarget === true
assembleAgentProfile() in agents-files/agent-profiles.ts (line 250) sets: isAgentTarget: mdPartial.role === "delegation-target" || mdPartial.role === "external-agent" || undefined
- Since Fred has no
role in frontmatter → role = undefined → isAgentTarget = undefined → Fred is excluded from agent targets
The inconsistency:
getByName("Fred") in handleDelegateToAgent DOES find Fred (it searches all profiles)
getEnabledAgentTargets() in handleListAvailableAgents DOES NOT include Fred (filtered out by role)
- The system prompt's "AVAILABLE AGENTS" section uses
getByRole('delegation-target') (line 176 of system-prompts.ts) — should also exclude Fred
So delegation to Fred may actually work via getByName() → executeAgentProfileDelegation(), but Fred won't appear in list_available_agents or the system prompt's agent list unless role is set.
Fix Options
Option A: Fix agent.md (quick fix)
Add role: delegation-target to Fred's frontmatter. This is the user-level fix.
Option B: Auto-infer role for ACP/stdio/remote agents (proper fix)
In assembleAgentProfile() (agents-files/agent-profiles.ts ~line 230), if role is not set but connection.type is acp, stdio, or remote, auto-assign:
role: mdPartial.role ?? (connectionType !== 'internal' ? 'delegation-target' : undefined),
isAgentTarget: mdPartial.role === "delegation-target" || mdPartial.role === "external-agent" || connectionType !== 'internal' || undefined,
Option C: Fix the agent creation flow
When creating an agent with connection-type: acp, the creation code should auto-set role: delegation-target. Check builtin-tools.ts:1472 where this already happens for some paths but may not cover all creation flows.
Files Involved
| File |
Line |
What it does |
agents-files/agent-profiles.ts |
250 |
assembleAgentProfile — sets isAgentTarget based on role |
agents-files/agent-profiles.ts |
200 |
parseAgentProfileMarkdown — parses role from frontmatter |
agent-profile-service.ts |
611-631 |
getByRole — filters by role/isAgentTarget |
agent-profile-service.ts |
650-657 |
getAgentTargets — combines role + legacy lookups |
agent-profile-service.ts |
522-527 |
getByName — searches all profiles (no role filter) |
acp-router-tools.ts |
587 |
handleDelegateToAgent — uses getByName (works) |
acp-router-tools.ts |
482 |
handleListAvailableAgents — uses getEnabledAgentTargets (broken) |
system-prompts.ts |
176 |
Builds AVAILABLE AGENTS section — uses getByRole (broken) |
Reproduction
- Create an external ACP agent (connection-type: acp) without explicitly setting
role: delegation-target in agent.md
- Agent won't appear in
list_available_agents output
- Agent won't appear in system prompt's AVAILABLE AGENTS section
- Direct delegation via
delegate_to_agent may still work (uses getByName which searches all profiles)
Summary
Delegating to external ACP agents like Fred fails with "agent not found" because their
agent.mdfrontmatter is missingrole: delegation-target, causing them to be excluded from the delegation lookup path.Root Cause
Fred's
~/.agents/agents/286c6b41-.../agent.mdhas this frontmatter:Missing field:
role: delegation-targetHow the lookup chain works:
handleDelegateToAgent()→ callsagentProfileService.getByName(agentName)(line 587 of acp-router-tools.ts)getByName()searchesthis.profilesData.profiles— finds Fred ✅handleListAvailableAgents()→ callsgetEnabledAgentTargets()→ callsgetAgentTargets()→ callsgetByRole("delegation-target")(line 652 of agent-profile-service.ts)getByRole("delegation-target")filters profiles wherep.role === "delegation-target"OR legacy fallbackp.isAgentTarget === trueassembleAgentProfile()inagents-files/agent-profiles.ts(line 250) sets:isAgentTarget: mdPartial.role === "delegation-target" || mdPartial.role === "external-agent" || undefinedrolein frontmatter →role = undefined→isAgentTarget = undefined→ Fred is excluded from agent targetsThe inconsistency:
getByName("Fred")inhandleDelegateToAgentDOES find Fred (it searches all profiles)getEnabledAgentTargets()inhandleListAvailableAgentsDOES NOT include Fred (filtered out by role)getByRole('delegation-target')(line 176 of system-prompts.ts) — should also exclude FredSo delegation to Fred may actually work via
getByName()→executeAgentProfileDelegation(), but Fred won't appear inlist_available_agentsor the system prompt's agent list unlessroleis set.Fix Options
Option A: Fix agent.md (quick fix)
Add
role: delegation-targetto Fred's frontmatter. This is the user-level fix.Option B: Auto-infer role for ACP/stdio/remote agents (proper fix)
In
assembleAgentProfile()(agents-files/agent-profiles.ts ~line 230), ifroleis not set butconnection.typeisacp,stdio, orremote, auto-assign:Option C: Fix the agent creation flow
When creating an agent with
connection-type: acp, the creation code should auto-setrole: delegation-target. Checkbuiltin-tools.ts:1472where this already happens for some paths but may not cover all creation flows.Files Involved
agents-files/agent-profiles.tsassembleAgentProfile— setsisAgentTargetbased onroleagents-files/agent-profiles.tsparseAgentProfileMarkdown— parsesrolefrom frontmatteragent-profile-service.tsgetByRole— filters by role/isAgentTargetagent-profile-service.tsgetAgentTargets— combines role + legacy lookupsagent-profile-service.tsgetByName— searches all profiles (no role filter)acp-router-tools.tshandleDelegateToAgent— uses getByName (works)acp-router-tools.tshandleListAvailableAgents— uses getEnabledAgentTargets (broken)system-prompts.tsReproduction
role: delegation-targetin agent.mdlist_available_agentsoutputdelegate_to_agentmay still work (usesgetByNamewhich searches all profiles)