At the moment I have the current flow:
- RG reads in things (Messages) from the database. This contains both user messages and OpenAI API response messages. Messages contains two important fields, the plain text (that is displayed in the RG) and the json (that is sent to the OpenAI API)
- When user sends a message, or a message is received back from OpenAI, a new thing is created in the database and the RG updates automatically.
The problem is that I’m seeing a crazy high utilization of WU from search - I presume each time a new message is added, the RG re-searches the database to pull in the new things.
To reduce this WU usage I’m looking to change the flow to this but seem to be stuck:
- On page load, the custom state is populated with the list of messages from the DB (this works fine).
- The RG displays the messages from the custom state (this works fine).
- The messages (user and OpenAI) are still added as new messages to the DB (this works fine).
- In tandem with “3” above I want the messages from the user and OpenAI to be added as a new message in the list of messages in the custom state.
- I then want the RG to update to show this change in the list of messages from the custom state.
In this way I avoid repeated DB searches with every message sent/received.
My problem is that I cannot figure out how to create a thing (message) locally, and add that into the custom state, for it to then be auto updated in the RG.
I’ve tried using the output of the created message (in DB) step in the workflow, but it seems I can only grab a field value rather than the whole “thing” (message).
Is what I’m trying to do possible or am I chasing an impossible dream?