Skip to main content

What This Example Shows

  • A HierarchicalSwarm applied to a real-world business analysis problem
  • A director coordinating three domain specialists (logistics, inventory, procurement)
  • How to write director and worker system prompts that compose cleanly
This is the same hierarchical pattern as the Hierarchical Workflow Example, applied to supply chain analysis instead of software development. Swap the worker roles and prompts to apply it to any domain — legal review, M&A due diligence, clinical case conferences, marketing campaign planning.

Step 1: Setup

Step 2: Define the Team

The director sets strategy and synthesizes. Each specialist owns one functional area.

Step 3: Run the Swarm

HierarchicalSwarm always builds its own director from director_model_name (default gpt-5.4) that decomposes the task and dispatches it to every agent in agents — the Supply Chain Director above runs as one of the director’s workers, not as a privileged synthesizer, and with the default max_loops: 1 and parallel worker execution, no agent sees another specialist’s output before writing its own. For a guaranteed synthesis pass, either set "max_loops": 2 on the swarm (the framework’s director gets every first-round output on its second pass and can route the synthesis to the Supply Chain Director by name/description), or collect the specialist outputs client-side and issue one more /v1/agent/completions call using the Supply Chain Director’s system prompt. Design that prompt around “review, decide, recommend” — not “write a long report.”

Adapting the Pattern

Replace the three specialists to retarget the swarm: Everything else — the request shape, the response shape, the billing — stays identical.