AI Agents by HandAll problemsAbout

All problems › Agent problem · medium · ~15 min

Debug a travel planner

debugging API message rules serialization json timestamps

Solve it in your browser →

Debug the travel planner (~15 min)

debug_travel_planner.py is a travel planner with four tools (search_flights, search_hotels, get_weather, convert_currency), some fixture data and three test prompts in PROMPTS.

Run them one at a time, in order, and make all three pass:

python -m debug_travel_planner itinerary
PromptExpected
itineraryAnswer gives the departure time of the earliest flight (11:05, UA837) and the Tokyo forecast (light rain)
budgetAnswer gives a total of about $1,220 (flight $980 + 3 nights at ¥12,000 = $240) and says it fits the $1,500 budget
unknownThe agent doesn't crash. It gives Tokyo's forecast and says there's no data for Atlantis

One bug can hide another, so rerun every prompt after each fix. Find the root cause of each failure by reading the raw tool_use inputs, the tool results, the message history and any exception, then fix it where it belongs (tool function, loop, or system prompt). Say out loud what you expect the model to send and receive before you run each prompt.

Constraints:

  • The tool names, their inputs, RATES (units of each currency per 1 USD) and run_agent(prompt, client=None, max_turns=10) -> str must stay.
  • Tool functions signal failure by raising; the loop turns that into an is_error result.
  • Keep the "some lookups failed" note for the model: it is useful. It just can't break the request.

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_travel_planner.py

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