AI agent interview questions and answers
Questions on designing and running agents: tools, the agent loop, permissions, context, multi-agent systems, security and evaluation.
The software around a model that turns it into an agent.
What turns a model's text requesting an action into a real effect?
The harness owns the loop, actions, state and limits around the model. A scripted model makes those behaviors observable without needing to predict or pay for a live model's response.
Scripted model proposes a typed report read
Harness validates, checks permission and calls the tool
Harness records the result and supplies it to the next model turn
Scripted model proposes a typed report read
Harness validates, checks permission and calls the tool
Harness records the result and supplies it to the next model turn
Given Scripted model proposes a typed report read and Harness records the result and supplies it to the next model turn, write down the missing step that connects them.
Harness validates, checks permission and calls the tool
Now take Harness validates, checks permission and calls the tool and the result above. Write an input and an implementation that could produce this trace.
Scripted model proposes a typed report read. Check that your implementation produces the result shown above.
If the scripted model proposes an unknown tool, what component should reject it?
The harness should reject the tool at lookup or validation and record a bounded error. The model supplied a proposal, and the harness decides which actions are available.
A scripted model asks to write a report before a reviewer has approved it. Say which component proposed the write, which one declines it, and which event a reviewer should see in the log.
The model proposed a call. The harness validates the call and applies the approval policy before calling the tool. A denial event includes the reason and the action identifier, so a reviewer can trace what happened without inspecting the model response alone.
One program runs a model with a lookup tool, a second checks the lookup against a known record, and a third compares lookup success across 80 changed prompts. Name the type of each harness and the evidence it produces.
The agent harness produces tool traces and task responses. The test harness checks a specific contract against a controlled example. The evaluation harness aggregates success on a collection of prompts to compare behavior.
You need an offline classroom exercise where every tool proposal comes from a script and you can pause after any step. Choose a starting runtime and name one reason you would revisit that choice for a long-running production service.
A small hand-built loop makes step boundaries and scripted responses explicit without requiring a network service. If production needs durable jobs, maintained integrations, or operational controls, compare what a vendor SDK or managed runtime provides and what ownership remains with your team.
Sketch two event sequences for a scripted report lookup. In the first the model supplies a known tool name and valid campaign ID. In the second it gives an unknown tool name. Which events prove no tool ran in the second case?
A successful sequence records proposal, validated dispatch, and result. The unknown name should produce proposal and rejection followed by a stop or bounded request for correction. Recording tool start and completion explicitly lets a reviewer distinguish a rejection from a partial dispatch.
Check this when debugging. Thinking an agent's quality comes only from the model.
A model on its own only turns text into text. Everything that makes it an agent, the loop, the tools, the permissions, the memory, is software around it called a harness. Two products using the same model can differ enormously because of their harnesses. Claude Code is a model plus a very good harness. This phase teaches you to build one: to customize agents, debug them, and judge the ones you're offered.
Its harness: the loop, tools, context and permissions around the model
A model only turns text into text. What it can read, which tools it can call, how it loops and when it stops are all the harness, so with the same model the harness decides the result. This phase teaches you to build one.
Recall: The agent loop built the smallest loop, and Hosts: connecting servers to a model built the program that runs a model's tool calls. A harness is that program grown up. This phase builds the rest of it.
SCRIPT = [{"stop_reason": "tool_use", "tool": "search"},
{"stop_reason": "end_turn", "text": "done"}]
def scripted_model(messages):
return SCRIPT[sum(1 for m in messages if m["role"] == "assistant")]
messages = [{"role": "user", "content": "find the tent"}]
turns = 0
while True:
reply = scripted_model(messages)
messages.append({"role": "assistant", "content": reply})
turns += 1
if reply["stop_reason"] != "tool_use":
break
messages.append({"role": "user", "content": "tool_result: 3 tents"})
print(turns, len(messages), reply["text"])2 4 done
The first reply asks for a tool, so the loop adds the result and calls again. The second reply ends the turn. That is two model calls and four messages: the question, the tool request, the tool result and the answer. Everything else in a harness is built around this loop, and the scripted model is how this phase tests it with no API.
Think of the model as an engine. It's the source of power, but an engine on a workbench goes nowhere. The harness is the rest of the car: wheels, brakes, fuel system, dashboard. A great engine in a bad car is a bad car.
A model call does exactly one thing: it reads a request (system prompt, messages, tool definitions) and returns a response (text, maybe tool_use blocks, and a stop_reason). Everything else is the harness:
| harness part | its job | lessons |
|---|---|---|
| the loop | call the model, run its tools, feed results back, know when to stop | core loop |
| tools | the actions on offer, their schemas and how they run | registry, files, execution |
| permissions | which actions need a person's approval | permissions |
| hooks and skills | let users and plugins change behavior; load know-how on demand | hooks and skills |
| context management | keep the conversation inside the window and cheap | context |
| memory and planning | carry work across long tasks and new sessions | memory and plans |
| subagents | hand off focused sub-tasks to fresh contexts | subagents |
| sessions and UI | stream output, allow interrupts, save and resume | sessions |
| observability and limits | logs, traces, costs, loop detection | production |
In plain words: the model only ever writes a reply. The harness is everything that acts on that reply.
You built the smallest possible harness in Phase 1's agent loop lesson, and a host in Phase 9. This phase builds the full set.
A model only returns text and requests. Without a harness, a request to read a file is nothing but data. Here's the same scripted reply with and without one.
def model(messages): if len(messages) == 1: return {"stop_reason": "tool_use", "tool": "read_file", "input": "notes.txt"} return {"stop_reason": "end_turn", "text": "The notes say: ship on Friday."} FILES = {"notes.txt": "ship on Friday"} # No harness: one call, and the request goes nowhere. print("alone:", model(["What do my notes say?"])) # A harness runs the tool and goes round again. messages = ["What do my notes say?"] while True: reply = model(messages) if reply["stop_reason"] == "end_turn": break messages.append(FILES[reply["input"]]) print("with a harness:", reply["text"])
The engine is the same in both. All the doing, like reading files, keeping the conversation and deciding when it's over, comes from the code around it.
Step through it. The list starts with one message and ends with four. The model never touches a file: the harness did that, then wrote the result down.
A horse's harness and a climber's harness are both gear around something, keeping it under control. The word turns up in software in three related senses:
harness.py runs your exercises and their checks.lm-evaluation-harness. The eval harness lesson builds one for agents.They share an idea: a harness is the controlled environment around the thing being run.
Mostly the harness's: carrying work across a long task (memory, notes, context) is its job
A model only sees what the harness puts in its context. Keeping notes, summaries and plans there is harness work.
Write a sentence or two, then compare it with a good answer in the lesson.
So why build one yourself? Because every one of these is made of the parts in this phase. To configure them well, debug them when they misbehave, add what's missing, or build a harness for a domain no product covers, you need to know what's inside.
Pilots train in flight simulators, because they can practice an engine failure there at no risk or cost. Make the model a parameter of the harness: a function that takes messages and tools and returns a response. Production passes a function that calls the API. Tests pass a scripted model that returns prepared responses in order. Then every part of the harness can be tested quickly, cheaply and deterministically, which is how the rest of this phase works.
How do you test what your harness does when the model asks for a file that doesn't exist? With a real model, you'd have to coax it. With a scripted one, you write the reply yourself.
def run(model, tools): messages = [{"role": "user", "content": "go"}] while True: reply = model(messages) if reply["stop_reason"] == "end_turn": return messages try: result = {"content": tools[reply["tool"]](reply["input"])} except FileNotFoundError as err: result = {"content": str(err), "is_error": True} messages.append({"role": "user", "content": result}) script = iter([{"stop_reason": "tool_use", "tool": "read", "input": "missing.txt"}, {"stop_reason": "end_turn"}]) def scripted(messages): return next(script) def read(path): raise FileNotFoundError(f"No file {path}") last = run(scripted, {"read": read})[-1]["content"] print(last) assert last["is_error"] is True print("test passed, with no API call")
That test costs nothing, takes milliseconds and gives the same result every time. It's why this phase passes the model in as an argument.
def fake_model(prompt): return "done" def agent(model): return model("go") print(agent(fake_model))
done
agent calls whatever model it's given, and fake_model returns "done", so it prints done. Pass the model in as an argument and your tests can use a scripted fake.
Tests need a model that does exactly what you say. Write scripted(replies): return a function model(messages) that returns the next reply from the list each time it's called, records a copy of every messages list it was given in model.seen, and raises RuntimeError when it runs out.
def scripted(replies): def model(messages): return replies[0] return model model = scripted(["first", "second"]) print(model([{"role": "user", "content": "hi"}]), model([]))
The loop gets a model, a dict of tools and an event log. Change the script in the cell below: make the first reply ask for a tool that does not exist, and read the transcript the harness writes.
The model is a list of prepared replies. The harness runs tools and records an event for everything that happens.
def scripted(replies): replies = list(replies) def model(messages, tools): return replies.pop(0) return model def run(task, model, tools): messages = [{"role": "user", "content": task}] events = [] while True: reply = model(messages, list(tools)) messages.append({"role": "assistant", "content": reply["content"]}) events.append(("model", reply["stop_reason"])) if reply["stop_reason"] != "tool_use": text = "".join(b["text"] for b in reply["content"] if b["type"] == "text") return text, events results = [] for block in reply["content"]: if block["type"] == "tool_use": output = tools[block["name"]](**block["input"]) events.append(("tool", block["name"])) results.append({"type": "tool_result", "tool_use_id": block["id"], "content": str(output)}) messages.append({"role": "user", "content": results}) model = scripted([ {"stop_reason": "tool_use", "content": [ {"type": "tool_use", "id": "t1", "name": "add", "input": {"a": 2, "b": 3}}]}, {"stop_reason": "end_turn", "content": [{"type": "text", "text": "2 + 3 = 5"}]}, ]) print(run("What is 2 + 3?", model, {"add": lambda a, b: a + b}))
Two model calls, one tool run, and an answer. Nothing here talks to a network. Swap scripted(...) for a function that POSTs to the Messages API and the same harness runs a real model. The event list is the seed of the tracing you'll add later.
add with a=2, b=3. What is the content of the user message the harness appends next?A tool_result block with the content "5"
The harness runs the tool and appends one user message holding a tool_result block, so the model sees its own call answered.
Tests can use a scripted model, so every part of the harness is fast, free and repeatable to test
It's dependency injection again. A scripted model makes behavior deterministic, so tests can check exact sequences.
Write counts(messages): count the model calls (assistant messages) and the tool results (blocks of type tool_result inside user messages whose content is a list). Return {"model_calls": ..., "tool_results": ...}.
TRANSCRIPT = [
{"role": "user", "content": "Which campaign did best?"},
{"role": "assistant", "content": [
{"type": "tool_use", "id": "t1", "name": "list_campaigns", "input": {}}]},
{"role": "user", "content": [
{"type": "tool_result", "tool_use_id": "t1", "content": "[...]"}]},
{"role": "assistant", "content": [
{"type": "tool_use", "id": "t2", "name": "get_stats", "input": {}},
{"type": "tool_use", "id": "t3", "name": "get_stats", "input": {}}]},
{"role": "user", "content": [
{"type": "tool_result", "tool_use_id": "t2", "content": "..."},
{"type": "tool_result", "tool_use_id": "t3", "content": "..."}]},
{"role": "assistant", "content": [{"type": "text", "text": "Spring sale."}]},
]
def counts(messages):
return {"model_calls": 0, "tool_results": 0}
print(counts(TRANSCRIPT))
Write a sentence or two, then compare it with a good answer in the lesson.
Four common ways to get an agent running on Claude differ in who writes the loop and who runs the machine. The rows below are the ones you meet in week one of a job.
You can cook dinner from scratch, use a meal kit, heat up a ready meal or go to a restaurant. There are four common ways to get an agent running on Claude, depending on who writes the loop and who runs the machines:
| approach | you write | you get |
|---|---|---|
| a manual loop | the whole loop over stop_reason | full control, no extra dependencies |
the SDK's tool runner (client.beta.messages.tool_runner) | your tool functions | the loop for tools you define, with per-turn hooks; you host it |
| the Claude Agent SDK | a prompt and options | Claude Code's harness as a library: built-in file, bash, grep and web tools, permissions, hooks, subagents, sessions; you host it |
| managed agents (a hosted API) | an agent config and your custom tool results | Anthropic runs the loop and a sandbox container per session |
The tool runner and the Agent SDK are easy to mix up. The tool runner is a thin helper in the normal API SDK that loops over your tools. The Agent SDK is a separate package with a full, opinionated harness and built-in tools.
The Claude Agent SDK
The Agent SDK is Claude Code's harness as a library: built-in tools, permissions, hooks and subagents, hosted by you.
Managed agents
The tool runner and the Agent SDK run on your own machines. Managed agents run the loop and the sandbox for you.
Agent frameworks compete on names, but they're built from the parts in this phase. When you meet a new one, map it onto those parts first:
| the part | in your own harness | what frameworks tend to call it |
|---|---|---|
| the loop | while stop_reason == "tool_use" | a runner, an executor, a graph run |
| tools | functions plus JSON schemas | tools, function tools, actions; MCP servers (Model Context Protocol) for shared ones |
| state | the messages list, plus anything you keep | memory, sessions, threads, checkpoints |
| control flow | your if and for around model calls | graphs (nodes and edges), crews, flows, pipelines |
| subagents | a function that runs a second loop | subagents, handoffs, agents as tools |
| permissions and hooks | code that inspects inputs, outputs and tool calls | guardrails, hooks, permissions, approval steps |
| observability | your log of every turn | traces, tracing, observability |
LangGraph's nodes and edges are control flow written as a graph. The OpenAI Agents SDK's handoffs and guardrails are the subagents and the permissions-and-hooks rows. CrewAI's crews are agents with set roles working through a list of tasks, in order or under a manager agent. And the Claude Agent SDK packages Claude Code's loop, tools, hooks and subagents. Names and APIs change between versions, so read the current docs, but the questions stay the same: who writes the loop, where state lives, and where you can put a check.
Permissions and hooks: code that inspects what goes in and out, and can stop the run
Whatever it's called, a check that looks at what goes in or comes out and can halt the run is the safety-check layer, the same place your harness checks tool calls before running them.
In an engineer's week, choosing among these is the first decision, and it is usually made by who must host and own the loop. A reviewer asks the same three questions of any of them: who writes the loop, where the state lives and where a check can go.
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.
Which of these is the model's job rather than the harness's?
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