Tom Xiao

Stage 4 · Agent engineer · AI agent case

AI portfolio assistant

I designed and built the whole assistant. It is live for real users of an investment app: they ask about their own assets in natural language, and it handles conversation, portfolio check-ups and memory.

RoleDesigned and built the assistant end to end
StatusLive in a financial platform
PrincipleNumbers never come from the model

One question, traced

This is what a single turn looks like. Each step opens to show what it did. Everything here is sample data.

portfolio-assistant · one turnsample data
You
How concentrated is my portfolio?
  1. # Decimal, no model involved
    hhi = sum(w*w for w in weights) * 10000
    → 2400
    tier = TIERS.lookup(hhi)
    → "moderate" (1,500 – 2,500)
    defensive = (bond_B + cash_E) / priceable
    → 36%
  2. HHI 2,400tier moderatetop weight 34%defensive 36%4/4 checked
Your portfolio is moderately concentrated (HHI 2,400). The largest holding, Equity fund A, is 34% of value, and defensive assets are 36%.
computed in code figures highlighted above come from the code, not the model
done · 4 steps

The bug that shaped the gate

Before launch, testing showed the defensive-asset share at 100%. The real figure was about 36%. The denominator was wrong: it counted only the assets that were already defensive. I fixed the denominator and added a gate.

Defensive share · sample

Animation: the denominator grows from defensive assets only to all priceable assets, and the share falls from 100% to 36%.

Before the fix · sample
100%

Defensive share = defensive / defensive. Always 100.

After the fix · sample
36%

Defensive share = defensive / all priceable assets.

The gate sample

If priceable assets cover less than 30% of the portfolio, the assistant gives no advice. Watch it run, then drag it yourself.

no advice givenToo little of the portfolio can be priced to say anything useful.

no advice given

Guarding what a model could get wrong

Identity from the session

The user is looked up from the session and never passed as a tool argument, so a prompt injection cannot read someone else's data.

# tool call, as the model sees it
get_snapshot(scope="holdings")
# user comes from session.user(), not args

When the model slips

Output is checked claim by claim. Memory is isolated per user and writes are idempotent.

Validate each claim in the answer
Fail: repair once
Fail again: fall back to a template

Fail again: fall back to a template

Who does what

The split is the product. Anything a user could check with a calculator is done by code.

Code computed in code

  • Valuation and weights, in Decimal
  • Concentration (HHI) and the diagnosis tier, found by table lookup
  • Freezing the data snapshot and saving a checkpoint, reused on retry
  • Checking every claim in the model's answer

Model explains

  • Reading the question and choosing the tools
  • Turning the computed numbers into plain language
  • Remembering what this user cares about
  • Nothing it says survives validation unless it matches the computed figures

The model explains. The code counts.

Next