Modular rules for specific subagents

Hey! I wanted to share a piece of feedback from building a setup with specialized subagents:

Certain operational rules/invariants need to apply to a specific subset of subagents (e.g., 3 out of 10), but not globally:

  • Skills / model_decision aren’t the same as a system prompt: Even if the subagent loads them every time, it adds non-deterministic cognitive overhead. More importantly, dynamically retrieved content gets pushed up into conversation history and begins to blur over long, multi-turn reasoning. A system prompt stays firmly anchored in the model’s attention across the entire run.
  • Global always_on rules bloat the shared token budget and pollute unrelated agents.
  • Manually maintaining copies/includes in each agents/.md is tedious and causes config drift across dozens of subagents.

It would be awesome to modularly attach rules directly to subagents so they bake into their system prompt:

In rules/my_rule.md:

trigger: always_on
subagents: [investigator, thread-auditor]
Or in agents/my_agent.md:

rules: [strict-evidence, formatting-invariants]

This would give us modular, DRY composition while keeping critical invariants firmly anchored in the subagent’s system prompt.

Your schema diagnosis matches what the current loader implements: Rules frontmatter only accepts trigger (always_on, model_decision, glob, manual), description, and globs, while Custom subagents only accepts name, description, tools, mainAgent, subagent, model, commandExecutionPolicy, mcpServers, and skills/plugins. Neither supports a subagents: or rules: key yet, and @[label](path) inline includes are documented for rule files (AGENTS.md, GEMINI.md, .agents/rules/*.md) rather than agents/*.md bodies.

Until native per-subagent frontmatter exists, keep shared rules in .agents/rules/*.md (e.g. trigger: manual), keep agent headers outside .agents/ so they are not double-discovered, and compile targeted agents/*.md system prompts with YAML frontmatter stripped (or compose SystemPrompt dynamically via define_subagent / /run-workflow):

from pathlib import Path
import re
TARGETS = {"investigator": ["strict-evidence.md", "formatting.md"], "thread-auditor": ["strict-evidence.md"]}
for agent, mods in TARGETS.items():
    head = Path(f"agent-templates/{agent}.md").read_text(encoding="utf-8").rstrip()
    parts = [re.sub(r"\A---\s*\n.*?\n---\s*\n", "", Path(f".agents/rules/{m}").read_text(encoding="utf-8"), count=1, flags=re.S).strip() for m in mods]
    Path(f".agents/agents/{agent}.md").write_text(head + "\n\n" + "\n\n".join(parts) + "\n", encoding="utf-8")

Running that in a pre-commit hook keeps each rule single-sourced inside .agents/rules/ while baking invariants straight into the selected subagents’ system prompts. For constraints that still stay global near the 20,000-token rules budget, symbolic [SCOPE: REQUIRE !FORBID] directives also cut pre-fill bloat alongside cross-file sync - the pattern used in governance-guard - while native rules: / subagents: support remains the ideal upstream fix.

thanks for your reply and suggestions!