agent loops — tool_use and the request/tool/respond cycle6 / 9
multi-step tools — when one tool isn't enough
The model hallucinated a tool name — web_search — that isn't in
the registry. The current dispatch raises KeyError deep inside
the loop, which crashes the agent and loses the whole conversation.
Fix the dispatch so an unknown tool returns the string
"unknown tool: <name>" as the tool result instead. The model can
then read that and recover (it usually retries with a real tool
name).
Expected output:
unknown tool: web_search
The break is on line 12 — but read the whole snippet first.
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _