Chat history not structured

The function TTMSMCPCloudAI.BuildPostData()
dont create the history correct. The content shoud liste the history of the Chat like:

history = [ { "role": "user", "parts": [{"text": "Hello, who ist there?"}] }, { "role": "model", "parts": [{"text": "Here is the KI first answer..."}] }, { "role": "user", "parts": [{"text": "My second question"}] }, { "role": "model", "parts": [{"text": "here the answer to the second question"}] },

and:

Sequence: The roles must always alternate: user -> model -> user -> model. Two user messages sent consecutively without a response in between often lead to API errors.

Cant find that logic

AMessages := AMessages + string.Format('{"role":"user","content":"%s"}', [AContext]);

The "file_data" entry must also be placed in the correct position in the history so that the AI ​​has access to the chat history and files in the correct order.

The functionCall and functionResponse must also be included in the content history.
It seems to be a bigger design change.
Any chance to get a solution?

It is on our todolist and we’ll investigate as soon as we can allocate sufficient time.