← Back to applications

Chargeback investigation agent active

Given a chargeback, the agent gathers what is known about the case: the transaction and its logs, the policies that apply, how similar cases were resolved, the merchant's risk and the customer's history. From that it proposes a justified resolution and grades itself. High-risk cases stop and wait for a human analyst.

Python 3.11FastAPIn8n Claude (Haiku + Sonnet)QdrantRAG Dockerpytest

Direct mode and n8n mode

The panel can run the pipeline directly or through your own n8n instance. If your n8n stops responding mid-run, the panel switches back to direct mode and says so. I'd rather show an error than a report claiming it went through the orchestration when it didn't.

1232tests in CI
36steps in the circuit
32endpoints
46n8n nodes

What it solves

A chargeback is a dispute: the customer doesn’t recognize a charge and someone has to decide whether the money goes back. Deciding means pulling together data that lives in different places: the transaction and its logs, the policy that applies, how similar cases were resolved, how risky the merchant is and what history the customer has. It also takes judgement that isn’t written down in any table.

The agent assembles that case file, proposes a resolution with its reasoning and then grades itself. On high-risk cases it stops and leaves the file waiting for a human analyst.

What it produces

The testing panel runs the circuit over any transaction in the dataset and shows the result without installing anything. The three scenarios cover both of the router’s outcomes: automatic rejection and human review.

Testing panel: health of FastAPI, SQLite, Qdrant and Langfuse, plus three test scenarios with their expected outcome.
The panel checks its own dependencies before letting you run anything: if Qdrant is down you see it there, before the pipeline starts.

Every run ends in a report: the transaction, the customer and merchant profiles with their flags, the policies that apply, the precedents, and the proposed resolution with its reasoning.

Chargeback report: transaction data, risk level, customer profile and merchant risk profile with anomaly flags.
A high-risk case. The antifraud score, the geographic anomaly and the suspended merchant are what make the circuit stop and wait for an analyst.

These three reports ship with the delivery package. I picked them for the policy situation each one covers, without looking at the score: a crypto blocker, a VIP customer with a fraud score and an extended SLA outside LATAM.

The reports are in Spanish because that is what the system wrote. A translation would show output it never produced.

A blocking policy stops the case before the model gets an opinion. The code decides, and the report explains which rule applied and why there was nothing to deliberate.

High risk. The agent assembles the case and proposes a resolution, and the case waits for an analyst with everything needed to decide on a single screen.

A duplicate charge outside LATAM, where the response window is different. Here the right policy depends on where the charge happened.

The circuit

These are five interactive, self-contained diagrams that open in any browser, offline, with nothing to install. They’re in reading order: first what the circuit does, then how the pieces talk to each other.

The sample strings inside them (the indexed policy, the case document, the assembled query) stay in Spanish because they are what the system actually sends.

cache hit · returns the stored report and stops Webhook POST Cache SQLite Context 7 calls SQLite Qdrant the model reasons · it doesn't decide Policies evaluates Resolution drafts Judge scores Rule decides Rejected automatic Analyst reviews high risk
The 36 steps, compressed down to what the design turns on. Code gathers the evidence —seven calls, always the same ones in the same order— and only then does the model come in. It interprets, but it doesn't pick the exit: a deterministic rule does. That is why an investigation can be audited by reading the canvas.

All 36 steps in execution order plus the 4 error exits, each with its endpoint. Generated from the workflow's own JSON, so it can't drift from the real flow.

The fifteen calls in order, what each one touches (SQLite, Qdrant or the model) and the two times the conversation runs the other way. A one-minute read.

The 32 endpoints drawn as a circuit. For each piece it explains what it does and why it's split that way: which SOLID principle backs each seam and which patterns are used. The other diagrams show the flow, and this one shows the design decisions.

The whole retrieval chain, followed through a real case: what gets indexed and what doesn't, how the query is built, why the two collections are searched by opposite criteria, and where the index writes itself.

The three layers, coverage per package, and the sixteen regression tests that pin real bugs so they can't come back. None of those sixteen bugs broke an import.

The RAG

The RAG is a chain of transformations over text, and a model decides none of them.

Policy 60–90 tokens never split 1 point policies · 17 Historical case its transaction glued 1 point historical_cases · 60 Qdrant 1024 d · voyage Context built by code Model code builds the query, picks how many results to bring back and ranks them — a model decides none of it
The two collections are indexed by opposite rules, and that is the design decision. A policy goes in whole: condition, threshold and exception only mean something together, and splitting them would have multiplied the points without adding a single useful distinction. A case, on the other hand, never goes in alone — its transaction is glued to it, because a precedent without its context resembles nothing.

The RAG diagram further down has the full detail: what text gets embedded, how the query is built and why the two collections are searched by different criteria.

How it’s built

The judge’s numbers

What I like most about this project is how it treats its own numbers.

The repo shows a 9.1/10 judge score and then explains where it comes from. That number came from development runs that can’t be reproduced today without API credit. The three reports shipped in the package average 8.67. The two later runs, done with free-tier models, score 8.97 and 8.4, but shouldn’t move the badge: each model grades itself by its own yardstick, and on the cases both runs share the score swings by up to ±1.8 between them.

It also leaves a script to measure again, which runs the sample, writes the case-by-case detail and reports the cost.

Every report the system generates states how it was produced: whether it really ran or is a stored result, with which model, and how far the score can drift. That travels in the HTTP header, in the body and in a log warning.

Trying it

The live panel runs the full pipeline with nothing to install and no key to provide. It starts in demo mode, which falls back to a free-tier model and actually runs the pipeline rather than replaying a stored result.

It’s on Render’s free tier and sleeps after 15 minutes idle, so the first call can take about a minute to wake it up.