Intermediate
Dispatch a call and feed errors back
Write dispatch(registry, call) that runs one tool call and returns the tool message dict {"role": "tool", "tool_call_id": <id>, "content": <JSON string>} (use json.dumps(value, separators=(",", ":"))).
On success, the content is the JSON of the function's result. If the name is not in registry: {"error": "unknown tool: <name>"}. If the function raises ToolError: {"error": <its message>}. For any other exception: {"error": "the tool failed unexpectedly"} (never include the exception text).
What Check tests
- Success: the result as JSON
- A
ToolErrorbecomes an error message - An unknown tool is reported
- Unexpected errors do not leak details
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.