Dispatch a Model's Tool Call
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):
- Walk the response's
tool_calls. - Call each one through
registry.call(name, arguments). - 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.