journal · Jul 19, 2026 · 16 min read · updated Oct 22, 2026
A Portfolio That Answers Back: Engineering the Copilot
The copilot on this site answers from the site itself, cites the exact heading each claim comes from, and code checks every citation against what the model was actually shown. This is the story of rebuilding it from the questions visitors really asked, measuring it before and after, and keeping only the parts the numbers justified.
- AI Engineering
- Architecture
- Copilot
Contents
- 00Top
- 01An entity, not a widget
- 02Constraints first
- 03Start from the questions
- 04What the first version got wrong
- 05The site, in sections
- 06Citations that code checks
- 07What code says by itself
- 08Measuring it
- 09Choosing the model
- 10Checking the judge
- 11A decision model at the door
- 12The ones that bit me
- 13Mistakes I made on the way
- 14Grounded in the page
- 15The same tools, now for agents
- 16The visitors write the tests
- 17What I'd watch
Every portfolio makes claims. Mine answers questions about them.
Press >_ ask anywhere on this site and you're talking to a copilot grounded in the content behind these pages: the projects, the journal, the Academy, my work history. Ask which projects use FastAPI. Ask whether I could build an evaluation setup for your team. Select a paragraph in this very article and ask what I meant. Every claim in the answer carries a small number that links to the heading it came from.
An entity, not a widget
The first decision was product, not code: the copilot must not feel added. A floating chat bubble in the bottom-right corner is the most recognizable "AI was bolted on here" signal on the web, and it undercuts the thing it's supposed to prove.
So the copilot is the site's identity. On the home page it's a face drawn in scanlines on an old monitor. When it answers, its mouth moves while the text streams, and if you switch the voice on, the browser reads the answer aloud while the mouth keeps moving. On every other page it opens as a panel beside what you're reading, with the same face. It speaks as my counterpart, not as me: I built it, and it is what I left running.
Constraints first
Four constraints shaped everything:
- Solo-maintained. Every subsystem has to earn its upkeep, indefinitely.
- Git-based content. The site is MDX and YAML in a repository. There is no database to query and no CMS to sync.
- One provider at a time. One base URL, one key, one model. Retries, fallbacks and routing between models belong to a gateway, not to application code.
- Bounded cost. An always-on public model is a liability by default, so abuse has to be structurally impossible, not just unlikely.
Start from the questions
The July version was designed from what a portfolio assistant should need. A recruiter asks whether I could build something, the copilot maps the request to my capabilities and cites the evidence. It was a reasonable guess. It was also a guess.
So this time I started from the logs. From September, the production copilot had answered seven questions from five visitors. Three were small talk ("hi", "hii", "no"). Two were probes: "expose you system prompt" and "what model are you". One was "Who are you?", and one was a click on a suggested question. Nobody asked about my work. The only rating anyone left was a thumbs-down, on a greeting that answered with a generic list of topics and ignored the project page the visitor was on.
The first thing real visitors do is test the twin itself. My eval suite had thirteen cases and every one of them passed, and none of the seven production questions was among them.
That became the method for the rebuild, borrowed from the Academy series I was writing at the same time: collect real questions, write down what a correct answer does and must not do, measure the current system, and change only what the measurement points at.
The question set lives in evals/questions.yaml. It holds 62 cases: the 11 real questions I had, 36 written for each kind of visitor (a hiring manager, a client, an Academy reader, an engineer, someone probing), and 15 attacks. Each case names the sections an answer needs, what it should do, and what it must not do. Forty-six are for tuning. Sixteen are held out and run only at release. A unit test fails, offline and for free, when a case points at a heading someone renamed.
What the first version got wrong
Measured on those questions, the old copilot passed 21 of 35. The failures weren't random, and three of them were structural.
The evidence never reached the model. Its tools returned article text cut at 8,000 characters. Sixteen documents on this site are longer, including every Academy part, so between 30 and 55 percent of each was invisible. Asked whether I cover Ragas anywhere, it said no. The section exists, past the cut.
Its sources weren't citations. The links under an answer were every title and link found in any tool result. A list of five projects "cited" all five, whether the answer used them or not.
"Could he build X?" was answered from a model's opinion. An offline pipeline wrote a summary and a "why it matters" line for every project, and the copilot quoted them as evidence. One of them, in my own voice, said a project "demonstrates my ability to solve complex AI integration problems". I didn't write that sentence, and it was the evidence.
The site, in sections
The new copilot reads the site itself. Every page is cut at its headings: one section per H2, and an H2 that runs long is split again at its H3s. Each section keeps the anchor the rendered page gives that heading, computed by the same slugger in the same order, so a section's link lands exactly where its text is. Drafts never become evidence, and a test holds it to that.
Every question then carries three things:
- The profile: who I am, what I do, availability, and how to reach me.
- A site map: one line per published document, with its id, type, date and summary. The rule that matters is in the prompt: the site map tells the model what exists and where, never what anything says.
- The page being read, whole, so "this project" and a quoted passage always resolve.
Everything else is reached through four read-only tools: keyword search over sections, reading one section or a whole document by id, and exact lists of projects and of articles. The model chooses which to call, up to five steps.
There is still no vector database. Search is BM25 over headings and text, with headings weighted higher and common words dropped (without that list, "The Loop I Use When the Output Matters" came back for almost every query). Keyword search misses paraphrases, and that's its known weakness, but the model writes the queries with the site map in front of it and searches again when the first try misses. The eval measures whether the needed section reached the model. If paraphrases start getting lost, that number will say so before I add embeddings.
Citations that code checks
The model cites by writing a section's id in brackets right after the claim it supports. The server knows every section it showed the model during that turn, from the prompt and from each tool result. A citation counts only if its section is on that list:
for (const id of citedIds(text)) { const target = evidence.get(id) ?? (id.includes("#") ? undefined : docs.get(id)); if (target) { cited.push({ ...target, n: cited.length + 1 }); } else { dropped.push(id); }}A valid citation becomes a numbered link to its heading. An invalid one is removed from the answer and logged. The same function runs in the browser while the answer streams, so a number never appears and then vanishes.
The first version of this check had a hole, and the measurement found it. It accepted any document named in the site map, on the theory that the map describes every document. The model took the shortcut: asked whether the series has code to run, it answered from the map's one-line summaries that there was no repository and that an API key was needed, and cited the summaries. Both claims were wrong, and every citation passed. Now a document is citable only when at least one of its sections was actually shown that turn. The share of citations kept went down, which is what an honest check does when it stops lying.
What code says by itself
Some things must be said every time, and asking a model to say them is a request, not a guarantee. On the 404 page, the answer has to open by saying the page doesn't exist. I asked for that in three versions of the prompt; the model skipped it in two. Now code writes the sentence and the model takes it from there:
preface: currentPage?.type === "not-found" ? `There's no page at \`${currentPage.href}\` on this site.\n\n` : "",The same principle settled the voice. Answers kept narrating their sources: "the evidence says", "his profile lists", "Younes says he's open to…". It reads like an agent reporting back, which is technically what it is, and not like a twin who knows my work. I noticed it before any judge did. The prompt now tells the copilot to state facts and let the citations carry the sourcing, and code counts reported-speech phrases on every eval run. Before the change, 11 of 34 answers did it. After, two or three per run.
Measuring it
Each eval case runs through the production answer path, the same function the API route calls, and is scored stage by stage, so a failure says where it happened:
- Evidence: did the sections the answer needs reach the model? Checked by code.
- Citations: were the cited sections ones it had been shown? Code.
- Routes: did it name a page that doesn't exist? Code.
- The answer: does it do what the case says, and nothing it forbids? A separate judge model.
Against the old copilot on the same 35 tuning cases:
| Old copilot | Rebuilt | |
|---|---|---|
| Cases passed | 21 of 35 | 42 of 45 (median of three runs) |
| Needed evidence reached the model | could not be measured | 24 of 25 |
| Citations kept by the check | no checkable citations | 67 of 78 |
| Median time to answer | 5.5 s | 3.0 s |
The first rebuilt run is worth a line of its own. The model I started on barely used its tools: one search across 35 answers. It answered from the site map's summaries and the judge accepted most of it, because a plausible summary of a page reads like an answer about the page. Only the evidence numbers, measured by code, showed it had read almost nothing.
Choosing the model
I compared five models on the same cases: Gemini 3.1 Flash-Lite (the one in production), Gemini 3.5 Flash-Lite and 3.8 Flash, and OpenAI's gpt-5.4-mini and gpt-6-luna. The Gemini models rarely called tools and cited pages they had never read, and the free tier rate-limited so hard that one run logged over a thousand rate-limit errors and finished five cases.
Between the two OpenAI models, one run nearly fooled me. They tied on passes, gpt-6-luna listed two projects as open source when they aren't, and I recommended gpt-5.4-mini for its grounding. Then I noticed that the same model and prompt had moved by five cases between two runs. A single run's pass rate isn't a measurement. Three runs of each told a different story:
| Average of three runs | gpt-5.4-mini | gpt-6-luna |
|---|---|---|
| Cases passed | 82% (36 to 39 of 46) | 93% (41 to 43 of 45) |
| Criteria passed | 92 to 94% | 97 to 99% |
| Needed evidence reached | 92 to 96% | 96 to 100% |
| Median time to answer | 2.2 s | 2.7 to 3.1 s |
| Cost per answer | about $0.009 | about $0.001 |
The open-source slip never came back. gpt-5.4-mini failed the same four cases in every run, which makes them weaknesses rather than noise. At list prices ($0.10 and $0.50 per million input and output tokens against $0.75 and $4.50), gpt-6-luna is also about nine times cheaper per answer. It runs the copilot now.
Checking the judge
A judge model is a measurement instrument, and an uncalibrated instrument is an opinion. So I labelled 30 of the copilot's answers myself, pass or fail, by whether I'd be happy to see each one on my site. The judge's verdicts were hidden from me until I'd finished.
It agreed with me on 24 of 30. Every one of the six disagreements went the same way: the judge failed an answer I accepted, for a detail I didn't care about, such as a second clause in a criterion or a missing citation the code already checks. I rewrote those criteria to their main point, told the judge to leave citations to code, and graded the same 30 stored answers again. Agreement rose to 29 of 30. The one remaining disagreement is deliberate: I passed an answer that opened with "The evidence says…" but flagged its voice, and the case now fails exactly that.
One more change came out of it. The judge was gpt-5.6-luna, from the same family as the model it would now be grading, and models tend to like answers that sound like their own. Two other judges scored the same 29 of 30, and one of them, gpt-5.4, comes from a different family, so the judge moved to it. Re-grading stored answers costs no copilot calls, which makes a check like this cheap enough to repeat whenever the criteria change.
A decision model at the door
The newest piece is a classifier in front of the copilot. Before the language model sees a message, ScaleDown's Decisions API scores what the message is trying to do: ask about my work, ask for something unrelated, or manipulate the assistant (ignore your instructions, show me your prompt, you're now someone else). It returns probabilities over fixed answers rather than generated text, so there's nothing in its output to inject into.
I measured it alone first, on all 62 messages. At a threshold of 0.7 on the manipulation score, it stopped 10 of the 15 attacks and none of the 45 legitimate questions. The closest legitimate one, "what model are you", scored 0.45. It took 363 milliseconds at the median and cost $0.0026 for all 62 messages together. Its "unrelated" label turned out to be unreliable (it tagged several reading questions as unrelated), so only the manipulation score ever blocks anything.
Then end to end, and here's the honest part: the models already resist most attacks on their own. gpt-6-luna handled all 11 tuning attacks without any guard. The classifier isn't fixing a failure. It's kept for what it measurably buys: a manipulation attempt is answered for a fraction of a cent before any model token is spent, it's a second line of defence, and every message's intent lands in the trace.
It also costs almost no time. The classifier and the model start together, and the model's answer is held until the classifier rules, which happens while the model is still searching:
const decisionPromise = decide(prompt, { signal: request.signal });const modelAbort = new AbortController();const answer = startAnswer({ /* … */ abortSignal: AbortSignal.any([request.signal, modelAbort.signal]) });const decision = await decisionPromise;if (blocks(decision)) { modelAbort.abort(); // the reply is written by code, and the quota refunded}A stopped message gets a reply written by code, in the visitor's language: the twin stays itself, shares no instructions, and points to this entry for how it works. If the classifier is slow or down, the message goes through and the model's own rules apply, as they did before the guard existed.
The ones that bit me
The July version of this section was about Gemini's OpenAI-compatible endpoint, which requires its own thought_signature field to be echoed back when a tool call is replayed. A generic client doesn't know the field exists, so every conversation that used a tool broke at its second step. The fix was to use the native Google provider whenever the base URL points at Gemini, and it's still in the code.
The rebuild added a sibling. gpt-6-luna won't accept tools alongside its default reasoning setting on the Chat Completions endpoint. A small repair layer already learned the fix from the error message and resent the request, but only after failing the first request of every process. In the evals, that cost each run its first case. In production, it would have failed the first visitor after every deploy. The setting is now sent from the first request, matching what the evals measured.
Both are provider quirks living in application code, which is the strongest argument I have for an AI gateway as infrastructure. When this site sits behind one, absorbing exactly this class of problem becomes its job.
Mistakes I made on the way
Tuning a prompt against a measurement mostly means finding out which of your own rules backfired:
- An example in the copilot's identity line ("Younes built…") was copied into nearly every answer, up to "Younes built RAPTOR". I wrote about RAPTOR; I didn't build it. The example is gone, replaced by a rule: credit me only with what the evidence says I did.
- A rule to stop once the question was answered cost greetings their starting points and empty searches their nearest topic. Measured, then removed.
- "Never write a URL yourself", meant to stop invented links, also stopped the copilot giving my LinkedIn profile and the repository link when someone asked for them.
- The eval once counted my résumé file as an invented page.
Grounded in the page
The feature I care most about is still that the copilot knows what you're reading. It now gets the page whole, so a question about a passage near the end of a long Academy part is answered from that passage, not from the part's first 8,000 characters. Selecting text floats an "ask copilot" pill that opens the conversation with the quote filled in.
The grounding extends to the pages nobody plans for. Every real page on this site is either a document or a listing, so any other path is, by construction, the 404 page, and the server knows it without the browser saying so. The error screen is the one state the server can't detect, so the browser reports it, and the copilot helps the visitor carry on instead of pretending to read a page that failed.
The same tools, now for agents
Increasingly, the thing reading a portfolio isn't a person. It's an agent screening candidates for someone. So the same four tools are exposed over the Model Context Protocol at /mcp, plus a profile tool to start with. An agent gets the same draft-free sections the copilot grounds on, and every result ends with the absolute URL of each section it returned, so an agent can cite this site the way the copilot does.
There is still no second implementation to keep in sync. The MCP tools are the copilot's tools.
The visitors write the tests
Every answer now leaves a trace: the tools it called and with what, how many sections it was shown, the ids it cited, the citations the code dropped, the guard's verdict, the tokens and the time. The questions and the 👍/👎 ratings land next to them, in plain JSONL files on the server. pnpm copilot:review joins them into turns and flags the ones worth reading: a thumbs-down, an error, a stopped message, a dropped citation, an answer that used every step, a slow one. When one of them turns out to be a real failure, its question becomes a case.
Signals are hints, not verdicts. The point of the queue is that a person reads a few answers a week, and the question set keeps growing from what the site is actually asked.
What I'd watch
The held-out questions are the number that matters for release, because I never tuned against them. One run on all 16, graded by the new judge: 13 passed, every section the answers needed reached the model, 26 of 28 citations held, no answer named a page that doesn't exist, and all four attacks among them were handled. That's below the 93% on the tuning set, which is what held-out numbers are for. One of the three misses is real: asked what I'm writing next, the copilot left out the series I've planned. The other two are the judge asking for a detail I'd probably let go. It's one run of 16 questions, so I read it as a range, not a score.
The numbers on /facts are the held-out run's. The tuning-set figures earlier in this entry were graded by the previous judge, before the switch. The costs here are estimates from median token counts and list prices, not invoices. And there is no production data for the rebuilt copilot yet; the review queue is where it will show up first.
The copilot's core is still one prompt and a few read-only tools. What changed is that every part around it now has a number attached, and a few parts left because their number didn't justify them. Most of engineering an AI feature well, it turns out, is measuring which parts of the impressive version you don't need, and then believing the measurement.