# How we roll the pipeline into a weekly forecast

The sales-forecast agent we run on Kortix — a weekly cron rolls up HubSpot's open pipeline into a weighted forecast vs quota by stage, rep, and segment, flags deals slipping the quarter, and posts it to Slack. Read-only — it never touches a deal's amount or close date.

Canonical page: https://openchatly.com/use-cases/sales-forecast

Every sales org has a number it's chasing every quarter, and every sales org
reconciles that number the same way: someone pulls open deals out of HubSpot,
weights them by gut feel or a spreadsheet formula nobody remembers building,
and calls it the forecast. It's accurate for about a day — the day it was
built — and it says nothing about the deal whose close date quietly slid past
last week, or the six-figure deal that hasn't had a logged activity in a
month.

We run a sales-forecast agent on Kortix that reads HubSpot every week and
posts a weighted forecast to our sales Slack channel — broken down by stage,
rep, and segment, measured against quota, with the deals putting that number
at risk called out by name. It only reads the pipeline; the single output is
the Slack post. This is how we forecast our own quarter.

- **Team:** Kortix
- **CRM:** HubSpot
- **Runs on:** Weekly cron
- **Mode:** Read-only · one Slack post per week

## The problem

A stage-by-stage pipeline view and a real forecast are different things. The
pipeline view says a deal is "open" and sitting in "Proposal Sent"; it doesn't
say whether that deal is on track to close this quarter, whether the rep's
commit number matches what the stage actually implies, or whether a big deal
has quietly gone stale while still counting toward the total. Turning open
deals into a forecast means weighting every deal by how likely its stage
really is to close, then rolling that up three different ways — by stage, by
rep, by segment — and comparing it to quota.

The usual fix is a spreadsheet rebuilt the week before the forecast call:
someone exports deals, applies a weighting rule by hand, and reconciles it
against every rep's stated commit. It's stale the moment it's built, it
depends on someone remembering to run it, and it rarely catches a deal whose
close date has already passed or one that's gone quiet in a late stage until
the quarter is nearly over.

## What we built

On Kortix, a weekly cron triggers an agent. It spawns a fresh session with
read-only access to HubSpot, pulls every open deal — stage, amount, close
date, owner, and its segment — weights each one by the probability already
configured on its HubSpot pipeline stage, and rolls the weighted amounts up by
stage, by rep, and by segment. It compares the total to this quarter's quota,
flags deals whose close date has already slipped or that don't have enough
runway left in their current stage to realistically close this quarter, flags
large deals that look at risk for other reasons — no recent activity, stalled
in a late stage — and posts the whole forecast to Slack. It writes nothing
back to HubSpot.

## How it works

### Copy the setup prompt into a new session

Open your Kortix workspace, start a new session, paste this prompt and send it.
The agent writes the agent file, the forecast skill and the weekly trigger, and opens a change request for you to review. Prefer
clicks? Choose **Use this template** instead.

**Setup prompt**

```
Set up a weekly sales forecast agent in this workspace.

1. Create the agent agents/sales-forecast.md. Its job is to roll the open HubSpot pipeline into a weekly forecast. It may read HubSpot and post to Slack.

2. Create the skill skills/forecast-rollup/SKILL.md with these rules:
   - Weight every open deal by the win probability configured on its HubSpot stage. Never hardcode a probability.
   - Count an open deal in this quarter when its close date falls inside the quarter. Count this quarter's closed-won deals at full value.
   - Roll the weighted total up by stage, by rep and by the deal_segment property, and compare it to the quarterly quota of 1000000.
   - A deal is slipping when its close date has passed and it is still open, or when its stage leaves too little runway to close this quarter.
   - Flag large deals with no recent activity or no recent stage movement as at risk.
   - Never write to HubSpot: no change to a deal's amount, close date, stage or owner. The post to #sales-forecast is the only output.

3. Add a cron trigger weekly-sales-forecast to kortix.yaml. It runs the sales-forecast agent every Monday at 09:00 with the prompt "Load the forecast-rollup skill and run one complete weekly forecast rollup."

4. Tell me which of these connectors are not connected yet.

5. Open a change request with all of it. Do not merge it.
```

### Connect your tools

Open **Connectors** in your workspace and connect your CRM with read-only access,
and Slack for the post. Credentials are brokered server-side and never enter
the agent's machine.

- **HubSpot** (Required):
Reads open deals, stage probabilities and close dates, read-only.
- **Slack** (Required):
Posts the weekly forecast rollup and slipping deals.

### Run it once with this prompt

Merge the change request, then start a session with the **sales-forecast** agent
and send this prompt. Check the totals against your own pipeline view before
you let the schedule take over.

**Prompt**

```
Build this quarter's forecast from HubSpot. Read only. Change nothing.

1. Read every open deal (amount, stage, close date, owner, deal_segment) and each stage's configured win probability.
2. Weight each open deal that closes this quarter by its stage probability, and add this quarter's closed-won deals at full value.
3. Roll the total up by stage, by rep and by segment, and compare it to the quota of 1000000.
4. List the slipping deals and the large deals that look at risk, with owner, amount, stage and close date.
5. Post the forecast to #sales-forecast.
```

### Let the weekly schedule take over

The change request added this trigger to `kortix.yaml`. From now on the agent
runs every Monday at 09:00, each run in a new session on its own cloud computer.
To change the time, edit the cron line, or open **Triggers** in the workspace.

**kortix.yaml**

```yaml
triggers:
  - slug: weekly-sales-forecast
    name: Weekly sales forecast
    on:
      cron: "0 0 9 * * 1"
    run:
      agent: sales-forecast
      prompt: Load the forecast-rollup skill and run one complete weekly forecast rollup.
```

### Keep HubSpot read-only

The agent reads the pipeline and writes nothing back. It never changes a deal's
amount, close date, stage or owner, even when a deal is clearly slipping. The
Slack post is its only output, and the sales team decides what to do about each
flagged deal.

### Read the weekly forecast

Each run ends with one message in #sales-forecast. This is what a run looks like
in the session:

> **Weekly sales forecast · Mon 09:00**
>
> Prompt: Load the forecast-rollup skill and run one complete weekly forecast rollup.
>
> Weighted forecast is **$842,000** against a **$1,000,000** quota: **84%**
> attainment and a **$158,000** gap. **5** deals are slipping the quarter, and
> **2** large deals look at risk with no activity in three weeks.

> **The pattern**
> A weekly **cron** spawns a session with read-only **connector** access to
> HubSpot. The weighting and rollup rules live as a **skill**. The agent reads
> the whole pipeline and writes nothing but the weekly Slack post.

## Make it do more

Once it works, paste any of these into the same session.

**Send reps their own risks**

```
After each forecast, send each rep a Slack DM with only their slipping and at-risk deals, so they can update close dates before the forecast call.
```

**Commit and best case**

```
Split the forecast into commit (late-stage deals only) and best case (all open deals), and show both against quota.
```

**Mid-week slip check**

```
Every Thursday, post only the deals whose close date passed since Monday to #sales-forecast.
```

## Guardrails

Rolling up the entire pipeline every week is a trust question, so the agent's
access is scoped and one-directional:

- **Isolation.** Every run happens in its own isolated sandbox. The session is granted access only to HubSpot and Slack, and only the forecast post is written back out.
- **Scoped secrets.** The HubSpot credential is encrypted in the Secrets
  Manager and injected into the sandbox at runtime, scoped to the agents you grant them to
  or the logs.
- **Read-only, no exceptions.** The connector into HubSpot is read-only. The
  agent never changes a deal's amount, close date, stage, or owner — it can
  only report on what it finds.
- **Everything is code.** The weighting rule, the quarter window, and the
  slipping/at-risk criteria are files in the repo, versioned and changed
  through a reviewed **change request** rather than a dashboard setting.

## The outcome

- **Every week:** Forecast rebuilt from HubSpot's current pipeline state
- **Read-only:** No deal amount, date, stage, or owner ever written
- **3 cuts:** Stage, rep, and segment rolled up in one weekly post

The forecast that used to get rebuilt by hand the week before the call now
arrives every Monday in the channel where the team already works, weighted by
HubSpot's own stage probabilities and carrying the specific deals putting the
number at risk. The agent only reads and reports; the sales team still owns
every deal.
