Compas: moving permission, not money
What inspired us
It started with Gladys.
Gladys is an invented grandmother in Medellín, but her situation is common. Her grandson Pedro works abroad and wants to pay for her blood-pressure medicine. Her granddaughter Andrea lives with her and does the errands. The usual answer is "send Andrea the money", and that is where things go wrong. Once the money arrives it is just money. It can pay for losartán, but it can also pay for anything else, and Pedro never learns which.
- Fast transfers are already solved. Bre-B already moves pesos free and instantly for tens of millions of people. Another way to send money would add nothing.
- Remittances are huge. Colombia received a record US\$13.1B in 2025, and almost none of it carries any purpose.
We treated Compas as a research project on AI in payments, and built it on PayPal. Pedro, as a member of the diaspora, most likely already uses PayPal, and PayPal is good on agentic commerce. The question became sharper: if an AI agent does Andrea's errand, who keeps the agent on a leash?
How we built it
Version 1
- Pull at the point of sale, not push and not escrow. Pedro approves one interactive outgoing-payment grant with
debitAmountandinterval. Compas pays the merchant only when Andrea confirms a purchase. Pushing money to Andrea can't restrict it afterwards. Escrow would make us a custodian, which needs a license. - Deterministic rules decide; AI only advises. This became the project's central idea.
- A merchant trust matrix. A shop declares its categories, and Compas assigns each declared category a confidence based on two axes: how independent evidence corroborates it, and what payment history shows.
$$ \text{confidence}(m, k) = M\big[\,\text{corroboration}(m,k),\ \text{history}(m,k)\,\big] \in {\text{CONTESTED}, \text{LOW}, \text{MEDIUM}, \text{HIGH}} $$
History counts distinct payers $p$ who confirmed purchases within 180 days, never the number of transactions, so a shop can't manufacture trust with fake volume. It becomes established when $p \ge 10$ over at least 60 days, and contradicted when enough payers report a mismatch:
$$ p_{\text{mismatch}} \ge 2 \quad\text{and}\quad \frac{p_{\text{mismatch}}}{p} \ge \frac{1}{5}. $$
The matrix has two rules that the code enforces: history alone never reaches HIGH, and better evidence never lowers confidence. Only an independent attester can make a shop fully trusted.
Version 2: PayPal and AI
The Paypal checkout pipeline looks like this:
intent → mandate active? → delegate? → time window? → budget?
→ merchant evidence → line items (verified CUM) → errand fits?
→ ALLOW ⇒ one PayPal order, payee = pharmacy, Pedro approves, Compas captures
The policy is a pure function. If $x$ is a purchase intent and $m$ a mandate,
$$ \text{decide}(m, x) \in {\text{ALLOW}, \text{DENY}, \text{REVIEW}}, $$
and only ALLOW ever creates a PayPal order. An allowed amount $a$ is reserved atomically against what is left:
$$ a \le R = B - \sum_{\text{reserved}} a_i - \sum_{\text{captured}} a_j . $$
On top of that we added three AI pieces, each kept on the "proposes" side of the line:
- The analyst. Claude reviews a pharmacy's catalog ahead of time. It looks up each SKU's candidate INVIMA medicine codes (CUM) in an Elastic index built from datos.gov.co. The model may only choose among the candidates it was given, and a deterministic verifier then re-reads every pointer from INVIMA's own data. Anything the model judges without a checkable source can only become a flag. The rule for flagging a "pharmacy" that mostly sells other things is simple arithmetic over the model's item classes:
$$ n_{\neg\text{med}} \ge 2 \quad\text{and}\quad \frac{n_{\neg\text{med}}}{n} \ge \frac{1}{3}. $$
A flag can only lower trust, and only a human reviewer can withdraw one, so a fooled model can't clear its own mistake.
- Errands. Andrea says "la losartán de mi abuela, la de siempre". A model drafts a structured errand, and only Andrea can confirm it. At checkout, a cart line fits errand item $k$ only if
$$ \text{CUM}(\text{sku}) \in A_k \quad\text{and}\quad \sum q_{\text{sku}} \le u_k, $$
where $A_k$ is the set of medicine codes Andrea accepted and $u_k$ the unit cap. This is plain set membership, and Compas never decides which drugs are "equivalent".
- An MCP server for any agent.
POST /mcpexposes four tools:search_eligible_merchants,check_purchase,propose_purchaseandget_mandate_status. None of them can pay. Agents sign in with errand-scoped OAuth 2.1 (PKCE S256, audience-bound tokens, rotating refresh tokens), and Andrea picks which errands an agent may use. The demo's third act shows a real agent making real MCP calls. An instruction hidden on the pharmacy page tells it to add a gift card, and Compas refuses the cart before PayPal ever sees an order.
The stack is TypeScript end to end: a Next.js demo with simulated PayPal, Nequi and pharmacy screens, a Node backend, Postgres on Supabase, Elastic for the CUM index, the Claude API, and real PayPal sandbox orders. It is deployed on Render with one isolated workspace per visitor.
What we learned
- AI proposes, the mandate decides. We reached this rule in Medellín on instinct, and the research later backed it up. The IMF's April 2026 note on agentic payments asks designers to keep authorization deterministic, and Google's AP2 builds on signed mandates. Two security papers then showed that a valid signature means nothing if the agent was manipulated before it signed. Merchant text is attacker-controlled input, so in Compas it reaches a model only as quoted data, and it can never raise trust.
- "Verified" has to mean re-read from the source. A model saying "SKU 123 is CUM 456" is a pointer, not a fact. The fact is INVIMA's record.
- Purpose checks aren't enough. A gift card fails the purpose check. Ten boxes of losartán pass it, and so does a second drug. That is why errands exist: the delegate's confirmation has to say what may be bought, not just that something may.
- Registries are not reality. A Colombian CIIU code says what a business registered, not what it sells. Supersociedades confirmed that merchants may legally do more than they registered, and a 2008 Bogotá study found pharmacy lists that included shops selling no medicine. That gap is exactly where evidence and history have to come in.
Challenges we faced
PayPal took away a lock.
$$ P(\text{bad payment}) \approx \prod_{j=1}^{3} P(\text{lock}_j \text{ fails}), $$
PayPal has no equivalent of a grant cap. We planned a hybrid that would charge Pedro's saved PayPal account for small, fully checked purchases. The sandbox then answered 403 NOT_AUTHORIZED to vaulting, so we chose per-order approval: Pedro approves every order at PayPal, which shows him the amount and the pharmacy, and Compas captures only afterwards. That restores the third lock. We say so openly in the pitch rather than pretending PayPal enforces our budget.
Sandbox surprises. PayPal validates payee.merchant_id when an order is created, but it does not check payee.email_address. An order to an email with no account is accepted. We switched to merchant IDs everywhere.
Health data stays home. A purchase of losartán reveals hypertension. PayPal orders carry only opaque references and lines named "Item 1", "Item 2". The pharmacy knows what it sold, and PayPal doesn't need to learn Gladys's diagnosis from us.
Elastic's hosted LLMs returned 403 on our trial project, so Claude became the default model, with Elastic's inference endpoint as the fallback. Any malformed model answer fails the whole analyst run closed.
Making a public demo safe. On a public URL every visitor would have been the same Pedro, spending the same budget with the presenter's sandbox passwords. We added in-memory workspaces per visitor (idle timeout of 2 hours, at most 300 live), let visitors enter their own sandbox account IDs (never passwords), cached the analyst run, and added rate limits. Render also kept overwriting NODE_ENV, which cost us an evening.