Inspiration
Chasing overdue invoices is the part of running a small business nobody enjoys. It is emotionally awkward (you are nudging a client or even a friend about money), it eats hours every week, and it is exactly the kind of judgment-heavy, repetitive work that should not require a human to sit down and do it by hand every single time. PayPal's own Orders and Checkout APIs already make it trivial to generate a real, payable link in seconds -- so we asked: what if an agent could decide, on its own, who needs a nudge, how hard to push, and then hand them a real PayPal link right inside the message, with no human copy-pasting anything?
What it does
CollectAI is an autonomous invoice-collections agent built on the Strands Agents SDK. Give it an overdue invoice -- client name, amount, days overdue, how many reminders were ignored, relationship history -- and it runs a full reasoning pipeline before a human ever sees it:
- Risk assessment -- scores how risky the account is from the money and the history involved.
- Payment probability -- separately estimates the odds the client pays without being asked at all.
- Action planning -- if the odds of voluntary payment are high, it leaves the account alone on purpose (chasing someone who was already going to pay just burns goodwill). Otherwise it picks a branch: a friendly standard nudge, or a firmer escalation, and picks the channel (email, WhatsApp, SMS) based on what contact info actually exists.
- Drafting -- writes the actual message in a tone matched to the relationship and the branch, with a real PayPal payment link token embedded in the body.
- Human approval gate -- nothing goes out until a person reviews and approves, edits, or rejects the draft.
- Execution -- on approval, it creates a real PayPal order through PayPal's Agent Toolkit and sends the message with the live payment link swapped in.
- Closing the loop -- a PayPal webhook tells the agent the moment the invoice is actually paid, so it marks it closed and reflects on whether the approach worked, feeding that back into the client's relationship score for next time.
- Negotiation -- if the client replies instead of paying, a separate negotiation agent can read the reply and either settle, propose an installment plan (billing each installment automatically as it comes due, each with its own PayPal order), or hand the thread back to a human if it gets complicated.
How we built it
- Agent graph: Python, built on the real Strands Agents SDK (not hand-rolled prompting) -- risk, probability, planning, drafting, execution and negotiation as distinct agents/tools in a graph, backed by Gemini.
- Backend: Node/Express, bridging to the Python agent over a stdin/stdout JSON protocol, with real PayPal Orders/Checkout API integration (sandbox) for both the main approval flow and the autonomous negotiation loop's own PayPal tool calls.
- Frontend: React + TypeScript (Vite), a from-scratch neo-brutalist ledger/approval UI so every decision the agent makes is visible and reversible by a human before anything is sent.
- Persistence: Firestore for invoices, client relationship memory, message history and payment plans, so state survives Cloud Run's scale-to-zero cold starts instead of living only on local disk.
- Deployment: Google Cloud Run (asia-south1), auto-deployed via a Cloud Build trigger on every push to main.
Challenges we ran into
We originally built on PayPal's Invoicing API, then hit a sandbox-side permissions wall that blocked that scope entirely for this developer account -- so we pivoted to the Orders/Checkout API, which turned out to be the better fit for an agent minting one-off payment links mid-conversation anyway.
The most interesting bug came from turning on real Firestore persistence today. Two separate things were silently wrong at once: (1) the Cloud Run service's own account had never actually been granted the IAM role to use Firestore, so every read/write had been failing and quietly falling back to a local JSON file the entire time -- it looked like it worked because the container stayed warm between the write and the read; and (2) once we fixed the permissions, a Python log line that printed straight to stdout at import time -- before our own stdout/stderr redirect existed -- started corrupting the JSON contract between the Node server and the Python agent subprocess, surfacing as "Invalid JSON response from Strands Agent bridge." Finding and fixing both, then proving the fix by forcing a brand-new container and watching a real write land in the Firestore console, was the most satisfying debugging of the build.
Accomplishments that we're proud of
Getting the full loop -- risk, probability, planning, drafting, human approval, a real PayPal payment link, and a webhook that closes the invoice on its own -- running end to end, with no mocked step in the demo path, and state that now genuinely survives a cold start instead of just looking like it does.
What we learned
That a successful test on Cloud Run can be lying to you if your fallback path degrades silently -- the local-JSON fallback was specifically designed to be safe, and that safety is exactly what let the missing IAM role hide for as long as it did.
What's next for CollectAI
Production WhatsApp approval (currently limited to an allow-listed test recipient in the Meta sandbox), smarter negotiation strategies that learn from which tone actually gets a reply, and multi-channel reconciliation when a client responds somewhere other than where the agent reached out.
Built With
- express.js
- firestore
- gemini
- google-cloud-run
- node.js
- paypal
- python
- react
- typescript