Skip to content

feat(agents): support declarative agent definitions via frontmatter files #4821

@qqqys

Description

@qqqys

What would you like to be added?

Support declarative agent definitions — define custom agents via Markdown files with YAML frontmatter, instead of hardcoding them in TypeScript. This is the pattern Claude Code shipped in 2.1.167.

How it works in Claude Code

Users place a .claude/agents/<name>.md file with frontmatter:

---
name: code-reviewer
description: "Review code for bugs and style issues"
model: sonnet
effort: high
permissionMode: plan
tools:
  - Read
  - Bash
  - Grep
disallowedTools:
  - Write
  - Edit
maxTurns: 10
skills:
  - code-review
memory: project
isolation: worktree
hooks:
  PreToolUse:
    - command: "echo reviewing..."
---

You are a code reviewer. Focus on correctness bugs...

The Markdown body becomes the agent's system prompt. The agent is then available via the Agent tool and --agent CLI flag.

Full schema (confirmed via binary reverse engineering of CC 2.1.167)

Field Type Description
name string (required) Agent identifier, used by Agent tool and --agent flag
description string (required) When to use this agent, shown in Agent tool listing
model string Model override (haiku, sonnet, opus, or full ID). inherit = match parent
tools string[] Tools available to this agent (replaces default set)
disallowedTools string[] Tools removed from default set (ignored if tools is set)
effort string Thinking effort: low, medium, high, max
permissionMode string Permission mode the agent runs in
mcpServers object MCP servers to connect when this agent runs
hooks object Hooks registered while this agent runs
maxTurns number/string/null Maximum conversation turns before agent stops
skills string[] Skills preloaded for this agent
initialPrompt string Auto-submitted first message (only when run as main session via --agent)
memory string Memory scope: user, project, or local
background boolean If true, agent runs in background by default
isolation string Filesystem isolation: worktree runs in a temporary git worktree

Why this matters

  1. User-defined agents — users can create project-specific agents (e.g. a DB migration agent, a security reviewer) without writing code
  2. Composable — agents can reference skills, hooks, and MCP servers declaratively
  3. Discoverable.qwen/agents/ directory makes agents visible and version-controllable
  4. Parity — Claude Code already ships this; community expects it

Suggested implementation

  • Add .qwen/agents/ directory scanning (similar to .qwen/skills/)
  • Parse frontmatter with the same parser used for skills
  • Register discovered agents in the existing builtin-agents.ts / subagent-manager.ts pipeline
  • Validate schema with zod (like CC does)
  • Support both project-level (.qwen/agents/) and user-level (~/.qwen/agents/) definitions

Prior art in this repo

  • Skill frontmatter parsing already exists (skill-load.ts, skill-manager.ts)
  • builtin-agents.ts has the registration path
  • subagent-manager.ts handles agent lifecycle

The skill loading pipeline can be largely reused — the main new work is the schema definition and wiring agents into the Agent tool's type resolution.


Metadata

Metadata

Assignees

Labels

category/coreCore engine and logicpriority/P2Medium - Moderately impactful, noticeable problemroadmap/subagents-toolsRoadmap: Subagents and tool systemstatus/needs-triageIssue needs to be triaged and labeledtype/feature-requestNew feature or enhancement request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions