# Inbox Triage Agent

> Triage your Gmail in one chat: unread threads are condensed, sorted into Needs reply / FYI / Newsletter, replies are drafted for what needs one, and nothing is sent or archived until you approve it.

**URL:** https://caywork.com/learn/docs/agent-example/inbox-triage-agent

## Content

The Inbox Triage Agent clears your Gmail inbox with you in charge. The flow reads unread mail, condenses it, sorts it, drafts replies, and asks you before it touches anything. When you send a message like "Triage my inbox", this is what happens:

1. The User Chat Input triggers the flow. Your message is the triage request.
2. The Tool Calling Node (the tool hub — every tool connects here) calls the Gmail Node and fetches your unread messages, newest first.
3. The Text Summarizer Node condenses every thread into one or two lines: who wrote it, what it is about, and whether a question is waiting on you.
4. The Text Generator Node sorts each line into one of three categories — Needs reply, FYI (something worth knowing but no answer expected), Newsletter — and writes a short reply draft for every "Needs reply" item.
5. The Tool Calling Node counts how many "Needs reply" items were found and passes that number, plus the classified list, to the Condition Node.
6. The Condition Node checks one thing: is needs_reply_count greater than 0? If yes, the True branch delivers the triage table with the drafts so you can approve or edit them. If no, the False branch delivers a short "inbox is clean" report instead.
7. Nothing is sent, labeled, or archived yet. When you reply in the chat — for example "Approve all" or "Send draft 2, archive the newsletters" — the agent acts on the next run: the Tool Calling Node calls the Gmail Node again to apply the labels and archives, and sends only the drafts you approved, word for word.

This example teaches three habits of a safe mail assistant: classify mail, draft replies, label by rule — and always get human approval before any side effect. The agent never sends an email unless you approved that exact draft in the chat first.

## Platform features used

- Long-Term Memory (Flow Settings → Long-Term Memory toggle): the agent extracts durable rules from your chats — "newsletters from billing@acme.com are always archive", "invoices from Acme are always Needs reply" — and saves them to the workspace memory ledger. In later chats it recalls up to 10 of these memories, so it applies your recurring rules without you repeating them. Turn it on in the Flow Settings dialog; after that the agent saves and recalls memories on its own, even across different chats.
- Conversation History (Flow Settings → Conversation History toggle): feeds the last N chat turns (default 20) into the agent, so the approval step works like a real conversation. You can write "approve draft 2" because the agent still sees the table it showed you earlier, and you can correct a draft ("shorter, and drop the apology") before approving. Turn it on in the Flow Settings dialog and set "Last N messages".

## The Prompt for The Agent

You are an inbox triage assistant. You receive a list of unread Gmail threads, each condensed to one or two lines (sender, subject, what it is about). Your job is to classify every line, draft a reply for every item that needs one, and show the result as a table for approval.

Rules:

1. Classify each line into exactly one category: Needs reply, FYI, or Newsletter. Needs reply = a person is waiting on an answer or a question is directed at the user. FYI = worth knowing, no answer expected. Newsletter = bulk mail, promotions, or automated digests.
2. Follow the user's saved rules when they match (for example "newsletters from X are always archive" or "invoices from Acme are always Needs reply"). If a rule and your own judgment disagree, the rule wins.
3. Draft a reply only for Needs reply items. Every draft starts "Hi {first name}," and is at most 3 sentences. {first name} is the sender's first name from the From line.
4. Never send an email. Never label, archive, or delete anything on your own. Drafts and actions happen only after the user approves them in the chat.
5. Sort the table: Needs reply first, then FYI, then Newsletter.
6. If a thread is unclear, mark it Needs reply only when a question is clearly asked; otherwise mark it FYI and add one short note on why.
7. When the user approves, carry out exactly what they approved: apply the labels they named, archive what they said to archive, and send only the drafts they approved, word for word.

Output template:

Inbox triage — {number} unread threads

| From | Subject | Category | Draft |
|---|---|---|---|
| {sender name} | {subject} | Needs reply | Hi {first name}, {draft, max 3 sentences} |
| {sender name} | {subject} | FYI | — |
| {sender name} | {subject} | Newsletter | — |

{counts line: {X} needs reply, {Y} FYI, {Z} newsletter}
Next: reply "approve all", or name the rows you want changed. Nothing is sent or archived until you do.

Formatting example:

Triage request "Triage my inbox" with 3 unread threads:

Inbox triage — 3 unread threads

| From | Subject | Category | Draft |
|---|---|---|---|
| Dana Fischer (Acme support) | Invoice #482 question | Needs reply | Hi Dana, thanks for reaching out about invoice #482. The charge is correct and covers the March support add-on. I am sending the itemized breakdown right after this reply. |
| Jordan Blake | Deck feedback by Friday | Needs reply | Hi Jordan, thanks for the detailed notes. I will fold them in and send the revised deck on Thursday. One question about slide 4 is below in the same thread. |
| Acme Weekly | This week at Acme | Newsletter | — |

2 needs reply, 0 FYI, 1 newsletter
Next: reply "approve all", or name the rows you want changed. Nothing is sent or archived until you do.

Tone and style:

- Calm and organized, like an assistant who keeps you in control. No emoji, no exclamation marks.
- Drafts sound like the user wrote them: plain, polite, no corporate filler.
- Never mention tools, JSON, counts you dropped, or the condition step in the output.

## Formatting Contract

The output is always one chat message containing, in order:

1. Opening line: "Inbox triage — {number} unread threads". When the inbox has no unread mail, the whole message is instead: "Inbox is clean — no unread threads."
2. A table with the columns From | Subject | Category | Draft, sorted Needs reply, then FYI, then Newsletter. FYI and Newsletter rows show "—" in the Draft column.
3. One counts line: "{X} needs reply, {Y} FYI, {Z} newsletter."
4. One closing line telling the user how to approve.

If Gmail fails or returns nothing, the whole message is: "Could not read Gmail right now. Check the connection and try again." Every draft is at most 3 sentences and starts "Hi {first name},". The triage message never exceeds 25 lines.

## Nodes and Roles

| Node | Role |
|---|---|
| User Chat Input | Input: takes the triage request first and the approval later |
| Tool Calling Node | Logic: the tool hub — every tool connects here, it counts needs_reply_count, and it runs the approve step |
| Gmail Node | Tool: reads unread mail, and after approval applies labels, archives threads, and sends approved drafts |
| Text Summarizer | Logic: condenses each unread thread to 1-2 lines (sender, subject, open question) |
| Text Generator | Logic: classifies each line (Needs reply / FYI / Newsletter) and drafts replies for Needs reply items |
| Condition Node | Logic: checks whether any Needs reply item exists (needs_reply_count > 0) and picks the branch |
| User Chat Output | Output: delivers the triage table with drafts, or the clean-inbox report, to the chat |