Yes, this is rather goofy.
There should be a persistent system message first that gives the AI its identity and purpose.
system = “You are IDBot, a conversational AI assistant with database lookup skills.”
The function specifications are added to, and the AI is trained on, functions in that first system message.
messages = system + conversation_history + user
where conversation_history is a full record of every AI assistant output and every response that happened previously. That includes every AI function call (in a special format) and every return value, placed after the user input.
The function specification is where the purpose of the function, and restrictions on use are. “this function cannot be called unless an alphanumeric customer ID has been provided by the user directly in the chat”.
then returning the value to the AI so it can answer, the new messages look like
messages = system + conversation_history + user + assistant_function + function_return
using the function role.
My documentation: