Blog

/

AI Email Workbench: inbound email triage with a decision model

Flowmails AI Email Workbench classifies every inbound message before an agent reads it, from three headers and at most 1,500 characters of plain text. The verdict is one category per message — no attachment and no body stored — and it is the same on the emailbox, the API, the CLI, MCP and a signed webhook. One switch per domain turns the classifier off for mail you would rather no model read.

Deep Dive
Inbound triage
Decision model
Privacy

Why does piping a raw inbox into an agent burn tokens?

Most of a mailbox is not for the agent. A login code, a receipt and a deploy notice are the same shape to a reader and three different jobs to a program, and a generative agent asked to sort them has to read all three bodies to say so — then keep them in context while it works out what to do. The waste is not the sorting. It is the reading.

Per inbound messageInbox straight to the agentTriage first
Bodies readevery oneonly the categories it asks for
Untrusted text in contextevery bodythe bodies it chose to fetch
What decides relevancethe model, per messagea fixed criteria set, before the model sees a body
Where a person sees itnowherethe same category, on the same mailbox

The second column is also the security argument. A body is untrusted input, and an instruction inside one is content to record rather than a command to obey — but the fewer bodies a context holds, the fewer chances that rule has to be tested. A category decided from three headers and a trimmed first paragraph is a much smaller surface than a full inbox read.

How does a decision model return a category without writing text?

Flowmails AI Email Workbench calls TypeSafe AI’s Jev, a discriminative decision model: you send a state and a fixed set of choices, and it returns a probability per choice. There is no completion to parse and no sentence an instruction inside the mail could steer, because the model never writes prose — it scores.

jev-request.httphttp
POST https://api.typesafe.ai/v1/systemone
Authorization: Bearer $TYPESAFE_API_KEY

{
  "model": "jev-latest",
  "state": "From: billing@stripe.com\nTo: ap@acme.test\nSubject: Invoice 8f21\n\nYour receipt for November is attached to your account.",
  "questions": {
    "category": {
      "type": "choice",
      "instructions": "Classify this inbound email into the single best matching category.",
      "criteria": {
        "customer": "Inquiries, support requests, bug reports, sales questions, direct human replies",
        "verification": "Login codes, OTPs, magic links, email confirmations, security alerts",
        "billing": "Invoices, receipts, renewals, refunds, failed charges, tax documents",
        "promotion": "Campaigns, newsletters, announcements, cold outreach, digests",
        "notification": "System alerts, CI/deploy notices, shipping updates, status posts",
        "other": "Any legitimate email that does not clearly fit the others"
      }
    }
  }
}

The answer is the same shape every time. The platform takes the highest probability among the keys it offered — a category the model invents is discarded, never widened into the taxonomy — and stores it with the confidence:

jev-response.jsonjson
{
  "answers": {
    "category": {
      "probabilities": {
        "billing": 0.94,
        "notification": 0.04,
        "other": 0.02
      },
      "confidence": 0.94
    }
  },
  "model": "jev-latest"
}

Six categories are built in, and they are the same on every plan:

CategoryWhat lands in it
customerinquiries, support requests, bug reports, sales questions, direct human replies
verificationlogin codes, OTPs, magic links, confirmations, security alerts
billinginvoices, receipts, renewals, refunds, failed charges, tax documents
promotioncampaigns, newsletters, announcements, cold outreach, digests
notificationsystem alerts, CI and deploy notices, shipping updates, status posts
otheranything legitimate that fits none of the above — the fallback, so a message is never left unclassified

A paid plan adds custom categories, and their description is the criteria: the sentence you write is what the model classifies against, so a category is configuration rather than a prompt you have to keep in a repository.

Why is the category read-only state instead of an action?

Because a platform that acts on a category is a rule engine with a nicer name, and a rule engine is the one thing this product refuses to be. Flowmails records what a message is and stops there. What happens next belongs to the person reading the mailbox or to the agent’s own code, both of which have more context than a classifier ever will.

  • No automatic reply, forward or delete. A “customer” tag does not open a ticket, and a “promotion” tag does not archive anything.
  • No condition language. There is no rule table, no execution log and no queue that decides; message_triage stores the category, the confidence and who decided it.
  • A person’s correction is the last word. A manual category is stored apart from the model’s and is never overwritten by it, so correcting a misclassification is permanent until somebody asks the model again.
  • The agent still decides. An agent that wants to escalate a billing mail writes that rule in its own code, where it can be reviewed, versioned and tested.

How do you triage in place inside the emailbox?

The human surface is the mailbox itself, not a second dashboard. Every inbound tab gets a category strip above the list, each classified row carries a chip, and the reading pane shows the verdict with the confidence and who decided it. Nothing about reading mail changed to make room for it.

  • A filter bar with counts. All, the six built-ins, any custom category the domain defines, and Unclassified — each with the number of rows on screen. The count describes the page in front of you, not the whole mailbox.
  • A manual override. Change a category from the reading pane and the row is stored as manual with no confidence, because a person does not have a probability.
  • Reclassify on demand. Ask the model again for one message. If the deployment has no model credential or the monthly cap is spent, the pane says so in words instead of leaving a button that looks broken.
  • A switch in the strip. Pause AI triage for the domain from the same bar, with the disclosure beside it and a link to manage categories.

How does an agent read the same triage state?

Over the same surfaces it already uses for mail, because a category is a property of a message rather than a feature of the dashboard. The listing is metadata only — no bodies — so an agent can filter first and fetch second:

triage-then-read.tstypescript
import { Flowmails } from "@flowmails/flowmails-sdk";

const fm = new Flowmails({ apiKey: process.env.FLOWMAILS_API_KEY! });

// One listing instead of an inbox read: metadata only, no bodies.
const { items } = await fm.triage.list({ category: "verification", limit: 10 });

for (const row of items) {
  // The body is a second, deliberate request — for the rows that matter.
  const mail = await fm.messages.get(row.messageId, { format: "markdown" });
  const [code] = mail.extracted?.verificationCodes ?? [];
  if (code) console.log(row.categoryKey, code.code);
}

A harness with no SDK gets the same listing from the shell:

triage.shbash
$ flowmails triage --category verification --limit 5
<9f2c1a@example.test>  verification  (ai 97%)
  no-reply@example.test → ap@acme.test
  Your sign-in code

$ flowmails triage --source manual
<41b7de@example.test>  billing  (manual)
  invoices@vendor.example → ap@acme.test
  Invoice 8f21
SurfaceWhat it gives an agent
GET /api/agent/triagea cursor-paginated listing, filterable by domain, category and source
GET /api/agent/messages/:idthe usual body read, carrying triage alongside it — or null
MCP list_triagethe same listing as a read-only tool, so a session with no skill installed still gets it
message.triageda signed webhook as the category is assigned, for an agent that would rather be told than poll

The webhook is metadata only, and that is a deliberate limit: a receiver gets the category, the confidence and who decided it — never a body, never an attachment. It is enough to decide whether to fetch the message, which is the whole point of triage:

app/api/flowmails/route.tstypescript
import { createHmac, timingSafeEqual } from "node:crypto";

export async function POST(request: Request) {
  const raw = await request.text();
  const sent = request.headers.get("X-Flowmails-Signature") ?? "";
  const timestamp = request.headers.get("X-Flowmails-Timestamp") ?? "";
  const expected =
    "sha256=" +
    createHmac("sha256", process.env.FLOWMAILS_WEBHOOK_SECRET!)
      .update(timestamp + "." + raw)
      .digest("hex");

  const ok =
    sent.length === expected.length &&
    timingSafeEqual(Buffer.from(sent), Buffer.from(expected));
  if (!ok) return new Response("bad signature", { status: 401 });

  const event = JSON.parse(raw);
  if (event.event !== "message.triaged") return new Response("ok");

  // Metadata only: what the mail is, never what it says.
  const { messageId, category, categoryName, confidence, triageSource } = event.data;
  console.log({ messageId, category, categoryName, confidence, triageSource });

  return new Response("ok");
}

What leaves the platform when triage runs?

An inbound classifier reads mail, so the honest answer is a precise list rather than a reassurance. The payload is built by one function with no parameter for anything else, and the list below is exactly what it can carry.

  • Three headers — the sender, the recipient and the subject line.
  • Up to 1,500 characters of plain text. HTML is stripped first, so style blocks, tracking pixels and hidden preheaders never reach the model; a quoted reply is removed, because the earlier message was already classified once.
  • No attachments. Not their bytes, not their filenames. The classifier’s input type has no attachment field, which is what makes that a structural fact rather than a promise.
  • No quarantined mail. A message that junk filtering holds produces no inbound event, so it never reaches the classifier in the first place.
  • No body stored. The verdict is stored; the message stays in the mailbox, where retention governs it.

How do you turn it off for one domain?

With one switch, per domain, and it is on by default — a decision the onboarding wizard states out loud next to the toggle rather than burying in a settings page. The disclosure names what is read, what is never read, and what never happens: no auto-reply, no forwarding, no automatic action.

  • During onboarding. The AI Email Workbench card is on Step 1, on by default, and the choice is saved with the domain row in the same request that creates it.
  • Later, from the domain page. The AI Email Workbench card carries the same switch and the same disclosure, plus the category list and the plan’s custom-category ceiling.
  • From the mailbox. The triage strip has a Pause button for the selected domain, so a reader who suddenly receives something sensitive does not have to leave the inbox.
  • What off means. No mail from that domain is sent to the model. Categories already stored stay readable, and new messages are recorded as skipped rather than silently unlabelled.

What does AI Email Workbench cost?

The six built-in categories are included on every plan, Base included — they are code, so charging for them would be charging for a constant. What a plan meters is stored configuration: the custom categories you write for a domain. Classification itself has no price, because selling it per call would put the platform’s judgement on an invoice.

PlanBuilt-in categoriesCustom categories per domain
Base60
Pro610
Enterprise630

The deployment’s monthly classification cap is a cost control, not a sold allowance: it exists so an inference bill cannot run away, it does not change when a plan does, and hitting it is recorded as a skip rather than as a failure.

Common questions

Straight answers to the five questions that come up once the design is on the table.

Q: Does a person's category ever get overwritten by the model?

No. A manual category is stored with source manual, and the automatic classifier refuses to replace it — the refusal is in the write itself, not just in a check before it, so a correction made while a classification is in flight still wins. Reclassify is the one action that replaces a manual category, and it only runs when a person presses it.

Q: What exactly is sent to the decision model?

The sender, the recipient, the subject line, and at most 1,500 characters of plain text: HTML is stripped and a quoted reply is removed before the body is trimmed. Attachments are never read, and a message that junk filtering quarantined never reaches the classifier at all, because a held message does not produce an inbound event.

Q: What happens to triage when the switch is off?

The domain's mail is not sent to the model and no category is produced. A record is written with status skipped_disabled so an operator asking why a message is unlabelled gets an answer instead of silence, and the categories already stored stay exactly where they are. Turning the switch back on classifies the next message.

Q: Is triage billed per message?

No. The six built-in categories ship on every plan, and a paid plan adds stored configuration — 10 custom categories per domain on Pro, 30 on Enterprise — not a number of classifications. Inference is bounded by a deployment-level monthly cap rather than a per-call price, so a busy mailbox does not produce a surprise line item.

Q: Can an agent act on a category by itself?

That is the agent's code, not the platform. Flowmails stores a category and stops: there is no rule engine, no condition language and no automatic reply, forward or delete. The webhook and the listing tell the agent what a message is; doing something about it is a decision it makes with the tools it already has.