Skip to content

< all problems21 · Level 04, Tool Calling

Dispatch a Model's Tool Call

easy · implement · Tool Calling

A model does not run your functions. It emits a request to run one, and the dispatcher turns that into an actual call.

Implement dispatch(response, registry):

  1. Walk the response's tool_calls.
  2. Call each one through registry.call(name, arguments).
  3. Return a list of result dicts, one per call, shaped {"tool_use_id": ..., "content": ..., "is_error": bool}.

A tool that raises must not propagate. registry.call raises ToolError for an unknown tool or bad arguments. Catch it, put the message in content, set is_error, and the model can correct itself.

Order and count must match. One result per call, in arrival order, each with its call's tool_use_id. Models emit several calls in one turn; handling only the first fails the moment one does.