Skip to content

Instantly share code, notes, and snippets.

@kcosr
Created December 9, 2025 03:50
Show Gist options
  • Select an option

  • Save kcosr/e32b476d19af1f27edc4e5ab4f5f74b7 to your computer and use it in GitHub Desktop.

Select an option

Save kcosr/e32b476d19af1f27edc4e5ab4f5f74b7 to your computer and use it in GitHub Desktop.
Multi-Agent Orchestration Workflow

Multi-Agent Orchestration Workflow

This document describes the workflow for an orchestrator agent to break down a large task into sub-tasks, delegate to worker agents, and coordinate the work to completion.

Overview

┌─────────────────────────────────────────────────────────────────┐
│                     Orchestrator Agent                          │
│                                                                 │
│  1. Create umbrella issue                                       │
│  2. Analyze task & plan breakdown                               │
│  3. Create sub-issues                                           │
│  4. Create umbrella branch                                      │
│  5. Spawn worker agents (parallel where possible)               │
│  6. Monitor progress, merge PRs                                 │
│  7. Open final PR to main                                       │
└─────────────────────────────────────────────────────────────────┘
         │                    ▲
         │ spawn              │ report back
         ▼                    │
┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
│  Worker Agent   │  │  Worker Agent   │  │  Worker Agent   │
│                 │  │                 │  │                 │
│  - Create branch│  │  - Create branch│  │  - Create branch│
│  - Implement    │  │  - Implement    │  │  - Implement    │
│  - Open PR      │  │  - Open PR      │  │  - Open PR      │
│  - Report back  │  │  - Report back  │  │  - Report back  │
└─────────────────┘  └─────────────────┘  └─────────────────┘

Phase 1: Planning

1.1 Create Umbrella Issue

Create a GitHub issue that describes the overall feature/change. This becomes the tracking point for all sub-work.

The umbrella issue should include:

  • High-level description of the change
  • Goals and non-goals
  • Link to design docs if applicable
  • Section for tracking sub-issues (updated as they're created)

1.2 Analyze and Plan Breakdown

Before creating sub-issues, analyze the work to determine:

  1. File scope: Which files/modules will be modified?
  2. Dependencies: Which changes depend on others?
  3. Parallelization: Which changes can happen simultaneously without merge conflicts?

Key principle: Minimize file overlap between parallel tasks to avoid complex merges.

1.3 Create Sub-Issues

Create individual issues for each sub-task. Each sub-issue should include:

  • Clear description of the specific work
  • Relevant file paths
  • Dependencies on other sub-issues (if any)
  • Reference to umbrella issue ("Part of #X")

Create all sub-issues upfront before spawning any agents. This provides visibility into the full plan.

1.4 Update Umbrella Issue

Add a tracking table to the umbrella issue:

## Sub-Issues

| Issue | Title | Status | Blocked By |
|-------|-------|--------|------------|
| #101 | Backend API changes | Open | - |
| #102 | Database schema | Open | - |
| #103 | Frontend components | Open | #101 |
| #104 | Integration tests | Open | #101, #102 |

1.5 Create Umbrella Branch

git checkout -b issue/<umbrella-id>
git push -u origin issue/<umbrella-id>

This branch is the merge target for all sub-task PRs.

Phase 2: Execution

2.1 Visualize Dependencies

Before spawning agents, display the dependency structure:

Dependency Tree:

#100 (Umbrella: Feature X)
├── #101 (Backend API) ─────────────┐
│                                   ├── #103 (Frontend)
├── #102 (Database schema) ────────┤
│                                   └── #104 (Integration tests)

Parallel Tracks:

  • #101 and #102 → can run in parallel (no file overlap)
  • #103 and #104 → can run in parallel after dependencies merge

Execution Order:

#101 ──┬──► #103
       │
#102 ──┴──► #104

2.2 Spawn Worker Agents

Spawn agents for tasks that are ready (no unmet dependencies).

When spawning a worker agent, provide:

  • Issue ID: The sub-issue number
  • Target branch: The umbrella branch (e.g., issue/100)
  • Implementation summary: Clear description of what to implement

Instructions for worker agents:

  1. Create branch issue/<sub-issue-id> from target branch
  2. Implement the assigned task
  3. Open PR targeting the umbrella branch (not main)
  4. Report back when complete

2.3 Track Progress

Maintain a status display as work progresses:

Issues Status:

Issue Title Status Agent Session PR
#100 Feature X (umbrella) Open - -
#101 Backend API In Progress abc123... -
#102 Database schema In Progress def456... -
#103 Frontend components Blocked by #101 - -
#104 Integration tests Blocked by #101, #102 - -

Agents Spawned:

Agent Session Issue Task
abc123-... #101 Backend API changes
def456-... #102 Database schema

Branch Structure:

  • issue/100 – Umbrella branch (merge target)
  • issue/101 – Created by worker, targets issue/100
  • issue/102 – Created by worker, targets issue/100

2.4 Handle Agent Completion

When a worker agent reports back:

  1. Verify the PR - Check that it targets the umbrella branch and has passed code review
  2. Merge the PR into the umbrella branch
  3. Update tracking - Mark issue as complete
  4. Check unblocked tasks - Spawn agents for newly unblocked work

Note: Worker agents are responsible for requesting and addressing code review with a separate review agent. The orchestrator does not perform code review.

2.5 Handle Conflicts

If a PR has merge conflicts (due to previously merged work):

  1. Ask the worker agent to rebase their branch on the updated umbrella branch
  2. Wait for agent to force-push the rebased branch
  3. Retry the merge

2.6 Continue Until Complete

Repeat the spawn → wait → merge cycle until all sub-issues are complete.

Update the status table after each significant event:

Issues Status:

Issue Title Status Agent Session PR
#100 Feature X (umbrella) Open - -
#101 Backend API ✅ Complete abc123... #105 (merged)
#102 Database schema ✅ Complete def456... #106 (merged)
#103 Frontend components In Progress ghi789... -
#104 Integration tests In Progress jkl012... -

Phase 3: Completion

3.1 Final Verification

Once all sub-issues are complete and merged into the umbrella branch:

  1. Verify the umbrella branch builds/tests successfully
  2. Review the combined changes
  3. Update the umbrella issue with completion summary

3.2 Open Final PR

Create a PR from the umbrella branch to main:

gh pr create --base main --head issue/<umbrella-id> --title "Feature X" --body "..."

The PR description should:

  • Reference the umbrella issue ("Closes #100")
  • Summarize all changes
  • List all sub-issues that were completed

3.3 Handoff

Leave the final PR open for human review and merge.

Best Practices

Context Preservation

The orchestrator should minimize file reads to preserve context window for coordination tasks:

  • Do not review code directly - worker agents handle code review with a separate review agent
  • Do read files when necessary to resolve merge conflicts
  • Do read files when answering specific questions from worker agents
  • Do rely on PR descriptions and agent reports for understanding changes

Task Breakdown

  • Right-size tasks: Each sub-task should be completable in a single agent session
  • Minimize overlap: Avoid multiple agents modifying the same files
  • Clear boundaries: Each task should have well-defined scope and success criteria

Parallelization

  • Independent first: Start with tasks that have no dependencies
  • Maximize parallelism: Spawn all unblocked tasks simultaneously
  • Pipeline: As tasks complete, immediately spawn newly unblocked work

Communication

  • Clear handoffs: Provide complete context when spawning agents
  • Track everything: Keep status tables updated
  • Document decisions: Note any deviations from the original plan

Error Handling

  • Conflicts: Ask agent to rebase, don't try to resolve yourself
  • Failed tasks: Can respawn a new agent for the same issue
  • Blocked agents: Check if dependencies are actually blocking or can be worked around

Template: Worker Agent Instructions

When spawning a worker agent, include:

You are implementing issue #<sub-issue-id> (<title>) for the <repo> repository.

## Task
<clear description of what to implement>

## Files
<relevant file paths>

## Branch Instructions
1. Create your branch from `issue/<umbrella-id>`: `git checkout -b issue/<sub-issue-id> origin/issue/<umbrella-id>`
2. Implement the changes
3. Open a PR targeting `issue/<umbrella-id>` (not main)
4. Request code review from a review agent
5. Address any review feedback
6. Report back when complete and review is approved

## Context
<any additional context, links to related issues, design docs, etc.>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment