Build your coach: the interview loop

How do you build an AI interviewer that behaves like an interviewer?

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.

  • 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.

Steps:

  1. List the phases. Clarify, solve, probe, score, done.
  2. List the events. Say, reply, advance, hint, tick.
  3. Write step(state, event). It returns new state and changes nothing else.
  4. Test it with a scripted interview. No model required, and it runs in milliseconds.
  5. Then connect a model. That's the next lesson.

Code, The interview as a state machine. Your code decides where the interview is. The model only writes the words.

/** A pure function: old state plus event gives new state. The model never decides what phase it's in. */
export function step(s: Session, e: CoachEvent): Session {
  if (s.phase === "done") return s;
  const advance = (from: Session): Session => ({ ...from, phase: ORDER[ORDER.indexOf(from.phase) + 1] });
  switch (e.type) {
    case "say":
      return { ...s, turns: [...s.turns, { who: "candidate", text: e.text }] };
    case "reply": {
      const next = { ...s, turns: [...s.turns, { who: "interviewer" as const, text: e.text }] };
      if (s.phase !== "probe") return next;
      const probes = s.probes + 1;
      return probes >= MAX_PROBES ? advance({ ...next, probes }) : { ...next, probes };
    }
    case "hint":
      return s.phase === "solve" ? { ...s, hints: s.hints + 1 } : s;
    case "advance":
      return advance(s);
    case "tick": {
      const secondsLeft = Math.max(0, s.secondsLeft - e.seconds);
      // When time runs out, go straight to scoring, as a real interviewer would.
      return secondsLeft === 0 && ORDER.indexOf(s.phase) < ORDER.indexOf("score") ? { ...s, secondsLeft, phase: "score" } : { ...s, secondsLeft };
    }
  }
}
  • 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.

  • Failure, Asking the model what phase it's in: It'll forget, or be talked out of it. Keep it in code.

  • Failure, No clock: Without one, you never practise running out of time.

Why not let the model manage the phases?
Models drift, and they can be persuaded. Phases must be reliable, so plain code should own them, and that also makes them testable.
What does a pure step function give you?
You can replay any interview as a list of events, test it without a model, and debug it by looking at state.