Pydantic AI · Chapter 23 of 23
Interview round
By the end of this chapter you have answered five timed questions, one idea each, from across the whole lab: reading what a run did, trimming a conversation safely, one budget for two agents, a money decision made in code, and tools that each farmer sees or does not. 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 Pydantic AI are free. This one comes with the all labs plan.
Why you need this
The assistant is live, and KhetBazaar is hiring a second AI engineer. Kedar runs the interviews. "Short problems, ten minutes each. I am not checking that you remember Pydantic AI's names; the docs have them. I am checking that you know what each piece does inside, and that you look at what really reached the model before you guess." Pradnya liked the idea so much that the round is now the last chapter 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. Below is a refresher of each idea, with what an interviewer listens for. The answers are not here.
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: trail.py, what the model asked for
Time yourself: 10 minutes. Write tool_trail(result): given an agent run's result, return every tool call the model asked for during the run, in order, as a list of (tool name, arguments as a dictionary) tuples; an empty list when it called no tool.
The check runs its own agent with two tools on a question that needs both, and on one that needs none, and compares your list with the calls in the lab model's log. The interviewer will ask: who ran these tools, the model or your code?
- Task 2 · interview question
Interview: trim.py, keep the last turns
Time yourself: 10 minutes. Write keep_last_turns(messages, n): a turn starts at each request that holds the farmer's own message (a user prompt part), and runs until the next one. Return a new list of the last n turns, whole; all the messages when there are n turns or fewer. Never change the list you are given.
The check trims a conversation with tool calls in it to 1, 2, 3 and 5 turns. The interviewer will ask: why must a trimmed conversation never start with a tool's result?
- Task 3 · interview question
Interview: budget.py, one budget for two agents
Time yourself: 10 minutes. A weather expert: an agent for openai-chat:lab-chat-loopy (a model that asks for the same tool forever) with the instructions You are KhetBazaar's weather expert. Use the tools. and a tool weather_forecast(taluka). The farmer assistant: an agent for openai-chat:lab-chat with the instructions You are KhetBazaar's farmer assistant. Use the tools. and one tool, weather_expert(taluka), whose docstring starts with Weather questions, that runs the expert on What is the weather in <taluka> this week? and returns its output.
Write ask(question, max_requests): run the assistant with a limit of max_requests requests for the WHOLE run, the expert's requests included, and return its output, or exactly Sorry, that is taking too long. Ganesh will call you. when the limit stops it. The check asks with limits of 3 and 5 and counts every request. The interviewer will ask: why did the assistant's limit not stop the expert at first?
- Task 4 · interview question
Interview: credit.py, a decision in code
Time yourself: 10 minutes. Write order_on_credit(farmer_id, sku, qty) as a pydantic-graph graph (BaseNode nodes, a GraphBuilder, chapter 13) with no model in it. CheckCredit works out the amount (qty times the product's price in khetbazaar.INPUTS) and the credit left (khetbazaar.credit_balance's available), then goes to PlaceOrder when the amount fits and to Refuse when it does not. PlaceOrder calls khetbazaar.place_order on credit and ends with Order <order_id>: ₹<amount> on credit. Refuse ends with Refused: ₹<amount> is more than the ₹<left> left. Return the graph's output.
The check orders for four farmers, two who can afford it and two who cannot. The interviewer will ask: why is this a graph of code and not an agent's decision?
- Task 5 · interview question
Interview: prepare.py, tools per farmer
Time yourself: 10 minutes. Write ask(farmer_id, message): an agent for openai-chat:lab-chat with the farmer's id as deps, the instructions You are KhetBazaar's farmer assistant. Use the tools., a tool mandi_price(crop, mandi) for everyone, and a tool file_claim(crop, cause, acres, loss_date) for the farmer in the deps that the model sees only when that farmer has crop cover (khetbazaar.get_farmer's crop_cover). Return the run's output.
The check sends a hail claim for two farmers without cover and one with it, and reads which tools each request offered. The interviewer will ask: why do fewer tools help, and what does the model say to a farmer it can no longer file for?
What you will learn
- How to work a timed question: say the plan, build the smallest thing that runs, then look at the requests.
- Five ideas again, at interview depth: a run's messages (chapter 3), history (6), usage limits across agents (8 and 11), graphs (13), and preparing tools per run (16).
More in Production
Build "Interview round" yourself
KhetBazaar, a Nashik agritech startup, answers farmers on WhatsApp from a bike. You build its farmer assistant. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Pydantic AI are free. This one comes with the all labs plan.