Implementing Subagent Delegation for Complex AI Agent Skill Workflows

Agent Skills enables hierarchical AI workflows by extending the metadata field in SkillProperties to declare delegate skills, validated in validator.py and rendered into prompts via prompt.py.

The Agent Skills repository (agentskills/agentskills) provides a lightweight, open-format system that lets AI agents acquire new capabilities by loading skill folders on demand. By extending the front-matter schema and prompt-generation logic, a skill can ask the host agent to delegate part of a task to a sub-agent, enabling multi-step, hierarchical workflows. This approach leverages the extensible metadata dictionary in SkillProperties to declare delegation targets without requiring changes to core runtime protocols.

Extending the Skill Data Model for Delegation

The canonical representation of a skill's front-matter lives in skills-ref/src/skills_ref/models.py. The SkillProperties dataclass defines the structure that parsers expect when reading a SKILL.md file.


# https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/models.py

@dataclass
class SkillProperties:
    name: str
    description: str
    license: Optional[str] = None
    compatibility: Optional[str] = None
    allowed_tools: Optional[str] = None
    metadata: dict[str, str] = field(default_factory=dict)

To support subagent delegation, add a delegates key to the metadata dictionary containing a list of skill names. Because metadata is a free-form map, no schema changes are required to store the delegation graph. The validator and prompt generator will read this list directly from the properties object.

Validating Delegate Dependencies

Before a skill can activate, the validator ensures all declared delegates exist in the repository. The validation logic resides in skills-ref/src/skills_ref/validator.py, where the validate function performs a filesystem walk to confirm each delegate name resolves to a folder containing a SKILL.md.


# https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/validator.py

def validate(skill_dir: Path) -> SkillProperties:
    # … existing checks …

    delegates = frontmatter.get("metadata", {}).get("delegates", [])
    for d in delegates:
        if not (skill_dir.parent / d / "SKILL.md").exists():
            raise SkillError(f"Delegate {d} not found")
    # …

When a skill lists a delegate that cannot be located, the validator raises a SkillError (defined in skills-ref/src/skills_ref/errors.py). This guarantees that any delegation graph is well-formed before the skill is ever handed to the agent.

Rendering Delegation Instructions in Prompts

The prompt generator converts validated SkillProperties into textual instructions that the host LLM receives. In skills-ref/src/skills_ref/prompt.py, the render_prompt function builds a base prompt from the skill description and appends a delegation section when metadata["delegates"] is non-empty.


# https://github.com/agentskills/agentskills/blob/main/skills-ref/src/skills_ref/prompt.py

def render_prompt(props: SkillProperties) -> str:
    base = f"## {props.name}\n{props.description}\n"

    if props.metadata.get("delegates"):
        deleg_str = ", ".join(props.metadata["delegates"])
        base += f"\n**Delegates:** {deleg_str}\n"
    # … add allowed-tools, examples, etc. …

    return base

The generated prompt tells the host agent: "When you reach the point where you need X, invoke the sub-agent named Y." The host's runtime (outside this repository) parses this hint and spawns the appropriate sub-skill.

Command-Line Inspection and Debugging

The command-line interface in skills-ref/src/skills_ref/cli.py provides tools to inspect, validate, and render skills. When run with --render, the CLI prints the full prompt including delegation hints, making debugging straightforward.

$ skills-ref --skill my-complex-task --render

The CLI also reports validation errors if a delegate is missing:

$ skills-ref --skill my-workflow --validate
Error: Delegate data-validator not found

Because the CLI uses the same code paths as the library, it guarantees consistency between interactive use and programmatic consumption.

Testing Subagent Delegation Logic

The repository includes unit tests covering parsing, validation, and prompt rendering. When implementing delegation, follow the existing pattern in skills-ref/tests/test_validator.py to assert that validator.validate accepts a skill only when delegate directories exist.

def test_delegate_validation(tmp_path):
    # Create a main skill with a delegate

    skill_dir = tmp_path / "main-skill"
    skill_dir.mkdir()
    (skill_dir / "SKILL.md").write_text(
        "---\n"
        "name: main-skill\n"
        "description: Test delegation\n"
        "metadata:\n"
        "  delegates: [sub-skill]\n"
        "---\n"
    )
    # Create the sub-skill folder

    (tmp_path / "sub-skill").mkdir()
    (tmp_path / "sub-skill" / "SKILL.md").write_text("---\nname: sub-skill\n---\n")
    # Validate – should pass

    props = validator.validate(skill_dir)
    assert "sub-skill" in props.metadata["delegates"]

Complete Subagent Delegation Workflow Example

Consider a data pipeline skill that delegates extraction and validation to specialized sub-agents. The SKILL.md declares the delegation graph in front-matter:

---
name: my-workflow
description: |
  Perform a complex data-pipeline that requires a data-extraction skill
  followed by a data-validation skill.
metadata:
  delegates:
    - data-extractor
    - data-validator
---

# Instructions

1. Use the `data-extractor` skill to collect raw records.
2. Pass the extracted data to the `data-validator` skill.
3. Combine the validation report with the extracted data and return the summary.

When the host loads this skill, validator.validate checks that folders data-extractor/ and data-validator/ each contain a SKILL.md. The rendered prompt output includes:


## my-workflow

Perform a complex data-pipeline that requires a data-extraction skill
followed by a data-validation skill.

**Delegates:** data-extractor, data-validator

The end-to-end subagent delegation workflow follows these steps:

  1. Discovery – At startup the host agent lists all skill folders, reading SKILL.md front-matter via the parser.
  2. Activation – When the host's task matches a skill description, it calls validator.validate to confirm the skill is well-formed, including declared delegates.
  3. Prompt Rendering – prompt.render_prompt creates a rich instruction block that includes the "Delegates" line.
  4. Execution – The host LLM receives the prompt. When it reaches the delegation cue, the host runtime spawns the designated sub-skills by loading their SKILL.md files and repeating steps 2-3 for each.
  5. Composition – The results from sub-agents are stitched together into the final answer.

Summary

  • Agent Skills implements subagent delegation by extending the metadata field in SkillProperties rather than modifying core protocols.
  • Validation occurs in validator.py, where the validate function confirms delegate directories exist before raising SkillError for missing dependencies.
  • Prompt generation in prompt.py automatically appends delegation instructions when metadata["delegates"] is present.
  • Testing follows the existing unit test pattern in test_validator.py, using temporary directories to simulate skill hierarchies.
  • CLI tools provide immediate feedback via --validate and --render flags to debug delegation graphs before runtime.

Frequently Asked Questions

How does Agent Skills validate subagent delegation targets?

The validator in skills-ref/src/skills_ref/validator.py checks that each skill listed in metadata["delegates"] corresponds to an existing directory containing a SKILL.md file. If any delegate is missing, it raises a SkillError before the skill can activate, ensuring the host agent never attempts to invoke a non-existent sub-skill.

Can a single skill delegate to multiple sub-agents simultaneously?

Yes. The metadata["delegates"] field accepts a list of skill names, allowing complex workflows that fork across multiple sub-agents. The validator iterates through the entire list in validator.py, and the prompt generator in prompt.py renders all delegates as a comma-separated list in the instructions.

Where does the actual subagent spawning logic reside?

The Agent Skills repository handles metadata, validation, and prompt generation only. The actual spawning and orchestration of sub-agents occurs in the host agent's runtime (outside this repository), which interprets the "Delegates:" line rendered by render_prompt and manages the lifecycle of sub-skills accordingly.

What happens if a delegate skill is deleted after validation?

Validation occurs at skill activation time. If a delegate skill is removed after validation but before execution, the host runtime will encounter a missing SKILL.md when attempting to load the sub-skill. While the Agent Skills library guarantees well-formed delegation graphs at activation time, runtime file system changes require host-level error handling.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →