Command Palette

Search for a command to run...

Hectal
Phase 7: Tools and Function Calling
LLM Engineering · Exercise 4 of 6 PreviousNext
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

  1. Success: the result as JSON
  2. A ToolError becomes an error message
  3. An unknown tool is reported
  4. 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.