Menlo TechOperations & Finance
Clave Case

Algorithm Tour

How artificial intelligence is woven into everything Menlo Tech does.

Scroll to start the tour

At Menlo Tech, Clave turns a home mortgage request into a process that moves on its own: it checks the documents, sends the proposal to three banks at the same time and follows every step until the keys are handed over. Clave checks; only the bank approves.

Instead of putting artificial intelligence on top of a manual process, we designed the process around it. Agents interpret information, execute tasks and coordinate systems; people step in where there is uncertainty, sensitivity or a need for authorization. Algorithms decide who does what — and leave everything recorded.

3
entry doors for the proposal
5
stages to the keys
3
banks receive the proposal in parallel
200
proposals per analyst, at most

Phase 1 design references. Proposed architecture: not measured results.

  • Entity resolution
  • Intent classification
  • Computer vision
  • Confidence calibration
  • Cost-sensitive decisions
  • Queues and retries
  • Financial mathematics
  • State machines
  • Audit sampling
  • Events and workflow

Let’s follow a single proposal, from the first conversation to the keys, to see some of the algorithms working behind the scenes. Then we will step back and look at the whole system.

Chapter 1

Entry and identity

Three doors, one person: before any analysis, Clave needs to know who is who.

A proposal is born in three ways: the broker saves the client in iList (the agency’s CRM), the broker creates the proposal in Clave in five questions, or the buyer arrives on their own through the website. Each door speaks a different dialect — fields, formats and data quality.

First, we normalize. CPF with digits only and its check digits verified, mobile phone in international format, standardized address. What fails validation does not enter the process: it goes back with the reason.

d₁ = ((10 · Σi=1..9 ci·(11 − i)) mod 11) mod 10

Then, we resolve entities. The same buyer can arrive through two doors, and the same person can be both buyer and broker. We compare attribute by attribute, with weights, and decide: same person, different person or doubt for Ops.

score(a, b) = Σk wk · simk(ak, bk)

Finally, confirmation. The mobile phone is confirmed with a six-digit code; the CPF data is checked against identity sources once per person. If they do not match, a person helps — the algorithm does not insist.

Avoids duplicate proposals for the same person and the same property.

Resolve the entities interactive
same person
doubt → Ops
different
score(a, b) = Σk wk · simk(ak, bk)  ·  weights: CPF 0.5 · phone 0.2 · name 0.2 · property 0.1
Door 1 · iListagency CRMDoor 2 · broker createsfive questions in the appDoor 3 · buyerarrives on their own through the websiteOne proposalProposal → Documents →Banks → Contract → Keys3 doors, 1 objectEach door speaks a dialect: different fields, formats and quality.rawnormalizedresult123.456.789-0912345678909✓ digits ok(21) 99999-0000+5521999990000✓ E.164 format123.456.789-00—✗ invalid digitR. da Passagem 12 ap3R. da Passagem, 12✓ standardizedd₁ = ((10 · Σ cᵢ·(11 − i)) mod 11) mod 10Invalid data does not enter: it goes back with the reason.Record AAna S.CPF …789-09phone …0000R. da Passagem 12Record BAna SouzaCPF …789-09phone …0001R. da Passagem, 12name 0.95cpf 1.00phone 0.00property 1.00score = 0.5·cpf + 0.2·phone + 0.2·name + 0.1·property= 0.50 + 0.00 + 0.19 + 0.10 = 0.79differentdoubt → Opssame person6-digit code on WhatsApp••••••resend only after 30 secondsSerasa ✓Receita ✓once per person✓ data matches → continues to documents✗ no match → a person from Ops helpsThe same person can be both buyer and broker: one account, two roles.
Chapter 2

The assistant

A WhatsApp conversation needs to be understood, answered at the right time and handed to a person when necessary.

The buyer talks to the assistant by text or audio: sends a photo of a document, asks “so?”, complains, asks to talk to someone. Each message is transcribed, if it is audio, and becomes text with the context of the proposal.

A classifier estimates the intent: document, status, question, request for a person, out of scope. The output is not an answer, it is a probability distribution — and that is what makes it possible to know when to doubt.

P(c | x) = exp(zc) / Σj exp(zj)

Routing uses confidence. If the highest probability passes the threshold and the margin over the second is large, the assistant answers. If not, the conversation goes to Ops, with its context. Asking for a person always leads to Ops, by rule.

answers ⇔ maxc P(c|x) ≥ τ ∧ p₁ − p₂ ≥ δ

What the assistant sends is also classified. Messages A and B go out on their own; C — bad news, third collection notice, any sentence outside the templates — only goes out with approval from an Ops person; D never goes out. The class comes from a deterministic rule, not from the model.

Answer or call a person? interactive
assistant answers
go to Ops
answers ⇔ maxc P(c|x) ≥ τ ∧ p₁ − p₂ ≥ δ ∧ intent ≠ “person”
“I sent the payslipjust now”▶ audio 0:12photo“Received! I’mchecking.”Text + contextaudio transcriptattachment typeproposal statewho the sender is“I sent the payslip just now”document0.91status0.03question0.02person0.02out of scope0.02P(c | x) = exp(zc) / Σ exp(zj)one probability per intent; they sum to 1highest probability ≥ τ and margin ≥ δ ?assistant answersand records the eventgoes to Opswith the conversation contextAsked for a person? Always Ops: it is a rule, not a probability.margin = p₁ − p₂ avoids deciding when two intents are competing.Agoes out on its ownroutine messageBgoes out on its ownroutine messageConly goes out with Ops approvalbad news, 3rd collection notice, sentence outside the templatesDnever goes outforbidden in any caseA rule decides the class, not the language model.
Chapter 3

Documents into data

A photo of a payslip becomes verified fields in minutes — that is the buyer’s moment of truth.

The buyer photographs a document and sends it through the web area or WhatsApp. It is the moment they decide whether to trust Clave: seeing the first document checked in minutes, without chasing anyone.

First, a vision model recognizes the document type: payslip, bank statement, proof of address. “Other document” is a legitimate answer — better than forcing a fit.

ŷ = argmaxc softmax(f(image))c

Then, reading: OCR and vision-language models extract the fields — name, CPF, amounts, dates, issuer. Each field comes with its own confidence, because an unreadable value should not contaminate a clear name.

Cross-validation compares what was read with what the proposal says: does the name match? is the document within its validity? is the amount compatible? This is where a perfectly legible document can still be rejected.

Finally, a combined confidence and one of five outcomes: looks right, unreadable, expired, data does not match or other document. Above the threshold the model checks it on its own; below, the case goes to the Ops desk.

conf = Πf conffield f × conftype × confvalidation
Combine the confidences interactive
combined confidence
decision
likely label
conf = confreading × conftype × confvalidation  ·  checks on its own ⇔ conf ≥ τ
PhotoTypeFieldsCross-checkConfidencePAYSLIPthrough the web areaor WhatsAppgoal: the first documentchecked in minutesWhat document is this?payslip0.93bank statement0.04proof of address0.02other document0.01ŷ = argmax softmax(f(image))“other document” is also a valid answerFields read, each with its confidencenameAna Souza0.99CPF***.456.789-**0.98net amountR$ 8,420.000.91reference month09/20260.96issuerCompany X0.88Cross-validation with the proposal✓ name = proposal name✓ CPF = CPF on file✓ reference month within validity✗ income incompatible with the declared oneoutcome: data does not matchFive possible outcomeslooks rightunreadableexpireddata does not matchother documentconf = Π conf(field) × conf(type) × conf(validation)conf ≥ τ → checks on its own · otherwise → Ops desk
Chapter 4

Confidence and policy

The model estimates; the policy decides. Where is the line between what the machine resolves and what goes to a person?

The model is probabilistic; the policy is deterministic. The decision engine confronts the evidence with a threshold: above it the model checks on its own, below it the document goes to the Ops desk. That is why the desk only sees what stayed uncertain — and why it may, one day, be empty.

For the threshold to hold, the probability has to be calibrated: when the model says 90%, it should be right about 90% of the time. We measure this by comparing confidence and accuracy per band.

ECE = Σb (nb/N) · |accuracyb − confidenceb|

And where to put the threshold? Reviewing costs cr; accepting an error costs cf. Accepting is worthwhile as long as the expected cost of the error is lower than that of the review. The minimum of the total cost curve comes straight from this calculation.

accept ⇔ (1 − p) · cf < cr ⇔ p ≥ 1 − cr/cf

The threshold is not an eternal number. It changes by document type, by bank and by model version — and sampling audit, in chapter 8, verifies whether it still holds.

Use the controls at the end of this chapter and watch the optimal threshold shift.

Where is the threshold? interactive
optimal threshold τ*
checked automatically
error among accepted
cost vs. reviewing everything
τ* = 1 − cr/cf  ·  confidence ~ Beta(20, 1), calibrated (illustrative)  ·  cost(τ) = cr·P(p<τ) + cf·P(error, p≥τ)
confidence distribution (illustrative)0.500.600.700.800.901.00threshold τ = 0.90decides on its own →← Ops deskthe desk only receives what fell below the thresholdconfidenceobserved accuracycalibrated: when it says 90%, it is right ≈ 90%ECE = Σb (nb/N) · |accuracyb − confidenceb|threshold τexpected cost per documentreview (c_r)accept wrongly (c_f)total cost · minimum at τ*accept ⇔ p ≥ 1 − c_r / c_fThreshold by document type (illustrative)payslipτ = 0.93bank statementτ = 0.95proof of addressτ = 0.90document with photoτ = 0.97changes by type, by bank and by model versionnew version → recalibrate before releasingand check in the audit whether it still holds (ch. 8)
Chapter 5

Submission to banks

The same proposal, three banks at the same time, never duplicating a request.

With the buyer’s consent, Clave sends the proposal to the three chosen banks at the same time. Each submission is an independent task, with its own state: created, under review, document requested, answered, late.

Integrations fail: the bank’s portal goes down, the response is slow. The policy is to try again with growing waits and a little randomness, so thousands of proposals do not knock on the bank’s door in the same second.

waitn = min(C, B · 2n) + jitter

Resending must not duplicate. Each submission carries an idempotency key derived from the proposal and the bank: if the same request arrives twice, the bank sees only one.

key = hash(proposal, bank, data version)

When a bank asks for a document, only that submission stops; the others continue. Each bank has a typical response time: past the deadline, the submission becomes “late” and Clave chases the bank, visibly to whoever is waiting.

P(delivery within n attempts) = 1 − pn+1
Try again — for how long? interactive
submission delivered
all 3 delivered
maximum wait
fall to Ops
P(delivery) = 1 − pn+1  ·  wait = Σk<n min(C, B·2k), C = 120 min
Proposalconsent ✓Bank Aunder reviewBank Bunder reviewBank Cunder reviewSame proposal, three banks at the same time.✕✕✕✓#1#2#3#45 min10 min20 minwait(n) = min(C, B · 2ⁿ) + jitterthe wait grows; the jitter keeps everyone from trying togetherkey = hash(proposal, bank, version)submission #1resendBankjust one requestsame key → the bank sees just one requestresending is safe: the operation is idempotentBank Aanswered ✓Bank Basked for a document · only this submission stopsBank Clate → Clave chases the bankA refusal is not bad news while another bank is evaluating.
Chapter 6

Offers and financial mathematics

Each bank answers in its own way. Clave turns the answers into comparable numbers and checks the math.

Banks answer by PDF, email, portal or phone. Clave turns each answer into comparable fields — amount financed, term, rate, installment, CET, total paid — always as the bank sent it. It does not invent conditions and does not choose the bank for the buyer.

Before showing any offer, an arithmetic validation: does the stated installment match the rate and the term? If it diverges beyond the tolerance, the answer goes to Ops to be classified instead of reaching the buyer.

PMT = P · i / (1 − (1 + i)−n)

Under the Price system, the installment is constant, but its composition changes: at the beginning, almost all of it is interest; over time, amortization grows. The total paid and the CET — the total effective cost, the rate that equates the net amount received to the stream of installments — come from this calculation and are solved numerically.

CET: P − fees = Σt=1..n PMT / (1 + CETm)t

The buyer compares the offers side by side and chooses. Clave shows what each bank sent, withdraws the submissions that were not chosen and, if the property appraisal comes in lower, offers to go back to another bank.

The values shown are fictional, as in the rest of the example.

Check the bank’s math interactive
calculated installment
total paid
CET p.a.
validation
PMT = P · i / (1 − (1+i)−n)  ·  i = (1 + rate)1/12 − 1  ·  P − fees = Σ PMT/(1+CETm)t  ·  fictional conditions
Bank Aanswer in PDFBank Banswer by emailBank Canswer in the portalnormalized fieldsamount financedterm (months)rate p.a.installmentCET p.a.total paidConditions appear as each bank sent them.Clave does not recommend a bank.PMT = P · i / (1 − (1 + i)^(−n))stated R$ 5,690 · calculated R$ 5,684 · Δ 0.1%✓ within tolerance → show to the buyerstated R$ 5,980 · calculated R$ 5,684 · Δ 5.2%✗ diverges → Ops classifies before showingtolerance of 0.5% (illustrative)■ interest■ amortizationmonthsconstant installment: the interest part falls and the amortization part risesBankInstallmentCET p.a.Total paidBank AR$ 5,68412.1%R$ 2.05 MBank BR$ 5,79012.4%R$ 2.08 MBank CR$ 5,61012.0%R$ 2.02 Mfictional values · the buyer choosesClave withdraws the other submissionstotal paid = installment × n + costsCET: rate that equates the net amount to the stream of installments
Chapter 7

From contract to keys

Inspection, signing, ITBI, registry office: a dependency graph in which the longest path defines the deadline.

Once the bank is chosen, the Contract stage begins: inspection, signing through the bank’s link, ITBI (the property transfer tax), registry office requirements, registration and handing over the keys. Almost none of this happens inside Clave — the bank decides in its own portal, the registry office has its own pace.

Each step is a state in a state machine, with dependencies: signing only comes after the inspection, and registration only after the ITBI and the requirements. Every state change emits an event, and the event is what notifies each actor.

The stage’s deadline is the critical path: the longest path in the graph. Knowing which branch is on the critical path says where to spend attention — delaying the ITBI within its slack does not change the keys date; delaying the registry office does.

EF(t) = dt + maxu ∈ pred(t) EF(u)

What Clave does off screen is turn each registry office requirement into a task with an owner and a deadline, chase the bank visibly and leave the right message ready, in each place, for whoever needs to act.

What is the critical path? interactive
deadline to the keys
slack of the parallel branch
critical branch
EF(t) = dt + maxu ∈ pred(t) EF(u)  ·  signing 3 d · keys 2 d (fixed)
ProposalDocumentsBanksContractKeysnow · property inspectionOff screenthe bank decides in its own portalthe registry office has its own pacethe seller signs with their own linkthe keys are handed over in personClave controls none of this:it leaves something ready in each place.InspectionSigningITBIRequirementsRegistrationKeyseach step is a state; each change emits an eventInspectionSigningITBIRequirementsRegistrationKeys5 dEF 53 dEF 84 dEF 127 dEF 1510 dEF 252 dEF 27deadline = 27 days · the ITBI has 3 days of slackEF(t) = dₜ + max EF(predecessors of t)Registry office requirementtask: updated property certificateowner: sellerdeadline: 7 daysstate: open → with the registry office → resolvedchasing the bank is visible to whoever is waitingevery requirement becomes a task with an owner and a deadline
Chapter 8

Human in the loop

People decide what the model did not decide — and each decision becomes an example for the model to learn from.

Ops is a small team of analysts, each with up to 200 proposals. The desk shows only what the model and the assistant did not decide on their own. The analyst sees what the model read, picks one of five labels and confirms. No free text.

Each label does two things: it triggers the consequence — a request to the buyer, a stalled proposal — and becomes a training example, once validated. When there are more cases than people, the most uncertain come first.

u(x) = 1 − maxc P(c | x)  ·  H(x) = − Σc P(c|x) log P(c|x)

Above the threshold the model decides on its own — so how do we know it is still right? By sampling: Ops reviews a daily sample of the automatic decisions. Disagreement becomes a label, and the disagreement rate is the metric that has to fall.

n = ln(1 − C) / ln(1 − p)

Sample size to see, with confidence C, at least one error of rate p.

In the end, what matters is the economics of the operation: how many interventions per 100 proposals, how many false accepts, how much each completed contract costs. We measure by bank, by document type, by model version and by confidence band.

Design references, not measured results: the productivity gain still needs to be demonstrated.

Size the Ops desk interactive
analysts (up to 200 proposals each)
team occupancy
interventions per 100 proposals
Ops cost per proposal
analysts = ⌈N / 200⌉  ·  hours = N · 5 · (1 − STP) · t / 60  ·  occupancy = hours / (analysts · 140 h)  ·  5 documents per proposal (illustrative)
One card per uncertain documentbuyerAna S.documentpayslipmodel sawnet amount ?if confirmed→ checkedwaiting1 dayDocuments 12 · Proposals 4 · Conversations 2only what fell below the threshold reaches the deskempty desk = the model decided everythinglooks rightunreadableexpireddata does not matchother documentConsequencerequest to the buyeror stalled proposalTraining examplelabel → supervised datafree text trains nothing; a label doesu(x) = 1 − max P(c|x): the most uncertain firstautomatic decisions, above the thresholdcircle = day’s sample · red = disagreementn = ln(1 − C) / ln(1 − p)disagreement becomes a label; week by week, it should fallInterventions per 100 proposalshow much the desk still decidesFalse acceptsaccepted but should not have beenCost per contractOps + infrastructure ÷ contractsAudit disagreementshould fall week by weekcuts: bank · document type · model version · confidence band
Chapter 9

Event platform

Every state change emits an event. The event is what notifies each actor and what makes everything traceable.

Every state change of a proposal emits an event: document.sent, document.checked, proposal.documents_checked, consent.recorded, submission.created, submission.answered, key.delivered. No screen synchronizes another — it is the event that notifies broker, buyer, Ops and the real estate agency.

The heart of the system is a durable workflow engine, not the language model. It stores the proposal’s state, controls what can happen and resumes from where it stopped when an external service fails. Agents are specialized workers, with their own tools and limits.

Around it, layers: experience, agents, workflow, intelligence, integration, trust and data. The rule of who sees what — the broker and the agency never see the content of documents, the full CPF or the offers — lives in code, not on a screen.

A proposal’s state is a function of its events: replaying the history rebuilds any moment. That is what gives end-to-end traceability — and allows auditing and learning later.

st = δ(st−1, et)
Replay the events interactive
stage
documents checked
banks that answered
events applied
state(p, n) = fold(δ, s₀, [e₁ … eₙ])  ·  the same history always generates the same state
document.sentdocument.checkedproposal.documents_checkedconsent.recordedsubmission.createdsubmission.answeredkey.deliveredDurable workflowstate · deadlines · resumptionDocumentsConversationBanksContractsthe language model is a worker, not the heartExperienceWhatsApp · web · Ops deskAgentsown tools and limitsWorkflowtransitions, deadlines, durable tasksIntelligencedocuments, extraction, classificationIntegrationCRM, identity, banksTrust and dataevents, permissions, auditwho sees what lives in code, not on a screens₀e₁s₁e₂s₂e₃s₃e₄s₄sₜ = δ(sₜ₋₁, eₜ)state(proposal) = fold of the proposal’s eventsreplaying the events rebuilds any momentaudit = rereading the history

A lot is going on

To recap the path of a proposal: it enters through one of three doors and has its identity resolved; the assistant converses and calls a person when needed; documents become data and only the uncertain ones reach the Ops desk; the proposal goes on in parallel to three banks, duplicating nothing; the offers come back as checked numbers; the contract moves through a dependency graph to the keys — and every step becomes an event that can be replayed and audited.

This work is divided into four teams, three aligned to a part of the flow and one cutting across all of them.

  • Entry and Conversation AlgorithmsEntity resolution, identity, assistant and intent routing. They decide who the person is and what they need.
  • Documents and Decision AlgorithmsDocument reading, calibration, cost-sensitive thresholds and auditing. They decide what the model resolves and what goes to a person.
  • Banks and Contracts AlgorithmsQueues, retries, financial mathematics and state machines. They decide how the proposal moves to the keys.
  • Events and Trust PlatformEvents, durable workflow, permissions and auditing. They carry no business logic: they build the foundation so the other three can work end to end.

The question that runs through all of this is always the same: between what a machine does well and what a person does better, where is the line — and how do we measure whether it is in the right place? The answer that does not change: AI executes and coordinates, people supervise the exceptions, and the banks decide the credit.