Create an AI Agent that keeps user thread with WebHooks
What is the problem?
I have built Agent and a WebHook that takes input from a webpage and passes back answers from my Agent. The problem is there is no thread kempt i.e. it forgets the last quetions and only works on the next? Is there a simple way to keep the thread ona conversation going?
AI agents invoked by webhook are stateless. Every webhook call is a new run with no built in memory of previous requests.
If you want a chat style conversation, you need to store the past messages yourself (for example in a database) and send the relevant history or a summary along with each new webhook request.
Your webpage has to send a unique ID for that user (for example, you can ask the user for their email address, or generate a UUID using JavaScript). If that needs to be used across browser sessions, then you’ll need to use JavaScript to store it in a cookie or localStorage, so that you can fetch and reuse it when the user visits the page again.
Alternatively, if you don’t require the thread to be saved across sessions, you could calculate a unique hash for each user based on details sent through the webhook (turn on the webhook headers to get more detailed information about the request).
Then, use that unique identifier in the Thread ID field for the “Run an Agent” module:
Won’t the message change every new message, and the datetime variable now change based on the time the scenario runs? This means a new thread will be created for every new message even from the same user.
You should just use a single identifier to identify the user, like email address or phone, or constant variables that won’t change for the user’s session (like IP address).