Debug the support agent (~15 min)
debug_support_agent.py is an order-support agent: two tools (get_order, refund_order), some in-memory state (ORDERS, REFUNDS) and three test prompts in PROMPTS.
Run them one at a time and make all three pass:
python -m debug_support_agent
| Prompt | Expected |
|---|---|
status | Answer gives the order's status and tracking number (shipped, TRK-77) |
refund | Order 1001 is refunded exactly once (REFUNDS == [1001]) and the answer confirms it |
compare | Answer reports on order 1001 and says that order 9999 doesn't exist, without crashing |
Find the root cause of each failure by reading the raw tool_use inputs, the tool results and the message history, then fix it where it belongs (tool schema, tool function, or loop). Say out loud what you expect the model to send and receive before you run each prompt. Note that refund_order has a real-world side effect: think about what happens if the model calls it twice.
Constraints:
- The tool names and
run_agent(prompt, client=None, max_turns=10) -> strmust stay, and so must the module-levelORDERS/REFUNDS(the checks readREFUNDS). - Tool functions signal failure by raising; the loop turns that into an
is_errorresult.
Running the module with a key prints a trace of every model call to stderr: tool calls with their ids and inputs, the results sent back, and token counts (ABH_TRACE=0 turns it off).
Check it: pytest tests/test_debug_support_agent.py