AI & Automation

AI Collections Agent: Past-Due Ticket Analyst

Chasing unpaid invoices means keeping notes on every overdue customer up to date. I built an AI assistant that re-reads each case twice a day, including the email back-and-forth, and fills in the notes and the recommended next step. It only suggests. A person still decides and sends every email.

Client: Marq

Key Metrics

-96% Model Cost per Ticket
-75% Run Time per Batch
3 of 3 Models Agreeing on Every Call
0 Ticket Notes Written by Hand
n8n workflow canvas of the Collections AI agent: 18 nodes from the twice-daily schedule trigger through HubSpot ticket search, email transcript, policy document, LLM call, validation and ticket update

Project Details

Marq's finance team keeps a HubSpot ticket for every customer with a past-due balance, and someone has to keep the notes on each one current. I built an AI agent that does that re-read twice a day: for every open collections ticket it pulls the ticket fields, the full email thread with the customer and the collections policy, then writes a status summary and sets three dropdowns, collections risk, recommended action and confidence. Finance opens HubSpot to an up-to-date read instead of updating it by hand. It has run on schedule since June 2026. Along the way I root-caused a bug where the agent was quietly summarizing the operator's own summaries, and in November a side-by-side model test cut the cost per ticket by about 96 percent with the same decisions coming out.

Challenge

  • Hand-maintained notes on every overdue account. One operator read each customer email thread and wrote the summary into the ticket. Management wanted a real-time view of collection likelihood and next steps across all open tickets, which no one had time to keep current.
  • Three sibling agents, one wrong blueprint. This was the third AI agent I built for the same sponsor, after a lost-deal revival agent and a churned-customer one. The first blueprint I was pointed at turned out to be a different agent on another page of the diagram, so scoping started with establishing what was actually being asked for.
  • Suggest, never act. Finance was explicit: the agent writes fields, a human decides. No emails to customers, no account freezes, no write-offs. Every design choice had to keep that line.
  • Several stakeholders, one real blocker. A finance lead with final sign-off, an accounting contractor reviewing quality, the operator using the output, and an ops sponsor holding the keys. The build could not start without a HubSpot token scoped to tickets, which only the sponsor could issue.

Approach

Lock the decisions before the build

I wrote the initial assessment, then worked the open questions down to a short list and got each one answered in writing: write straight into the existing three ticket fields rather than parallel "AI suggested" fields (the sponsor's words were that the notes were not precious), add one new field for confidence, run twice daily at 8am and 6pm Arizona time, fixed all year, and use the live dropdown values as they stood. Slack and the billing system were deferred to a later version so V1 shipped on ticket, email thread and policy document only. With the token in hand on 28 May, the build spec was already written and verified against live HubSpot, and the workflow imported the next day.

An 18-node n8n workflow, generated from a single source

The workflow runs on a schedule, searches open tickets in the collections pipeline, and processes them one at a time. For each ticket it fetches the associated company and email IDs, batch-reads the email bodies, builds a transcript capped at the fifteen most recent messages, pulls the policy document from Google Docs, and assembles one prompt that includes today's date, the current field values and any comments the team has left. The model call goes through OpenRouter with a strict JSON schema, a validation node enforces the dropdown values, and only a valid result is written back to the four HubSpot fields. Invalid output takes a skip branch instead of a write.

The prompt and the output schema live in two files and a script generates the importable workflow from them, so a prompt change never drifts from the schema it has to satisfy. Every external call continues on error so one bad ticket cannot halt the twice-daily batch. Before the first import I ran an adversarial review across four angles, n8n runtime, HubSpot API, the model and the Google Docs edge cases, which caught that the default model did not support strict structured outputs on OpenRouter. The model was switched before anything ran.

Tuned on real tickets with the people who use it

A ten-ticket sample went to the accounting contractor and the finance lead, who checked each summary against the actual email thread. The contractor rated them thorough, fair and accurate, and useful for write-off and legal calls. The finance lead's team meeting produced the design changes that shaped V1: a documented decision tree for which action applies when, the action list cut from seven options to five with freeze, agency and write-off becoming recommendations under escalation, and a separate "Additional Comments" field the team writes and the agent reads but never overwrites. One mismatch kept surviving, where the dropdown said one escalation and the first recommended step said another, so the action became a derived field: it must equal the first recommended next step, stated in both the prompt and the schema.

The bug that was really a missing permission

The finance lead's screenshot showed the agent writing "no customer email correspondence" on a ticket with a real customer reply. The email chain was built and present in every version, so I traced the live calls: the associations request returned the thirteen emails fine, and the batch read of their bodies returned a 403 for a missing scope. Because that node was set to continue on error, the failure was swallowed and the transcript came back empty, so the model truthfully reported no correspondence. The reason the earlier sample had still looked accurate was that the agent had been summarizing the operator's manual summaries in the notes field, a summary of a summary, which was exactly what the project existed to stop. The fix was two parts: the sponsor granted the email read scope, and I made the transcript fail loudly, with an explicit "email read failed" marker and a prompt instruction to treat it as a technical gap that lowers confidence, never as absence of correspondence.

Prompt changes and a 96 percent cost cut, without touching the live run

After launch, prompt edits came from the accounting contractor directly. Each one ships through the n8n public API with the same recipe: generate the new workflow file from a fresh live export, push it with the ticket search pinned to two known tickets, execute once, read the written fields back through the HubSpot API, then restore the production search. The pre-change export is the rollback.

In November the engineering manager asked where the OpenRouter spend was coming from. A pass over all 145 workflows on the instance showed this was the only active one on Claude Sonnet 4.5. Rather than switch blind, I cloned the workflow into an inactive copy with no write nodes, pinned it to two tickets, and ran the same prompt and schema through three models in parallel. All three returned the same action and risk on both tickets. The cheapest, GPT-6 Luna, also wrote the shortest notes and was the only one to catch a date slip the other two repeated. The switch was one field in the live workflow. Cost per ticket went from about three cents to about a tenth of a cent, with the run time already cut from around 100 seconds to 25 by an earlier prompt trim.

Results

  • Every open past-due ticket re-evaluated twice a day since 11 June 2026, with summary, risk, action and confidence written straight into HubSpot.
  • Zero customer-facing actions by design. The agent has never sent an email, frozen an account or written anything off. A person makes every call.
  • Model cost per ticket cut by about 96 percent in November 2026, verified on a side-by-side run before the switch, with identical decisions from all three models tested.
  • A silent data gap found and closed. The "no correspondence" bug was traced to a missing API scope rather than the prompt, and the workflow now says so out loud when email access fails.
  • The finance team edits the brain, not the plumbing. Prompt changes arrive from the accounting side and ship through a repeatable push, test and restore recipe with a rollback export every time.

Tools Used

n8n, HubSpot API v3, OpenRouter with structured outputs, Claude Sonnet 4.5 then GPT-6 Luna, Google Docs API, JSON Schema

AI n8n HubSpot OpenRouter Claude GPT Structured Outputs JSON Schema Accounts Receivable Collections Finance Ops Google Docs LLM Cost Optimization automation

Get Started

Looking to Hire?

I bring 19+ years of cross-functional experience to every role. Connect on LinkedIn to learn more.

Need a Consultant?

Start with a one-hour session on the decision in front of you, or send me the brief for a longer engagement.