# escalation-cycle

**Trigger:** a new `reviews` row event from review-aggregator.
**Cadence:** event-driven. Each new review fires its own cycle.
**Agents (in order):** queen-coordinator -> escalation-router -> response-drafter (only if escalation opened) -> alert worker (not an agent; a plain Function call to sendgrid/twilio).
**Output:** a row in the `escalations` table (or no row, if escalation-router decides the review is not actionable), a draft response in the case, and an email/SMS alert dispatched to the right human.
**SLA:** 10 minutes from a 1-2 star review posting to the first assignee getting an alert.

## How it runs

1. Queen-coordinator gets the new-review event. It checks for an existing open escalation on the same (location, topic) pair within 7 days. If found, queen marks the new review as a "related" event and stops. Otherwise it routes to escalation-router.
2. Escalation-router evaluates the rating + topics + location's escalation-rules entry and emits the routing decision (severity, first assignee, SLA, alert channel).
3. If `open_escalation` is true, queen creates the escalation row and routes to response-drafter.
4. Response-drafter generates a draft response in the brand voice. The draft lands inside the escalation case for the human to approve, edit, or rewrite.
5. The alert worker (plain Function call, not an agent) sends the email or SMS to the first assignee with a link into the app's escalation page.
6. If the first assignee does not respond within the SLA, queen-coordinator fires the next-step escalation per the routing decision. Each climb sends a new alert.

## Stop conditions

- Operator clicks "Mark resolved" in the app.
- Operator approves and posts the response (handled outside the swarm; gate-outbound prevents auto-post).
- Customer adds a reply on the platform that the brand judges as closing the loop.
- 7 days pass with no further activity (auto-close with status "stale").

## What the swarm does not do here

- Does not post the response. Human approves first.
- Does not delete or hide the review. We don't.
- Does not call the customer. We do not have their contact info, and even if we did, that's an operator decision, not a swarm action.

## Cost

Per cycle: about $0.02 (Sonnet 4.6 for response-drafter is the bulk of the cost). At 50 negative reviews per day per 1,000 locations, daily cost is ~$1.
