Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Creates specialized worker agents dynamically from templates. Use when orchestrator needs to spawn task-specific workers for parallel execution. Handles agent lifecycle: create -> execute -> cleanup.
.claude/skills/ibrahim-3d-agent-factory/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 229% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 206% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 53% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 106% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 196% | 0% |
Creates ephemeral worker agents from templates, specializing them based on task type.
Task from DAG -> Determine Type -> Select Template -> Substitute Placeholders -> Spawn Worker| Task Type | Template | Specialization | |-----------|----------|---------------| | code | code-worker.template.md | TDD, code patterns, tests | | ui | ui-worker.template.md | Design system, accessibility | | integration | integration-worker.template.md | API contracts, error handling | | test | test-worker.template.md | Coverage targets, test patterns | | docs | task-worker.template.md | Base template | | config | task-worker.template.md | Base template |
pythondef create_worker_agent(task: dict, track_id: str, message_bus_path: str) -> dict: """ Create a specialized worker agent for a task. Args: task: Task node from DAG (id, name, type, files, depends_on, acceptance) track_id: Current track identifier message_bus_path: Path to message bus directory Returns: dict with worker_id, skill_path, prompt """ # 1. Generate unique worker ID timestamp = datetime.utcnow().strftime("%Y%m%d%H%M%S") worker_id = f"worker-{task['id']}-{timestamp}" # 2. Select template based on task type task_type = task.get('type', 'code') template_map = { 'code': 'code-worker.template.md', 'ui': 'ui-worker.template.md', 'integration': 'integration-worker.template.md', 'test': 'test-worker.template.md', } template_name = template_map.get(task_type, 'task-worker.template.md') template_path = f"${CLAUDE_PLUGIN_ROOT}/skills/worker-templates/{template_name}" # 3. read_file template template = read_file(template_path) # 4. Prepare substitution values substitutions = { '{task_id}': task['id'], '{task_name}': task['name'], '{track_id}': track_id, '{phase}': str(task.get('phase', 1)), '{files}': format_list(task.get('files', [])), '{depends_on}': format_list(task.get('depends_on', [])), '{acceptance}': task.get('acceptance', 'Complete the task as specified'), '{message_bus_path}': message_bus_path, '{timestamp}': timestamp, '{worker_id}': worker_id, '{unblocks}': format_list(find_unblocked_tasks(task['id'])), } # 5. Substitute placeholders worker_skill = template for placeholder, value in substitutions.items(): worker_skill = worker_skill.replace(placeholder, value) # 6. Add task-specific instructions if task.get('task_instructions'): worker_skill = worker_skill.replace( '{task_instructions}', task['task_instructions'] ) else: worker_skill = worker_skill.replace( '{task_instructions}', f"Implement: {task['name']}\n\nAcceptance: {task.get('acceptance', 'N/A')}" ) # 7. Add base protocol base_protocol = read_file("${CLAUDE_PLUGIN_ROOT}/skills/worker-templates/task-worker.template.md") base_protocol_section = extract_section(base_protocol, "## Execution Protocol") worker_skill = worker_skill.replace('{base_worker_protocol}', base_protocol_section) # 8. Create worker skill directory (ephemeral) worker_skill_path = f"${CLAUDE_PLUGIN_ROOT}/skills/workers/{worker_id}/SKILL.md" os.makedirs(os.path.dirname(worker_skill_path), exist_ok=True) write_file(worker_skill_path, worker_skill) # 9. Generate dispatch prompt dispatch_prompt = f"""You are worker agent {worker_id}. Your task: {task['name']} (Task {task['id']}) MESSAGE BUS: {message_bus_path} Follow your worker skill instructions at: {worker_skill_path} Protocol: 1. Check dependencies via message bus 2. Acquire file locks before modifying 3. Post progress every 5 min 4. Post TASK_COMPLETE when done Execute autonomously. Do NOT wait for user input.""" return { 'worker_id': worker_id, 'skill_path': worker_skill_path, 'prompt': dispatch_prompt, 'task_id': task['id'], 'task_type': task_type }
For parallel groups, create all workers at once:
pythondef create_workers_for_parallel_group( parallel_group: dict, dag: dict, track_id: str, message_bus_path: str ) -> list: """ Create workers for all tasks in a parallel group. Args: parallel_group: Parallel group definition (id, tasks, conflict_free) dag: Full DAG with all task nodes track_id: Current track identifier message_bus_path: Path to message bus Returns: List of worker definitions ready for dispatch """ workers = [] for task_id in parallel_group['tasks']: # Find task in DAG task = next((n for n in dag['nodes'] if n['id'] == task_id), None) if not task: continue # Create worker worker = create_worker_agent(task, track_id, message_bus_path) # Add coordination info if not conflict-free if not parallel_group.get('conflict_free', True): worker['requires_coordination'] = True worker['shared_resources'] = parallel_group.get('shared_resources', []) workers.append(worker) return workers
Dispatch workers via parallel Task calls:
pythondef dispatch_workers(workers: list) -> list: """ Dispatch multiple workers in parallel using Task tool. Returns list of Task call results. """ # Create Task calls for all workers task_calls = [] for worker in workers: task_calls.append({ 'subagent_type': 'general-purpose', 'description': f"Execute {worker['task_id']}: {worker.get('task_name', 'task')}", 'prompt': worker['prompt'], 'run_in_background': True # Run in background for true parallelism }) # Dispatch all at once (Claude Code handles parallel calls) results = [] for call in task_calls: result = Task(**call) results.append(result) return results
After task completion, cleanup worker artifacts:
pythondef cleanup_worker(worker_id: str): """ Remove ephemeral worker skill directory. Called by orchestrator after worker reports completion. """ worker_skill_path = f"${CLAUDE_PLUGIN_ROOT}/skills/workers/{worker_id}" if os.path.exists(worker_skill_path): shutil.rmtree(worker_skill_path) # Log cleanup print(f"Cleaned up worker: {worker_id}")
After parallel group completes:
pythondef cleanup_parallel_group_workers(parallel_group_id: str, workers: list): """ Cleanup all workers from a completed parallel group. """ for worker in workers: cleanup_worker(worker['worker_id']) # Remove workers directory if empty workers_dir = "${CLAUDE_PLUGIN_ROOT}/skills/workers" if os.path.exists(workers_dir) and not os.listdir(workers_dir): os.rmdir(workers_dir)
pythondef format_list(items: list) -> str: """Format list for template substitution.""" if not items: return "None" return "\n".join(f"- {item}" for item in items) def find_unblocked_tasks(task_id: str, dag: dict) -> list: """Find tasks that will be unblocked when task_id completes.""" unblocked = [] for node in dag.get('nodes', []): if task_id in node.get('depends_on', []): # Check if this is the only remaining dependency remaining_deps = [d for d in node['depends_on'] if d != task_id] if not remaining_deps: unblocked.append(node['id']) return unblocked def extract_section(content: str, section_header: str) -> str: """Extract a section from markdown content.""" lines = content.split('\n') in_section = False section_lines = [] for line in lines: if line.startswith(section_header): in_section = True continue elif in_section and line.startswith('## '): break elif in_section: section_lines.append(line) return '\n'.join(section_lines).strip()
The orchestrator calls the agent factory during PARALLEL_EXECUTE:
python# In conductor-orchestrator async def execute_parallel_phase(phase: Phase, dag: dict): # 1. Get parallel groups for this phase parallel_groups = [ pg for pg in dag.get('parallel_groups', []) if all(task_in_phase(t, phase) for t in pg['tasks']) ] for pg in parallel_groups: # 2. Create workers via agent factory workers = create_workers_for_parallel_group( pg, dag, track_id, message_bus_path ) # 3. Dispatch workers in parallel results = dispatch_workers(workers) # 4. Monitor message bus for completion await wait_for_group_completion(pg, message_bus_path) # 5. Cleanup workers cleanup_parallel_group_workers(pg['id'], workers)
+---------------------------------------------------------------+
| WORKER LIFECYCLE |
| |
| 1. CREATE |
| Agent Factory -> Template -> Substitution -> Skill Dir |
| |
| 2. DISPATCH |
| Orchestrator -> Task(prompt, run_in_background) -> Worker |
| |
| 3. EXECUTE |
| Worker -> Check Deps -> Lock Files -> Implement -> Commit |
| |
| 4. REPORT |
| Worker -> Message Bus -> TASK_COMPLETE/TASK_FAILED |
| |
| 5. CLEANUP |
| Orchestrator -> cleanup_worker() -> Remove Skill Dir |
| |
+---------------------------------------------------------------+pythondef handle_worker_failure(worker: dict, error: str, message_bus_path: str): """ Handle worker failure gracefully. 1. Post failure to message bus 2. Release any held locks 3. Cleanup worker artifacts 4. Notify orchestrator """ # Post failure message post_message(message_bus_path, "TASK_FAILED", worker['worker_id'], { "task_id": worker['task_id'], "error": error }) # Release all locks held by this worker release_all_locks_for_worker(message_bus_path, worker['worker_id']) # Cleanup worker cleanup_worker(worker['worker_id'])
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 6,937 | 32,448 | +368% | 1 | 1 | 0% | 1,464 | 4,821 | +229% | 0 | 0 | — |
case-02 | fail→pass | 8,178 | 10,567 | +29% | 1 | 1 | 0% | 1,754 | 5,376 | +206% | 0 | 0 | — |
case-03 | fail→fail | 3,139 | 7,091 | +126% | 1 | 1 | 0% | 395 | 3,408 | +763% | 0 | 0 | — |
case-04 | fail→pass | 12,960 | 1,822 | -86% | 1 | 1 | 0% | 2,146 | 3,276 | +53% | 0 | 0 | — |
case-05 | fail→pass | 9,815 | 2,187 | -78% | 1 | 1 | 0% | 1,610 | 3,321 | +106% | 0 | 0 | — |
case-06 | fail→pass | 6,970 | 2,244 | -68% | 1 | 1 | 0% | 1,133 | 3,359 | +196% | 0 | 0 | — |
case-07 | fail→pass | 9,105 | 2,634 | -71% | 1 | 1 | 0% | 1,430 | 3,443 | +141% | 0 | 0 | — |
case-08 | fail→pass | 11,025 | 1,445 | -87% | 1 | 1 | 0% | 1,714 | 3,125 | +82% | 0 | 0 | — |
case-09 | fail→pass | 12,055 | 4,506 | -63% | 1 | 1 | 0% | 1,884 | 3,793 | +101% | 0 | 0 | — |
case-10 | fail→pass | 10,946 | 3,040 | -72% | 1 | 1 | 0% | 1,778 | 3,510 | +97% | 0 | 0 | — |
case-11 | pass→pass | 4,230 | 2,280 | -46% | 1 | 1 | 0% | 677 | 3,382 | +400% | 0 | 0 | — |
case-12 | pass→pass | 3,758 | 4,956 | +32% | 1 | 1 | 0% | 653 | 4,014 | +515% | 0 | 0 | — |
case-13 | fail→fail | 16,783 | 2,039 | -88% | 1 | 1 | 0% | 2,900 | 3,355 | +16% | 0 | 0 | — |
case-14 | pass→pass | 6,596 | 2,819 | -57% | 1 | 1 | 0% | 1,026 | 3,375 | +229% | 0 | 0 | — |
case-15 | fail→pass | 10,988 | 3,649 | -67% | 1 | 1 | 0% | 1,777 | 3,598 | +102% | 0 | 0 | — |
case-16 | pass→pass | 7,573 | 2,247 | -70% | 1 | 1 | 0% | 1,404 | 3,281 | +134% | 0 | 0 | — |
case-17 | fail→pass | 9,336 | 2,557 | -73% | 1 | 1 | 0% | 1,495 | 3,405 | +128% | 0 | 0 | — |
case-18 | pass→pass | 7,014 | 2,280 | -67% | 1 | 1 | 0% | 1,187 | 3,369 | +184% | 0 | 0 | — |
case-19 | fail→pass | 11,733 | 1,922 | -84% | 1 | 1 | 0% | 1,954 | 3,276 | +68% | 0 | 0 | — |
case-20 | fail→fail | 20,520 | 20,074 | -2% | 1 | 1 | 0% | 4,331 | 6,968 | +61% | 0 | 0 | — |
case-21 | fail→fail | 13,325 | 10,785 | -19% | 1 | 1 | 0% | 2,691 | 5,136 | +91% | 0 | 0 | — |
case-22 | fail→fail | 24,425 | 21,609 | -12% | 1 | 1 | 0% | 5,678 | 8,183 | +44% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +55 percentage points is the difference between those two pass rates over the 21 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.