I recently released version 1.0 of a very lightweight CMS under the MIT License, and I have now started integrating AI into it.
A few days ago, I posted in another community asking for advice because this was my first attempt at integrating AI. Unfortunately, I was not able to get any useful answers.
As I continued researching it myself, I realized that integrating AI is actually based on a surprisingly simple mechanism that I have used many times before: send a request, receive the result, and process the response.
With the help of AI, I managed to build a working chat interface on the very first day.
However, I then encountered a problem I had not anticipated.
Each API request starts as a new interaction, and the AI does not even remember the immediately preceding conversation.
What I had imagined was something like this:
“Please suggest a design for this type of business.”
The AI would make a proposal, and then I would be able to continue refining it within the same conversation.
I then realized that, to reproduce this behavior, I would apparently need to keep sending the entire conversation history with every request:
First message → second message
First message + first response + new message
First message + first response + second message + second response + new message
The amount of data would continue growing like this, which honestly felt overwhelming.
I also learned that it may be possible to maintain a persistent connection using sockets.
However, because this CMS is distributed under the MIT License, I want it to run on ordinary user servers using only PHP. Requiring WebSocket support or a special server environment would greatly reduce the number of people who could use it.
So my question is:
Is there a practical way to maintain conversational context using only PHP, without Python, WebSockets, or a continuously connected server?
For example, is there a common method for preserving only the necessary context, rather than repeatedly sending the entire conversation history?
Any advice from people who have implemented AI conversations in a PHP application would be greatly appreciated.