Task Delegation & Subagents
Relevant source files
The following files were used as context for generating this wiki page:
- tools/delegate_tool.py
- agent/delegation_context.py
- agent/subagent_lifecycle.py
- optional-skills/software-development/subagent-driven-development/SKILL.md
- skills/autonomous-ai-agents/hermes-agent/SKILL.md
- skills/autonomous-ai-agents/hermes-agent/references/contributor-guide.md
- optional-skills/research/research-paper-writing/references/phase5-paper-drafting.md
Task delegation in Hermes Agent allows a controller agent to dispatch specialized subagents to execute discrete tasks. This system enables parallel execution, prevents context pollution, and ensures high quality through automated review loops. The primary mechanism for this behavior is the delegate_task tool, which initializes a fresh subagent with a specific goal and context.
Subagents operate as separate conversations within the shared process, allowing them to focus on small units of work (2-5 minutes) without the interference of accumulated session history.
Subagent Architecture
Hermes Agent differentiates between task delegation via tools and spawning independent processes. While delegate_task is suitable for quick parallel subtasks, independent process spawning (e.g., via tmux) handles long autonomous missions.
Comparison: Delegation vs. Spawning
| Feature | delegate_task | Spawning hermes process |
|---|---|---|
| Isolation | Separate conversation, shared process | Fully independent process |
| Duration | Minutes (bounded by parent loop) | Hours/days |
| Tool Access | Subset of parent's toolsets | Full tool access |
| Interactive | No | Yes (via PTY/tmux) |
| Use Case | Quick parallel subtasks | Long autonomous missions |
Sources: skills/autonomous-ai-agents/hermes-agent/SKILL.md, skills/autonomous-ai-agents/hermes-agent/references/contributor-guide.md
Subagent Lifecycle
The subagent lifecycle follows a request-response pattern managed by the delegate_task tool.
This diagram illustrates the synchronous call path when the controller agent delegates a task.
Sources: optional-skills/software-development/subagent-driven-development/SKILL.md, agent/subagent_lifecycle.py
Subagent-Driven Development (SDD)
Subagent-Driven Development is a systematic process for executing implementation plans using three distinct roles: Implementer, Spec Reviewer, and Quality Reviewer. This 2-stage review process ensures that code not only works but also matches requirements and follows best practices.
The SDD Workflow
- Dispatch Implementer: Create a subagent to write code, typically following Test-Driven Development (TDD).
- Dispatch Spec Compliance Reviewer: Verify the implementation against the original task specification.
- Dispatch Code Quality Reviewer: Audit the code for conventions, naming, and error handling.
- Mark Complete: The controller updates the plan once all reviews pass.
The SDD flowchart highlights the requirement for spec compliance before quality review begins.
Sources: optional-skills/software-development/subagent-driven-development/SKILL.md:1-120
Context Management for Delegation
Effective delegation requires strict context discipline to avoid exceeding token limits and to maintain subagent focus. Controllers must provide "scene-setting" context without loading raw, unnecessary data.
Delegation Guidelines
- Summarize, don't include raw files: Load a 10-line summary table instead of a 200-line JSON result.
- Load one section at a time: A subagent drafting a specific module does not need notes from unrelated modules.
- Provide specific verbs: Instruct subagents with active verbs (e.g., "Validate", "Erased") rather than abstract phrases.
- Fresh context: Always use a fresh subagent per task to prevent state accumulation from prior tasks.
Sources: optional-skills/research/research-paper-writing/references/phase5-paper-drafting.md, optional-skills/software-development/subagent-driven-development/SKILL.md
Technical Reference: delegate_task
The delegate_task tool is the primary interface for creating subagents.
Parameters
| Parameter | Type | Description |
|---|---|---|
goal | string | The primary objective the subagent must achieve. |
context | string | The background information and task specifications required. |
toolsets | list[str] | A subset of tools the subagent is permitted to use (e.g., ['terminal', 'file']). |
Implementation Example
delegate_task(
goal="Create User model with email and password_hash fields",
context="""
TASK: Create src/models/user.py.
CONVENTIONS: Use bcrypt for hashing. Follow TDD.
""",
toolsets=['terminal', 'file']
)
Sources: optional-skills/software-development/subagent-driven-development/SKILL.md, tools/delegate_tool.py
Task delegation and the use of subagents allow the Hermes Agent to scale complex software development and research tasks by ensuring that each sub-component is implemented and reviewed with a clean context and high technical rigor.