AI Agents by HandAll problemsAbout

All problems › Agent problem · medium · ~15 min

Debug a support agent

debugging idempotency parallel tool calls parsing

Solve it in your browser →

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
PromptExpected
statusAnswer gives the order's status and tracking number (shipped, TRK-77)
refundOrder 1001 is refunded exactly once (REFUNDS == [1001]) and the answer confirms it
compareAnswer 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) -> str must stay, and so must the module-level ORDERS / REFUNDS (the checks read REFUNDS).
  • Tool functions signal failure by raising; the loop turns that into an is_error result.

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

Starter code and hidden tests open in the editor. Nothing to install.