Plug: I’ve built something vaguely similar, but of course a trillion times less brilliant and powerful, yet nonetheless useful for some straightforward cases where really you just want GPT et al. to call your API at just the right moment of the conversation, with JSON that is guaranteed to be valid:
https://github.com/manuelkiessling/php-ai-tool-bridge