Dev3Pack · Session 05
A deterministic mini-agent
A mini-AgentA program that uses a language model to decide what to do (search, call a tool, answer, refuse), in a loop, with stopping rules.See in the glossary → is a loop that runs a plan of Tool callThe model's request to run a tool with specific arguments. That's what you read in the trace, not the final answer.See in the glossary →, and always stops while saying why. A loop without exits spins idle, spends without limit, or crashes on a tool error.
The concept
Think of a stock order with a cap and a stop: you know in advance under which conditions it stops, and the statement says which one triggered. The loop has four exits, tested in this order:
answered: the plan has the answer.repeated_call: the same tool, with the same arguments, as the previous call.budget: the call cap is reached, checked before the call.tool_error: a tool refused.
Each run returns a receipt: {steps, stopped_because, answer, refusal}.
How I worked
As since Session 4: the code is written by the assistant, tested against the real grader and explained line by line; I reran the check myself before handing in.
What the hand-in contains
run_loop and its four exits.
answeredisn’t a call: it’s never counted insteps.repeated_call: the last call is kept as(name, arguments); the same pair twice in a row signals an idle loop.budget:len(steps) >= budgetis tested before the call, so there’s never one call too many. A plan that runs out without an answer also exits here.tool_error: atry/except ToolErrorturns the error into a RefusalAn explicit "I can't answer": no citation, zero confidence, human review. A state, not a crash.See in the glossary → that names the tool, instead of a crash.
The weekly challenge: a bot respond(text, chat), with run_loop behind it.
- A repeated message doesn’t use up a call.
- Five calls per conversation, then “come back in 1 hour”: a BudgetThe maximum number of calls an agent loop may make, checked before each call, never after.See in the glossary → that recovers.
- A tool of its own,
page, which refuses an unknown ID. - A non-existent tool refused cleanly, and the loop’s exit visible in the reply.
The first attempt came out at 400/500: an unknown tool raised a KeyError instead of a refusal. Once fixed, it reached 500/500. That’s exactly the failure the session teaches you to avoid.
What I keep
- An Agent loopThe cycle message → model → tool call → result → model, repeated until an answer or a planned exit.See in the glossary → is designed by its exits: you first write how it stops.
- The budget is checked before the call, never after.
- A tool error becomes a readable refusal, not a crash.
The defense question
What keeps your agent from going in circles?
Two exits. The same call twice in a row triggers repeated_call, and a budget counted before each call triggers budget. Either way, the person reads a sentence that says why it stopped.
Result: 700/700 (200 for the session, 500 for the challenge), handed in through PR #553.