Chapter 3 · Quest 5 of 5 · 15 XP
Toolbelt
🧰 Not every question needs a tool. Ask Pip for a joke and it answers by itself: "tool" comes back as null, which json.loads() turns into Python's None, and the answer is in "reply".
{"tool": null, "reply": "Why did the robot go on holiday? ..."}A good agent handles both. Test for nothing with is None:
if choice["tool"] is None:
print("No tool needed")Build the toolbelt and finish the chapter for your Handy badge: your bot gets arms.
Instructions
- Make
use_tools(question). It askspip.ask_with_tools(question, tools)and loads the JSON. - If the tool is
None, return the"reply". Otherwise run the tool and return its result. - Loop over
questionsand printuse_tools(q)for each one.
💡 Hint
Inside use_tools: choice = json.loads(...). Then if choice["tool"] is None: return choice["reply"]. After that, return tools[choice["tool"]](**choice["args"]).
bot.py
Terminal