[PR #10377] fix: improve error message when invoking primary agent as subagent - Issue #10350 #13420

Closed
opened 2026-02-16 18:18:16 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10377

State: closed
Merged: No


Problem

When users try to invoke a primary agent (like 'build' or 'plan') as a subagent using the Task tool, they receive a misleading error message: "Unknown agent type".

Solution

Added explicit check for primary agent mode with a helpful error message that:

  • Explains primary agents cannot be invoked as subagents
  • Suggests changing the agent mode to 'all' or 'subagent' in configuration
// Primary agents cannot be invoked as subagents
if (agent.mode === "primary") {
  throw new Error(
    `Agent "${params.subagent_type}" is a primary agent and cannot be invoked as a subagent. ` +
      `Primary agents (build, plan, etc.) are designed to be user-facing only. ` +
      `If you want to invoke this agent programmatically, change its mode to "all" or "subagent" in your configuration.`
  )
}

Testing

  • Verified with existing test suite (752/759 tests passing)
  • Tested with both primary and subagent invocations

Fixes #10350

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10377 **State:** closed **Merged:** No --- ## Problem When users try to invoke a primary agent (like 'build' or 'plan') as a subagent using the Task tool, they receive a misleading error message: "Unknown agent type". ## Solution Added explicit check for primary agent mode with a helpful error message that: - Explains primary agents cannot be invoked as subagents - Suggests changing the agent mode to 'all' or 'subagent' in configuration ```typescript // Primary agents cannot be invoked as subagents if (agent.mode === "primary") { throw new Error( `Agent "${params.subagent_type}" is a primary agent and cannot be invoked as a subagent. ` + `Primary agents (build, plan, etc.) are designed to be user-facing only. ` + `If you want to invoke this agent programmatically, change its mode to "all" or "subagent" in your configuration.` ) } ``` ## Testing - Verified with existing test suite (752/759 tests passing) - Tested with both primary and subagent invocations Fixes #10350
yindo added the pull-request label 2026-02-16 18:18:16 -05:00
yindo closed this issue 2026-02-16 18:18:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13420