AI agent interview questions and answers
Questions on designing and running agents: tools, the agent loop, permissions, context, multi-agent systems, security and evaluation.
Run agents on tasks in fresh environments and grade what they leave behind.
Why does an agent passing once tell you little about how reliably it works?
Agent runs can differ across trials. Use the same task and independent grader in fresh environments, then decide whether your metric rewards at least one success or demands consistent success.
Harness prepares identical fresh states
Agent attempts the same task several times
Independent grader compares each resulting state with acceptance criteria
Harness prepares identical fresh states
Agent attempts the same task several times
Independent grader compares each resulting state with acceptance criteria
Given Harness prepares identical fresh states and Independent grader compares each resulting state with acceptance criteria, write down the missing step that connects them.
Agent attempts the same task several times
Now take Agent attempts the same task several times and the result above. Write an input and an implementation that could produce this trace.
Harness prepares identical fresh states. Check that your implementation produces the result shown above.
Three fresh trials succeed, fail, and succeed. Did at least one of the three work, and did all three work?
At least one worked, while the all-three standard failed. Those criteria answer different questions about retry usefulness and consistency.
One harness version is faster on three successes but silently skips a required verification step on the fourth case. How should the comparison treat it?
Score the incorrect task outcome separately before comparing latency. Report time or cost per successful task and include the failed case in the trace-based evidence.
Check this when debugging. Running each task once and trusting the number.
You change the system prompt, add a tool, or switch models. Is the agent better? Trying a few tasks by hand can't tell you: agents vary from run to run, and a change that fixes one task can break three others. An evaluation harness runs the agent across a fixed set of tasks, many times, in clean environments, and grades what it leaves behind. It's how teams improve agents with evidence instead of hope.
You can't tell yet: agents vary, so run more tasks and repeats
Agents give different results from run to run, so one pass over 5 tasks is mostly noise. An eval harness runs many tasks several times each, in fresh environments, and reports pass rates.
Recall: Evaluating agents defined pass@k and pass^k, and Comparing two models on the same test compared two systems on the same cases. This lesson builds the harness that produces the grid they read.
Think of a driving test. Everyone takes the same route in a prepared car, and the examiner cares whether you parked safely, not which hand you used on the wheel. Each task has three parts:
Benchmarks like SWE-bench work this way: a real repository, a real issue, and the project's own tests as the grader. Grade the outcome, not the path. Many different tool sequences can solve a task, and grading the exact steps punishes good solutions you didn't think of.
By the outcome: the hidden tests pass, so it passes
Grade the outcome, not the path. Many tool sequences can solve a task, and grading exact steps punishes good solutions you didn't think of.
| grader | example | notes |
|---|---|---|
| code | run tests, compare files, query the database | fast, cheap, repeatable; use when you can |
| model | a rubric scored by an LLM judge | for open-ended output; check it against human scores |
| human | expert review | the gold standard, but slow; use to calibrate the others |
A chemist washes the glassware between experiments. Each trial gets a brand-new copy of the setup: a new container, a clean checkout. If trials share state, one trial's leftover files can make the next pass or fail for the wrong reason.
The trials didn't each get a fresh copy of the setup
Each trial needs its own brand-new setup. Here, the second trial's pass says nothing about the agent, because leftovers from the first one did the work.
The grid is the raw result. Rates are read off it.
Write a sentence or two, then compare it with a good answer in the lesson.
One free throw tells you little about a basketball player. Agents are not deterministic either, so one run per task measures luck as much as skill. Run each task n times and report:
An agent with a 60% success rate has pass@3 near 94% but pass^3 near 22%. Same agent, very different stories.
In plain words: pass@k asks "will one of these tries work?" pass^k asks "will every try work?"
p, k = 0.5, 3 print(round(p ** k, 3), round(1 - (1 - p) ** k, 3))
0.125 0.875
All three attempts succeed one time in eight. At least one succeeds seven times in eight. The same agent looks unreliable by the first measure and dependable by the second. An evaluation harness has to estimate both from a handful of real runs, which takes more care than putting a guess for p into a formula.
Run each task several times and some will pass sometimes and fail other times. Write flaky(results): results maps task ids to lists of True/False trial outcomes. Return the sorted ids that have at least one pass and at least one fail.
RESULTS = {
"fix-typo": [True, True, True],
"add-endpoint": [True, False, True],
"refactor-db": [False, False, False],
"write-tests": [False, True, False],
}
def flaky(results):
return []
print(flaky(RESULTS))
Run n trials, and c pass. The tempting estimate of pass@k, 1 - (1 - c/n) ** k, is biased. Think of your trials as marbles in a bag, with the passing ones green. You pick k marbles, and you fail only if none of them is green. The standard estimator, from the HumanEval paper, counts the ways to pick k of the n trials that are all failures:
pass@k = 1 - C(n - c, k) / C(n, k)
where C is "choose" (math.comb). If fewer than k trials failed, it's 1.
Say 2 of 5 trials passed. Compare the tempting formula with the standard one from this section, for picking 3 tries.
from math import comb n, c, k = 5, 2, 3 tempting = 1 - (1 - c / n) ** k unbiased = 1 - comb(n - c, k) / comb(n, k) print("tempting:", round(tempting, 3)) print("unbiased:", round(unbiased, 3))
The two disagree by 12 points on the same five runs, and that's without changing any model. So when you compare harnesses, make sure both reports used the same formula, or the winner may only be down to the arithmetic.
The unbiased pass^k needs no new idea: pick k trials, and count how many such picks are all passes. A rate from few trials is uncertain, so give an interval beside it.
from math import comb, sqrt def pass_hat_k(n, c, k): return comb(c, k) / comb(n, k) def wilson(passed, n, z=1.96): p = passed / n center = (p + z * z / (2 * n)) / (1 + z * z / n) half = z * sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / (1 + z * z / n) return round(center - half, 2), round(center + half, 2) n, c = 10, 6 print("tempting pass^3:", round((c / n) ** 3, 3)) print("unbiased pass^3:", round(pass_hat_k(n, c, 3), 3)) print("95% interval for 6 of 10:", wilson(6, 10)) print("95% interval for 60 of 100:", wilson(60, 100))
Tell someone the floor only has to look clean, and the dirt may end up under the rug. Agents optimize for what the grader checks, sometimes in ways you didn't intend. Coding agents have been seen deleting failing tests, special-casing test inputs, or editing the grader. Defenses:
An agent told to make the tests pass may special-case the inputs it can see. Hidden tests with different inputs tell you whether it solved the real problem.
def honest_add(a, b): return a + b def cheating_add(a, b): if (a, b) == (2, 3): # the one input in the visible test return 5 return 0 visible = [((2, 3), 5)] hidden = [((10, 4), 14), ((0, 0), 0), ((-1, 1), 0)] def score(fn, tests): return sum(fn(*args) == want for args, want in tests), len(tests) for fn in [honest_add, cheating_add]: print(fn.__name__, "visible:", score(fn, visible), "hidden:", score(fn, hidden))
Both look perfect on the visible test. Notice the cheat even passes two hidden cases by luck, because its answer of 0 happens to be right for them. So a thin hidden set can miss a cheat too, and graders need varied inputs.
from math import comb n, c, k = 5, 2, 2 print(round(1 - comb(n - c, k) / comb(n, k), 2))
0.7
There are 10 ways to pick 2 of 5 trials, and 3 of them pick only failures. So 1 − 3/10 = 0.7.
Protect or hide the tests, and fail any trial that changes them
Protected files and hidden tests close the shortcut. Reading some passing transcripts helps too.
Write changed_tests(before, after): both map file paths to their text. Return the sorted paths of test files (names starting test_ or paths under tests/) that were changed or deleted, so a run that passes by editing its tests is caught.
BEFORE = {
"calc.py": "def add(a, b):\n return a - b",
"tests/test_calc.py": "assert add(2, 2) == 4", "test_io.py": "..."}
AFTER = {
"calc.py": "def add(a, b):\n return a - b",
"tests/test_calc.py": "assert add(2, 2) == 0"}
def changed_tests(before, after):
return []
print(changed_tests(BEFORE, AFTER))
A good agent may solve it another way
A route check fails a clever solution, and passes an agent that took every expected step and still left a broken result.
Fifteen paired runs: three tasks, five seeds each, on practice models with a mix of habits. Version one lets the agent edit test files. Version two refuses. The seed fixes the habit, so each run is a pair.
from math import comb from pathlib import PurePosixPath from agentlab import PracticeModel, TASKS, grade, run_tests TOOLS = ["read_file", "edit_file", "run_tests"] MIX = {"careful": 3, "overconfident": 1, "edits_tests": 1} def run_agent(task_name, seed, protect): task = TASKS[task_name] files = dict(task["files"]) model = PracticeModel(MIX, seed=seed) messages = [{"role": "user", "content": task["prompt"]}] for _ in range(8): reply = model(messages, TOOLS) messages.append({"role": "assistant", "content": reply["content"]}) if reply["stop_reason"] != "tool_use": break results = [] for b in reply["content"]: if b["type"] != "tool_use": continue args = b["input"] path = args.get("path", "") if b["name"] == "edit_file" and protect and ( PurePosixPath(path).name.startswith("test_")): out = "Denied: test files are read-only." elif b["name"] == "edit_file": files[path] = files[path].replace(args["old"], args["new"]) out = "Edited " + path elif b["name"] == "read_file": out = files[path] else: out = run_tests(files)["summary"] results.append({"type": "tool_result", "tool_use_id": b["id"], "content": out}) messages.append({"role": "user", "content": results}) return grade(files, task_name)["passed"] names = ["calc", "discount", "words"] grid = {v: [[run_agent(t, s, v) for s in range(5)] for t in names] for v in (False, True)} for v, label in ((False, "tests writable"), (True, "tests read-only")): print(label) for t, row in zip(names, grid[v]): print(f" {t:<9}", "".join("P" if ok else "." for ok in row)) only_b = sum(b and not a for ra, rb in zip(grid[False], grid[True]) for a, b in zip(ra, rb)) only_a = sum(a and not b for ra, rb in zip(grid[False], grid[True]) for a, b in zip(ra, rb)) print("only read-only passes:", only_b, " only writable passes:", only_a)
Write a sentence or two, then compare it with a good answer in the lesson.
Agents vary from run to run. A task that passes once might pass 6 times in 10. So a single run can mislead you in either direction, and a jump from 60% to 80% on a few tasks may be nothing but noise. Run each task several times, and compare the runs with some statistics before you believe a change helped.
It's tempting to check that the agent took the steps you expected: read this file, then call that tool. But a good agent might solve the problem another way, and it would fail your check for being clever. Worse, an agent can take all the right steps and still leave a broken result. Check what's true at the end instead. Do the tests pass? Is the file correct? Is the record in the database?
Very little: one run of a task that varies can mislead either way
Agents vary from run to run, so one pass is one draw. Run each task several times and compare rates, with their error bars.
A student who goes from a D to an A overnight deserves a second look. When a pass rate leaps overnight, look before you celebrate. Check whether the agent found a way to game the grader, or whether a task leaked its answer. Read a handful of transcripts from runs that now pass.
Two versions with the same pass rate aren't equal if one takes 40 turns and $3 a task, and the other takes 8 turns and 40 cents. Report cost, turns and time beside the pass rate, so that a change that wins on one and loses badly on another doesn't slip through.
Track cost and turns as well as success. A car that's 2% faster and burns twice the fuel may not be an upgrade, and a change that adds 2% success but doubles cost may not be worth it. Keep a small, fast suite that runs on every change to the harness, like unit tests, and a large one that runs before releases.
Write a sentence or two, then compare it with a good answer in the lesson.
Start with a short baseline or choose guided, independent, or AI-assisted practice.
Why grade an agent's outcome rather than the exact sequence of tool calls?
575 lessons in thirteen phases. 176 are free without an account, and a free account opens the rest. See every lesson.
Questions on designing and running agents: tools, the agent loop, permissions, context, multi-agent systems, security and evaluation.
Learn how to build AI agents by building one: tools, the agent loop, MCP, permissions, context management and evals, ending with a coding agent that stops when its tests pass.
Build a bounded run loop, test it with scripted model responses, and recover interrupted work from an event log.
Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write