Build your own AI interviewer · Lesson 1 of 4 · 15 min
Build your coach: the interview loop
Part 1Basics
This path is our own pick. You'll build a small AI mock interviewer. You'll get a tool you really use, and it covers most of what AI rounds ask about: prompts, structure, validation, evals and cost. It also gives you a true story to tell, with real numbers.
Start with the part that has no AI in it. Left alone, a chatbot drifts: it teaches, it gives hints, it runs forever. A real interview has phases and a clock. So your code owns the phases, and the model only writes the words.
This is the most useful idea in applied AI: put what must be reliable in code, and use the model only for what needs language.
Words you need
- State machine
- A fixed set of states and allowed moves between them. Here: clarify, solve, probe, score, done.
- Pure function
- Output depends only on input, with no side effects. It's easy to test.
- Event
- Something that happened: the candidate spoke, the clock ticked, time ran out.
A worked example
Meera's first version is one long prompt: 'You're an interviewer, run a 45-minute round.' It gives the answer by the fourth message, and never asks to stop. Her second version is 40 lines of state machine. Now the model can't move to scoring early, and three probing questions is exactly three. And she can test it without paying for a single API call.
Part 2The question
How do you build an AI interviewer that behaves like an interviewer?
By the end of this lesson, you should be able to:
- Model a process as states and events
- Separate what must be reliable from what can vary
- Test an AI product without calling a model
Part 3In detail
Step by step
- List the phases. Clarify, solve, probe, score, done.
- List the events. Say, reply, advance, hint, tick.
- Write step(state, event). It returns new state and changes nothing else.
- Test it with a scripted interview. No model required, and it runs in milliseconds.
- Then connect a model. That's the next lesson.
The code, explained
This is real code, and our tests run it, including the buggy versions, to prove the bugs are real.
The interview as a state machine
Your code decides where the interview is. The model only writes the words.
1/** A pure function: old state plus event gives new state. The model never decides what phase it's in. */2export function step(s: Session, e: CoachEvent): Session {3 if (s.phase === "done") return s;4 const advance = (from: Session): Session => ({ ...from, phase: ORDER[ORDER.indexOf(from.phase) + 1] });5 switch (e.type) {6 case "say":7 return { ...s, turns: [...s.turns, { who: "candidate", text: e.text }] };8 case "reply": {9 const next = { ...s, turns: [...s.turns, { who: "interviewer" as const, text: e.text }] };10 if (s.phase !== "probe") return next;11 const probes = s.probes + 1;12 return probes >= MAX_PROBES ? advance({ ...next, probes }) : { ...next, probes };13 }14 case "hint":15 return s.phase === "solve" ? { ...s, hints: s.hints + 1 } : s;16 case "advance":17 return advance(s);18 case "tick": {19 const secondsLeft = Math.max(0, s.secondsLeft - e.seconds);20 // When time runs out, go straight to scoring, as a real interviewer would.21 return secondsLeft === 0 && ORDER.indexOf(s.phase) < ORDER.indexOf("score") ? { ...s, secondsLeft, phase: "score" } : { ...s, secondsLeft };22 }23 }24}export function step(s: Session, e: CoachEvent): Session- A pure function, so the tests can replay a full interview with no model at all.
probes >= MAX_PROBES- Ends the probing after three questions, rather than trusting the model to stop.
secondsLeft === 0- When time runs out, it moves to scoring, like a real interviewer.
s.phase === "solve" ? { ...s, hints: s.hints + 1 } : s- Hints only count while solving.
Tested by npm run test:modules.
What can go wrong
- Asking the model what phase it's in
- It'll forget, or be talked out of it. Keep it in code.
- No clock
- Without one, you never practise running out of time.
Part 4Questions and answers
Answer out loud first, then open each one.
Why not let the model manage the phases?
What does a pure step function give you?
Part 5Going further
Drill: Add a phase (20 min)
- Copy the state machine.
- Add a 'review' phase after solve, where the candidate must state complexity.
- Write a test that replays a full interview.
- Make sure the clock still jumps to scoring.
Keep the fundamentals fresh with the critical basics.
Next: connect a real model, and keep the answer key away from it.