Agents from scratch · Chapter 18 of 18
Interview round
By the end of this chapter you have answered five timed questions, one idea each, from across the whole lab: spotting a repeated call, rebuilding streamed tool calls from the raw wire, validating arguments so a model can correct itself, resuming a paused run, and explaining a trace. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Production
- 5 tasks
- Python
- In the all labs plan
The first 2 chapters of Agents from scratch are free. This one comes with the all labs plan.
Why you need this
Vikram will not hand the booking agent to anyone who has only read about it. "Short problems, ten minutes each. I am not checking that you remember the openai package. I am checking that you know what the loop does at every step, and that you look at what really went over the wire before you guess." Anjali wants GharFix's next AI engineer interviewed the same way, so the round is now part of the lab.
Each question is one idea from an earlier chapter, with no hand-holding: the file has the goal, the check has the edge cases. The ideas are below, as a refresher and as what an interviewer listens for. The answers are not.
What you build: 5 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1 · interview question
Interview: repeat_guard.py, a repeat guard
Time yourself: 10 minutes. Write a class RepeatGuard whose seen(name, arguments) returns True when this run already saw the same call, and otherwise remembers it and returns False. arguments is the model's JSON text: other spacing or another key order is the same call; text that is not JSON is compared as it is.
Then run_agent(question, model="lab-chat"): the loop with a system message saying today is 2026-10-22, the question and GharFix's tools, at most 8 requests. When a reply asks for a call already seen, run nothing from it, send the conversation once more with tool_choice none, and return that answer; otherwise return the final answer.
The check tries seen on many spellings, and runs lab-chat-loopy and a booking with no slot.
- Task 2 · interview question
Interview: sse_calls.py, tool calls from the wire
Time yourself: 10 minutes. Write calls_from_sse(lines): lines are the raw lines of a streamed reply (server-sent events, read without the openai package): data lines holding one chunk of JSON each, blank lines, and data: [DONE] at the end. Return the reply's tool calls in the order of their index, each a dictionary with id, name and the whole arguments text; a reply with no calls gives an empty list.
The check reads lab-chat's stream, and another provider's that sends comment lines (starting with a colon), writes data: with no space after the colon, mixes two calls together and puts arguments in a call's first piece.
- Task 3 · interview question
Interview: validate_retry.py, validate, and let it retry
Time yourself: 10 minutes. Write validated_find(arguments): validate the model's JSON text for find_technicians with a Pydantic model (service one of plumbing, electrical, carpentry or ac; area text; date written YYYY-MM-DD and slot morning, afternoon or evening, both optional; no other keys). When valid, run gharfix.find_technicians and return its result as JSON text; otherwise run nothing and return JSON text of an object with an error key naming every field that failed.
Then run(question): the loop with lab-chat-confused, a system message saying today is 2026-10-22, the question and GharFix's tools, at most 6 requests, every find_technicians call run through validated_find (other calls as they are, an error result when one cannot run). Return the final answer.
The check sends wrong arguments of five kinds, then a booking the confused model gets wrong on its first call.
- Task 4 · interview question
Interview: resume.py, resume a paused run
Time yourself: 10 minutes. A run paused before a dangerous call is saved as JSON: status waiting, messages (the conversation, ending with the assistant's message that asked for the call), pending (each call's id, name and arguments) and answer null. Write resume(path, approved): for a waiting run, give each pending call its tool message (approved: run it with GharFix's function and send the result; not approved: run nothing and send an error result), empty pending, and go on with lab-chat and GharFix's tools, at most 6 more requests, until the model answers. Save the run with status done and the answer, and return the answer. For a run that is not waiting, return its answer and ask the model nothing.
The check pauses a booking, resumes it once with yes and once with no, and then resumes each again.
- Task 5 · interview question
Interview: explain_trace.py, explain a trace
Time yourself: 10 minutes. Write diagnose(path, trace_id): read that trace's spans from a trace file (chapter 12's format) in the order of their span number. Going through the tool spans in order, return the first of: error at step <step>, <tool>: <error> for a span with an error; empty result at step <step>, <tool> for a result of 2 characters; repeat at step <step>, <tool> for the same tool with the same arguments as an earlier span (as JSON, in any spelling). If none, return no answer: stopped after <n> requests when the last model span did not finish with stop, and ok otherwise.
The check writes five traces into one file, one of them with its spans out of order, and a clean one.
What you will learn
- How to work a timed question: say the plan, build the smallest thing that runs, then measure it against the real API.
- Five ideas again, at interview depth: repeats (chapter 6), streamed calls (13), validation (7), paused runs (9 and 10) and traces (12).
More in Production
Build "Interview round" yourself
GharFix, a Bengaluru home-services company, needs an assistant that books, reschedules and refunds safely. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Agents from scratch are free. This one comes with the all labs plan.