Skip to content

[FEATURE]: Improve Subagent Invocation Documentation #3715

@mossbergmaverick

Description

@mossbergmaverick

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

The current documentation explains that subagents can be invoked automatically or manually, but doesn't clearly explain how to write agent prompts for automatic invocation when creating agents via markdown files.

From the docs:

Subagents can be invoked:

  • Automatically by primary agents for specialized tasks based on their descriptions.
  • Manually by @ mentioning a subagent in your message.

What's unclear for users creating agents via .md files:

  • Should primary agents use @subagent-name or just subagent-name in their system prompts?
  • What syntax should be written in the markdown body of primary agent files?
  • How does the automatic invocation mechanism work?

Context

This issue specifically concerns users who create agents using markdown files in:

  • ~/.config/opencode/agent/
  • .opencode/agent/

The confusion is about what to write in the markdown body (system prompt), not the frontmatter configuration.

Expected vs Actual Behavior

User possible expectation based on docs:

# .opencode/agent/test-agent.md
---
description: Test agent
mode: primary
---
Example: "@test-subagent create a test file"

What actually works:

# .opencode/agent/test-agent.md
---
description: Test agent
mode: primary
---
Example: "test-subagent create a test file"

The @ prefix is only for manual user invocation, not for automatic agent-to-agent invocation in system prompts.

Suggested Documentation Improvement

Add a clear example in the Agents section showing the difference:

Proposed addition:

Subagent Invocation

Subagents can be invoked in two ways:

1. Automatic Invocation (by primary agents)

When creating agents via markdown files, primary agents invoke subagents by mentioning their name without @ in the system prompt:

Primary agent file (~/.config/opencode/agent/delegator.md):

---
description: Main development agent that delegates tasks
mode: primary
tools:
  write: false
---

You delegate file creation to the file-writer subagent.
When user requests file creation, invoke it like this:
"file-writer create the requested file"

NOT like this: "@file-writer create file"  # @ is only for manual user invocation

Subagent file (~/.config/opencode/agent/file-writer.md):

---
description: Creates and manages files
mode: subagent
tools:
  write: true
---

You create files as requested.

2. Manual Invocation (by users)

Users invoke subagents directly in the TUI using @:

@file-writer create test.txt with content "hello"

Technical Note

Subagents appear as available tools to primary agents based on their description. The primary agent decides when to invoke them based on the task context. In the agent's system prompt (markdown body), reference subagents by name only, without the @ prefix.

Additional Examples for Markdown Agent Files

Example 1: Testing Agent

# .opencode/agent/developer.md

---
description: Main development agent
mode: primary
tools:
  write: false
---
Delegate test creation to test-writer subagent:
"test-writer generate tests for this code"

# .opencode/agent/test-writer.md

---
description: Writes unit and integration tests
mode: subagent
tools:
  write: true
---
You write comprehensive tests for the code provided.

Example 2: Security Review

# Primary agent markdown body
When security review is requested, invoke the subagent:
"security-auditor analyze this code for vulnerabilities"

# Correct ✅
"security-auditor analyze code"

# Incorrect ❌ (@ is for manual user invocation only)
"@security-auditor analyze code"

Related Documentation Files

  • /docs/agents/
  • Specifically the "Usage" and "Markdown" sections

Impact

This clarification would help users who create agents via markdown files:

  • Understand the difference between automatic and manual invocation syntax
  • Write correct agent system prompts in markdown files
  • Avoid confusion with @ syntax when writing agent instructions

Metadata

Metadata

Assignees

Labels

discussionUsed for feature requests, proposals, ideas, etc. Open discussiondocumentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions