When a model asks to call tools, your runtime has to validate the arguments, run the functions, and turn every failure into a message the model can read and recover from. It must never crash the agent loop.
Each call is {"id": str, "name": str, "arguments": str}, where arguments is a JSON string. The registry maps tool names to (function, params), where params is a dict from parameter name to type (int, float, str or bool). All parameters are required.
Implement dispatch(calls, registry), returning one result per call in the same order: {"id": ..., "content": str(result)} on success, or {"id": ..., "error": message} using the first problem found in this order:
"invalid JSON", if the arguments don't parse to a dict"unknown tool: <name>""unexpected argument: <arg>", for the first unexpected key in sorted order"missing argument: <param>", in parameter order"argument <param> must be <type name>". A float parameter accepts ints. bool values are not accepted as int or float."<ExceptionType>: <message>"