Skip to main content

What This Example Shows

  • A HierarchicalSwarm with a Triage Manager routing tickets to one of five specialists: Billing, Technical, Account, Product Liaison, Retention
  • A Quality Reviewer agent that scores every draft for tone and confidence, then sets an escalation flag
  • A complete /v1/swarm/completions call for a realistic ticket — subject, body, and suggested next action returned as a structured reply
  • A Flask webhook that catches new Intercom conversations, runs the swarm, and either auto-replies via the Intercom REST API or drops the ticket into a human queue
  • A /v1/swarm/batch/completions pattern for clearing a 500-ticket overnight backlog for about $50
  • The cost math: ~$0.10 per ticket vs. ~$1.50 for a fully loaded tier-1 agent
This tutorial uses HierarchicalSwarm and /v1/swarm/batch/completions — both included on every paid Swarms tier. For production-volume webhook traffic and overnight batches above a few thousand tickets, upgrade at https://swarms.world/platform/account for the parallel execution and rate-limit headroom you need.

Why This Matters

A fully loaded tier-1 support agent runs ~$50K/yr and clears about 30 tickets a day. A swarm running on this stack handles 30,000 tickets a day for under $200. The job is not to fire the support team — it is to put a customer-ready, on-brand drafted reply in front of your humans so they approve-and-send in five seconds instead of writing from scratch in five minutes. That single shift takes your team from drowning in queue to ahead of SLA, and it does the boring 80% of tickets autonomously so the humans get their afternoon back for the cases that actually need them. Every SaaS company on Earth has this problem and almost none of them have shipped a real fix.

The Architecture

Step 1: Setup

Install the dependencies and grab your API key from https://swarms.world/platform/api-keys.

Step 2: Define the Triage + Specialist + Quality Team

Seven agents. The Triage Manager owns routing. Each specialist drafts a customer-ready reply in a strict format the Quality Reviewer can grade. The Quality Reviewer decides whether the draft auto-sends or goes to a human.
The Triage Manager runs on claude-sonnet-4-5 because misrouting cascades into the wrong specialist and burns the whole pipeline. Specialists run on cheaper models (gpt-4.1-mini, claude-haiku-4-5, xai/grok-4) — they are doing template-shaped writing and the cost difference is what keeps this near $0.10/ticket. The Quality Reviewer steps up to claude-opus-4-8 because the escalation decision is load-bearing.
Two mechanism details matter before you rely on this in production. First, claude-opus-4-8 is a premium-only model — a free-tier key is rejected on the Quality Reviewer agent, so this swarm needs an active Pro, Ultra, or Premium subscription regardless of /v1/swarm/completions itself not being a premium-only route. Second, HierarchicalSwarm always builds its own director from director_model_name (default gpt-5.4); the Triage Manager above is a worker like the other six, not a mechanism that literally routes the ticket to one specialist. With the default max_loops: 1 and parallel worker execution, the framework’s own director decides (from each agent’s description) who gets dispatched, every dispatched agent — including the Quality Reviewer — works from the raw ticket rather than a prior agent’s draft, and extract_quality_review below only finds a “Quality Reviewer” output if the director happened to dispatch that agent too. For deterministic one-of-five routing, use MultiAgentRouter for the classify step, then a second call (SequentialWorkflow or a plain /v1/agent/completions request) so the Quality Reviewer genuinely receives the chosen specialist’s draft as input.

Step 3: Process a Single Ticket

Build a realistic ticket, post it to /v1/swarm/completions, and pull the Quality Reviewer’s JSON out of the response.
The Quality Reviewer’s JSON is the single object your application needs. escalate_to_human is the only field that decides what happens next — every downstream branch reads from there.

Step 4: Wire It to Intercom (or Zendesk) via Webhook

Drop the swarm behind a Flask webhook. Intercom POSTs every new conversation to your endpoint, you run the swarm, and you either reply via the Intercom REST API or assign the conversation to a human teammate based on the escalation flag.
For Zendesk, swap the Intercom calls for the equivalent endpoints — POST /api/v2/tickets/{id}/comments for the reply and PUT /api/v2/tickets/{id}.json with {"ticket": {"assignee_id": <human_id>}} for the escalation. The swarm layer does not change.

Step 5: Batch Mode for Existing Backlog

When the team comes back from a long weekend with 500 tickets stacked up, you do not run the webhook 500 times — you fan them out through /v1/swarm/batch/completions and clear the queue overnight.
A 500-ticket backlog at this swarm shape runs about $50 end-to-end and finishes in the time it takes to refill the coffee pot. The auto-send list goes straight to Intercom, the human queue lands in your inbox with the draft and escalation reason already attached.

Real Cost vs. Tier-1 Support

Your humans are not gone — they are reviewing the 10-20% of tickets the Quality Reviewer flagged, plus the ones that came back with follow-up questions. The swarm took the 30,000 routine tickets off their plate, which is the entire point. A tier-1 floor of ten people now does the work of a floor of fifty, with shorter response times and a fully auditable trail per ticket.

Guardrails

These rules belong in code, not in the prompt — the prompt is a soft constraint, the code is hard.
  • Never auto-send for refunds above $X. Hard-cap it. Read the dollar amount out of suggested_next_action with a regex and force escalation if it exceeds your finance team’s pre-approved threshold.
  • Never auto-send for legal, compliance, or media topics. Match on keywords (lawsuit, attorney, GDPR, HIPAA, breach, press, journalist) and force escalation regardless of confidence.
  • Always include the original ticket ID in the reply. Customers reference it, your support team searches by it, your audit log requires it. The specialist prompts include it but verify in code before sending.
  • Rate-limit auto-replies per customer. If you have already auto-sent two replies on a thread, the third one is escalated by default — a customer who is still responding usually needs a human.
  • Log every swarm decision. Persist the Quality Reviewer JSON, the specialist who drafted, and the model usage to your warehouse. The first time you debate “is the swarm getting better or worse,” that table is the only thing that matters.
  • Run a shadow week before going live. Send every ticket through the swarm, drop every result into an internal note, never auto-send. Your support leads grade a sample of 200 drafts. Ship when the approval rate clears the bar you set.

Next Steps