# How we figure out why we win and lose deals

Once a week our win-loss agent reads every HubSpot deal closed won or lost since its last run, then posts the patterns to Slack by segment, competitor, price and the stage where deals died.

Canonical page: https://themachine.myapps.ai/use-cases/win-loss-analysis

Each deal you close, won or lost, tells you something about why a buyer picked
you or picked a rival. Trouble is, that story usually gets squeezed into a
single HubSpot field, typed by a rep rushing to their next call. One of those
notes on its own is close to useless. Line up a hundred of them from a quarter
and they show you plainly where you're winning, which competitor is taking
deals off you, and the point where your pipeline keeps quietly leaking.

So we have an agent on Machine read our closed HubSpot deals every week and
post what it finds to the sales channel in Slack. It reads deal data and does
nothing else; a Slack post is all it ever produces. It's how we keep an eye on
our own win rate.

- **Team:** Machine
- **Runs on:** A cron schedule, once a week
- **Connected systems:** HubSpot · Slack
- **Mode:** Reads only · a single Slack post each week

## The problem

Reps record close reasons and rival names in HubSpot because the form makes
them, and then nobody looks at those fields again. A lost deal gets a short
reason, perhaps a competitor's name, and slides into the archive. Because no
one adds them up, the same losing pattern can run for six months. Maybe one
competitor keeps undercutting you on price in a single segment, or one type of
deal always stalls at the same step. Eventually a sales leader senses it during
a QBR, on instinct alone.

The usual answers don't solve it. A win-rate figure on a dashboard shows that
the number moved, not the reason. A quarterly deal review is thorough, but by
the time it's presented it's describing three months ago, far too late to
change how you sell this week. And no one is keen to read two hundred close
reasons by hand every Monday morning.

## What we built

Once a week, a schedule on Machine starts an agent. It opens a fresh session
(a cloud sandbox) that can read HubSpot and nothing more, then fetches every
deal marked closed-won or closed-lost since its previous run. It splits the
results by segment, competitor and price band, and pins down the stage at which
the lost deals actually fell away. From that it draws out the themes, attaches
a concrete suggestion to each, and posts the summary in Slack. HubSpot is left
exactly as it was.

## How it works

### Start it on a weekly schedule

A **cron trigger** starts the agent every week. Each time it opens a new
**session**: a fresh cloud computer (a sandbox) used for that run and then
thrown away. Every week gets its own run on its own short-lived computer, so
the numbers are worked out again from whatever HubSpot holds today, and
nothing leaks from one week into the next.

### Teach it how we break deals down

The rules for reading a win or a loss travel with the agent as a **skill**.
It knows which HubSpot fields hold the close reason and the competitor, how we
group deals by size, how we sort them into segments, and how to boil a heap of
one-line reasons down to a few genuine themes instead of a hundred one-offs.

### Hook up HubSpot for reading only

A **connector** is a scoped connection to your tools. The key stays on our
servers, so the model never sees a raw token. Through it the agent reads:

- **Every won and lost deal.** All deals that closed since the previous run,
with their amount, their segment and the stages they passed through.
- **Close reasons and competitor names.** The exact HubSpot fields a rep
completes when a deal closes, taken word for word.
- **Stage history.** The step a lost deal had reached when it fell away, not
just the fact that it was lost.
- **Slack, for posting.** The single weekly roundup of themes and
suggestions.

### Put the limits in place

HubSpot is **read-only** for this agent. It can't write to any deal, contact
or company record, so a stage, a close reason or an amount can't be changed by
it. The Slack post is the only thing it produces. Its credentials are stored
encrypted in the **Secrets Manager** and only handed to the agents you grant
them to, when a run starts.

### Post the themes and suggestions

After that, each week brings a single Slack post. It gives the win rate and
the number of losses for the period, splits results by segment, competitor and
price, names the stage where deals fall away most often, and lists a few
themes, each with a suggestion attached. The sales team reads it and chooses
what to change. Nothing flows back into HubSpot on its own.

> **The pattern**
> Each week a **cron** opens a fresh session with a **connector** that can only
> read HubSpot. The rules for breaking deals down are kept as a **skill**. The
> agent goes through every closed deal, and the Slack post is the only thing
> it writes.

## Guardrails

The agent can see every closed deal in HubSpot, so its access is narrow and
runs in one direction only:

- **Isolation.** Each run happens in a sandbox of its own. The session can
  reach HubSpot and nothing else, and the Slack post is the only thing that
  comes out.
- **Scoped secrets.** The HubSpot key is stored encrypted in the Secrets
  Manager and only handed to the agents you grant it to, when the run begins.
- **Read-only.** The HubSpot connection can't write. The agent has no way to
  change a deal's stage, close reason, competitor or amount. All it can do is
  report what's already recorded.
- **Report only.** The agent never reaches out to a rep, a prospect or the
  buyer on a lost deal. It points out the pattern, and a person decides what
  to do about it.
- **Everything is code.** How it breaks deals down, its skill and its HubSpot
  permissions are files in the repo. They're versioned, and any change goes
  through a reviewed **change request**, not a toggle on a settings page.

## The outcome

- **Every week:** Closed deals scored again from what HubSpot holds today
- **Read-only:** No HubSpot deal is ever written to
- **4 cuts:** Segment, competitor, price and the stage deals die at, in one post

The reasons behind each win and loss used to sit untouched in a HubSpot field.
Now they turn into a weekly roundup in the channel sales already lives in,
with the themes spelled out and a suggestion next to each one. The agent does
the reading. The team decides how the playbook changes.
