powerclamp is a building block towards a solution that you describe.
Note that if you need a "near instant" limit, a kernel level solution isn't going to work, you need something much much faster responding.
But if you can deal with "we need over <some hundreds of milliseconds> the average to be below X", and you can measure X.. this driver is what a small (userspace) control agent can use to actually impact the current consumption