What they’re really asking
If you only remember one thing, say this in the first minute: “I’ll start with the smallest chat loop that runs, then add one requirement at a time and run it after each: tools with checked arguments, a step cap, a hand-off to a human, and finally compaction, which shrinks old history when the conversation gets too long. I keep exact facts like order ids outside the summary, so compaction never loses what the next tool call needs.”
The rest of this page explains each part of that answer.
This is a live coding round: write a working agent chat loop quickly, and keep it correct as the interviewer adds requirements.
What makes this different from normal live coding
In a normal live-coding round your functions are deterministic. Here one function is a large language model (LLM), usually a stub the interviewer gives you, that takes the conversation and returns either text or a request to run a tool. Two things are new. The model keeps no memory between calls, so your code must keep the conversation and resend it every time. And the conversation keeps growing, so at some point it no longer fits in what the model can read. Handling that is the likely final requirement.
Words you need first
- Message list: the conversation so far, as a list of
{role, content}entries (user, assistant, tool). - Tool call: the model asks your code to run a function, such as
lookup_order(order_id), and you send the result back as a tool message. - Step cap: the maximum number of tool calls per user turn.
- Hand-off: passing the conversation to a human agent.
- Context window: the maximum amount of text, counted in tokens (pieces of words, about ¾ of a word each), that the model can read in one call.
- Compaction: replacing older turns with a short summary so the conversation fits again.
Where it was reported
One Sierra AI Engineer candidate on Aced lists “build an agent chatbot” and “Implement chatbot compaction logic” among the coding questions, and advises “explaining clearly and moving fast through first and second round” so there is time for the third Aced (formerly Exponent). A first-hand blog describes Sierra’s coding screen as a multi-part problem where each follow-up adds requirements to your code gaijineer.co. Expect the same growth here.
Clarify first
- Is there a real model, or a stub you call? Assume a function that takes messages and returns text or a tool call.
- Which tools exist and what do they return? Assume one or two lookups with typed arguments.
- How does the conversation end, and when should it hand off? Assume a hand-off tool and a step cap.
- Is there a context limit to handle? Assume yes; the compaction question is the likely follow-up.
Answer
Write the smallest loop first, then add one requirement at a time.
A picture of the loop
User message
│ append to message list
▼
Model(messages) ──► text? ──► append, show to user, wait for next message
│
└──────────────► tool call? ──► registry: known name? arguments valid?
│ yes → run it, append result as tool message
│ no → append the error as a tool message
│ step count +1; at cap → hand-off
└──► call Model again
Before each model call: token count > threshold? → compact old turns
The five versions
- Turn loop. Keep a message list. Append the user’s message, call the model, and if it returns text, append and show it. That is version one; run it.
- Tools. A registry mapping each name to a function and an argument schema (the expected names and types). If the model returns a tool call, check the name and arguments, run it, append the result (or the error as text) as a tool message, and call the model again. Cap tool steps per user turn, say five, and hand off when the cap is hit.
- Hand-off. A tool the model may call, and a rule your code applies on its own: repeated tool errors, the cap, or the user asking for a person.
- Compaction. When the token count of the history passes a threshold, replace the oldest turns with a summary. Keep the system prompt (the fixed instructions at the start), the latest turns, and any facts tools returned (order ids, amounts) word for word. Summaries lose details, so keep structured facts outside the summary.
- Robustness. Unreadable model output gets one retry with the error. Unknown tool names become an error message to the model, not a crash.
Narrate what you are about to test before each run. Keep functions small so each new requirement is a local change; that is what the multi-part format rewards. Say it like this: “Version two works. Next I’m adding the step cap, and I’ll test it with a stub that calls the same tool forever.”
Follow one conversation through compaction
An illustrative conversation with a customer whose order is late:
| Turn | What happens | What to say in the interview |
|---|---|---|
| 1 | ”Where’s my order 4417?” Model calls lookup_order("4417"); result: shipped, carrier delayed. | ”Tool result goes into the message list and into a facts dictionary.” |
| 2–9 | Back-and-forth about delivery options and the address. | — |
| 10 | History passes the token threshold. Turns 1–6 become a two-sentence summary. | ”Compaction runs before the model call, not after it fails.” |
| 11 | ”OK, then cancel it.” Model calls cancel_order("4417"). | ”The id came from the kept facts, not from the summary, so it’s exact.” |
The bug to avoid is in turn 11: if the summary had said “the customer’s order” instead of “4417”, the next tool call would have nothing to work with.
Senior vs Staff
Live agent chatbot
Senior
- A running loop with tools, a step cap, hand-off and compaction, each added and tested in turn.
Staff
- Also names what production adds (per-conversation traces, eval of hand-off decisions, which facts must survive compaction) and asks which failure the interviewer cares about most.
In plain words: Senior gets all five versions running and tested. Staff also says what production would add and asks which failure matters most to the interviewer.
Small-team version
A small team’s support or internal assistant is this loop. Write it in plain code against a managed API, keep tool permissions in code, and log every turn with tokens, so you can see when compaction kicks in and what it costs.
The cost grows faster than the number of turns, because every turn resends the history. With assumed numbers, a 10-turn conversation costs about 9 cents on Claude Sonnet 5 ($2 per 1M input, $10 per 1M output, list prices fetched 2026-10-11). So 1,000 conversations a day is about $2,800 per 30 days before prompt caching, which bills a reused opening part of the prompt at a tenth of the input price.
Default: plain code, one managed provider, caching on. Revisit compaction thresholds when long conversations dominate the bill.
The arithmetic behind the numbers (for a Staff-level follow-up)
- Assumed: a 2,000-token system prompt, 300 tokens added per turn, 200 output tokens per reply, 10 turns.
- Input: turn k sends 2,000 + 300 × k, so the total is 10 × 2,000 + 300 × 55 = 36,500 tokens; × $2 per million = $0.073.
- Output: 10 × 200 = 2,000 tokens × $10 per million = $0.020.
- Per conversation ≈ $0.093, about $0.09; × 1,000 a day × 30 days ≈ $2,800.
Pitfalls
- Writing everything at once. Running nothing for 30 minutes leaves you with no working version when time runs out.
- No step cap. A tool error then loops forever, and each loop costs money.
- Summarizing away the order id. The next tool call needs the exact value, which a summary may drop.
Go deeper
- Family walkthrough: Build an LLM app or agent take-home, then defend it.
- Related: the multi-part practical coding family for the growing-requirements format.
- Lab: Build Your Own Agent FrameworkPartial.