Best practice for AI to update database

Hello to the community !

Video Game
Imagine you are developing a video game which change the scenario in real time by using and collecting data on the player and the game.
The collection is made for example when the player is talking to AI characters in the game.
They might say, “I don’t think those kind of characters funny anymore”, “this task is too hard not funny” or “There is too much zubats in this cave!”.

Huge nested dict
There is a huge nested dict in the background which contains information about the user and the game; [user], [user][quest] (which quest he has done or he has tried, how does it rate the difficulty, …), [user][PNJ] (what how many time he talk to a pnj, , which one he fights, the win, the loss, …)

Three API Calls
This huge nested dict is going to be update by AI using the recommendation of a previous call.
First call : Analyze update raw data collecting during the game and provide orders (for example it might order : decrease the spawn rate of zubats! And make the gym leader difficulty rate higher).
Second call : Analyze orders and fetch current relevant data to feed the third call (the dataframe size is prohibitive to add to the third prompt.
Third call: Using llm function callings (with a lot of functions) the change are applied. For example the AI will update the spawn rate key.

Efficiency question
The goal to lessen the number of errors (when the first call order some change, that could be done, but are not done).
Any advice ?

Thank you for your help.

Hi @cechgmyt ,

Interesting project! To tackle it, I’d focus on 3 key aspects:

  1. Parallel Execution of Tasks

Consider using parallel processes to handle tasks asynchronously. For example, one process could analyze the data and recommend changes, while another supervises the game state updates in the background. This would make your system faster and more resilient, reducing bottlenecks and keeping the game scenario updated in real-time.

  1. Transactional Database

To manage your nested dict and frequent updates, I’d possible look into a transactional DB like the TigerBeetle (https://tigerbeetle.com/) or a similar. These databases handle a high number of transactions efficiently without crashing, which is important when your game is constantly updating based on player actions.

  1. Error Reduction

To reduce errors, introduce a confirmation mechanism after each update. This could be a simple check to ensure that changes recommended by the first call are correctly applied by the second and third calls. You can also use a queue system to track pending changes and retry if something fails.

1 Like

Thank you for your answer !

1 Like