Skip to content

Bug: External ACP agents (e.g. Fred) fail delegation — missing role in agent.md #1110

Description

@aj47

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:

  1. handleDelegateToAgent() → calls agentProfileService.getByName(agentName) (line 587 of acp-router-tools.ts)
  2. getByName() searches this.profilesData.profiles — finds Fred ✅
  3. BUT handleListAvailableAgents() → calls getEnabledAgentTargets() → calls getAgentTargets() → calls getByRole("delegation-target") (line 652 of agent-profile-service.ts)
  4. getByRole("delegation-target") filters profiles where p.role === "delegation-target" OR legacy fallback p.isAgentTarget === true
  5. assembleAgentProfile() in agents-files/agent-profiles.ts (line 250) sets: isAgentTarget: mdPartial.role === "delegation-target" || mdPartial.role === "external-agent" || undefined
  6. Since Fred has no role in frontmatter → role = undefinedisAgentTarget = 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

  1. Create an external ACP agent (connection-type: acp) without explicitly setting role: delegation-target in agent.md
  2. Agent won't appear in list_available_agents output
  3. Agent won't appear in system prompt's AVAILABLE AGENTS section
  4. Direct delegation via delegate_to_agent may still work (uses getByName which searches all profiles)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions